latentcode 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +49 -5
- package/dist/latentcode.mjs +2441 -664
- package/package.json +4 -1
package/dist/latentcode.mjs
CHANGED
|
@@ -1380,7 +1380,7 @@ var require_react_development = __commonJS({
|
|
|
1380
1380
|
}
|
|
1381
1381
|
return dispatcher.useContext(Context);
|
|
1382
1382
|
}
|
|
1383
|
-
function
|
|
1383
|
+
function useState9(initialState2) {
|
|
1384
1384
|
var dispatcher = resolveDispatcher();
|
|
1385
1385
|
return dispatcher.useState(initialState2);
|
|
1386
1386
|
}
|
|
@@ -1388,11 +1388,11 @@ var require_react_development = __commonJS({
|
|
|
1388
1388
|
var dispatcher = resolveDispatcher();
|
|
1389
1389
|
return dispatcher.useReducer(reducer, initialArg, init);
|
|
1390
1390
|
}
|
|
1391
|
-
function
|
|
1391
|
+
function useRef6(initialValue) {
|
|
1392
1392
|
var dispatcher = resolveDispatcher();
|
|
1393
1393
|
return dispatcher.useRef(initialValue);
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1395
|
+
function useEffect9(create2, deps2) {
|
|
1396
1396
|
var dispatcher = resolveDispatcher();
|
|
1397
1397
|
return dispatcher.useEffect(create2, deps2);
|
|
1398
1398
|
}
|
|
@@ -2175,15 +2175,15 @@ var require_react_development = __commonJS({
|
|
|
2175
2175
|
exports.useContext = useContext8;
|
|
2176
2176
|
exports.useDebugValue = useDebugValue;
|
|
2177
2177
|
exports.useDeferredValue = useDeferredValue;
|
|
2178
|
-
exports.useEffect =
|
|
2178
|
+
exports.useEffect = useEffect9;
|
|
2179
2179
|
exports.useId = useId;
|
|
2180
2180
|
exports.useImperativeHandle = useImperativeHandle;
|
|
2181
2181
|
exports.useInsertionEffect = useInsertionEffect;
|
|
2182
2182
|
exports.useLayoutEffect = useLayoutEffect2;
|
|
2183
2183
|
exports.useMemo = useMemo6;
|
|
2184
2184
|
exports.useReducer = useReducer2;
|
|
2185
|
-
exports.useRef =
|
|
2186
|
-
exports.useState =
|
|
2185
|
+
exports.useRef = useRef6;
|
|
2186
|
+
exports.useState = useState9;
|
|
2187
2187
|
exports.useSyncExternalStore = useSyncExternalStore2;
|
|
2188
2188
|
exports.useTransition = useTransition;
|
|
2189
2189
|
exports.version = ReactVersion;
|
|
@@ -7875,9 +7875,9 @@ var require_react_reconciler_development = __commonJS({
|
|
|
7875
7875
|
module.exports = function $$$reconciler($$$hostConfig) {
|
|
7876
7876
|
var exports2 = {};
|
|
7877
7877
|
"use strict";
|
|
7878
|
-
var
|
|
7878
|
+
var React17 = require_react();
|
|
7879
7879
|
var Scheduler = require_scheduler();
|
|
7880
|
-
var ReactSharedInternals =
|
|
7880
|
+
var ReactSharedInternals = React17.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
7881
7881
|
var suppressWarning = false;
|
|
7882
7882
|
function setSuppressWarning(newSuppressWarning) {
|
|
7883
7883
|
{
|
|
@@ -7941,7 +7941,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
7941
7941
|
var HostPortal = 4;
|
|
7942
7942
|
var HostComponent = 5;
|
|
7943
7943
|
var HostText = 6;
|
|
7944
|
-
var
|
|
7944
|
+
var Fragment6 = 7;
|
|
7945
7945
|
var Mode = 8;
|
|
7946
7946
|
var ContextConsumer = 9;
|
|
7947
7947
|
var ContextProvider = 10;
|
|
@@ -8081,7 +8081,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
8081
8081
|
return "DehydratedFragment";
|
|
8082
8082
|
case ForwardRef:
|
|
8083
8083
|
return getWrappedName$1(type, type.render, "ForwardRef");
|
|
8084
|
-
case
|
|
8084
|
+
case Fragment6:
|
|
8085
8085
|
return "Fragment";
|
|
8086
8086
|
case HostComponent:
|
|
8087
8087
|
return type;
|
|
@@ -11215,7 +11215,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
11215
11215
|
}
|
|
11216
11216
|
}
|
|
11217
11217
|
function updateFragment2(returnFiber, current2, fragment, lanes, key) {
|
|
11218
|
-
if (current2 === null || current2.tag !==
|
|
11218
|
+
if (current2 === null || current2.tag !== Fragment6) {
|
|
11219
11219
|
var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
|
|
11220
11220
|
created.return = returnFiber;
|
|
11221
11221
|
return created;
|
|
@@ -11618,7 +11618,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
11618
11618
|
if (child.key === key) {
|
|
11619
11619
|
var elementType = element.type;
|
|
11620
11620
|
if (elementType === REACT_FRAGMENT_TYPE) {
|
|
11621
|
-
if (child.tag ===
|
|
11621
|
+
if (child.tag === Fragment6) {
|
|
11622
11622
|
deleteRemainingChildren(returnFiber, child.sibling);
|
|
11623
11623
|
var existing = useFiber(child, element.props.children);
|
|
11624
11624
|
existing.return = returnFiber;
|
|
@@ -11846,10 +11846,10 @@ var require_react_reconciler_development = __commonJS({
|
|
|
11846
11846
|
}
|
|
11847
11847
|
while (fiber !== null) {
|
|
11848
11848
|
var nextFiber = void 0;
|
|
11849
|
-
var
|
|
11850
|
-
if (
|
|
11849
|
+
var list2 = fiber.dependencies;
|
|
11850
|
+
if (list2 !== null) {
|
|
11851
11851
|
nextFiber = fiber.child;
|
|
11852
|
-
var dependency =
|
|
11852
|
+
var dependency = list2.firstContext;
|
|
11853
11853
|
while (dependency !== null) {
|
|
11854
11854
|
if (dependency.context === context) {
|
|
11855
11855
|
if (fiber.tag === ClassComponent) {
|
|
@@ -11876,7 +11876,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
11876
11876
|
alternate.lanes = mergeLanes(alternate.lanes, renderLanes2);
|
|
11877
11877
|
}
|
|
11878
11878
|
scheduleContextWorkOnParentPath(fiber.return, renderLanes2, workInProgress2);
|
|
11879
|
-
|
|
11879
|
+
list2.lanes = mergeLanes(list2.lanes, renderLanes2);
|
|
11880
11880
|
break;
|
|
11881
11881
|
}
|
|
11882
11882
|
dependency = dependency.next;
|
|
@@ -17109,7 +17109,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
17109
17109
|
var _resolvedProps2 = workInProgress2.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
|
|
17110
17110
|
return updateForwardRef(current2, workInProgress2, type, _resolvedProps2, renderLanes2);
|
|
17111
17111
|
}
|
|
17112
|
-
case
|
|
17112
|
+
case Fragment6:
|
|
17113
17113
|
return updateFragment(current2, workInProgress2, renderLanes2);
|
|
17114
17114
|
case Mode:
|
|
17115
17115
|
return updateMode(current2, workInProgress2, renderLanes2);
|
|
@@ -17546,7 +17546,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
17546
17546
|
case SimpleMemoComponent:
|
|
17547
17547
|
case FunctionComponent:
|
|
17548
17548
|
case ForwardRef:
|
|
17549
|
-
case
|
|
17549
|
+
case Fragment6:
|
|
17550
17550
|
case Mode:
|
|
17551
17551
|
case Profiler:
|
|
17552
17552
|
case ContextConsumer:
|
|
@@ -22314,7 +22314,7 @@ var require_react_reconciler_development = __commonJS({
|
|
|
22314
22314
|
return fiber;
|
|
22315
22315
|
}
|
|
22316
22316
|
function createFiberFromFragment(elements, mode, lanes, key) {
|
|
22317
|
-
var fiber = createFiber(
|
|
22317
|
+
var fiber = createFiber(Fragment6, elements, key, mode);
|
|
22318
22318
|
fiber.lanes = lanes;
|
|
22319
22319
|
return fiber;
|
|
22320
22320
|
}
|
|
@@ -23111,13 +23111,13 @@ var require_buffer_util = __commonJS({
|
|
|
23111
23111
|
var { websocketMask, websocketUnmask } = __require("http");
|
|
23112
23112
|
var { EMPTY_BUFFER } = require_constants2();
|
|
23113
23113
|
var FastBuffer = Buffer[Symbol.species];
|
|
23114
|
-
function concat(
|
|
23115
|
-
if (
|
|
23116
|
-
if (
|
|
23114
|
+
function concat(list2, totalLength) {
|
|
23115
|
+
if (list2.length === 0) return EMPTY_BUFFER;
|
|
23116
|
+
if (list2.length === 1) return list2[0];
|
|
23117
23117
|
const target = Buffer.allocUnsafe(totalLength);
|
|
23118
23118
|
let offset = 0;
|
|
23119
|
-
for (let i = 0; i <
|
|
23120
|
-
const buf =
|
|
23119
|
+
for (let i = 0; i < list2.length; i++) {
|
|
23120
|
+
const buf = list2[i];
|
|
23121
23121
|
target.set(buf, offset);
|
|
23122
23122
|
offset += buf.length;
|
|
23123
23123
|
}
|
|
@@ -23432,26 +23432,26 @@ var require_permessage_deflate = __commonJS({
|
|
|
23432
23432
|
value = value[0];
|
|
23433
23433
|
if (key === "client_max_window_bits") {
|
|
23434
23434
|
if (value !== true) {
|
|
23435
|
-
const
|
|
23436
|
-
if (!Number.isInteger(
|
|
23435
|
+
const num3 = +value;
|
|
23436
|
+
if (!Number.isInteger(num3) || num3 < 8 || num3 > 15) {
|
|
23437
23437
|
throw new TypeError(
|
|
23438
23438
|
`Invalid value for parameter "${key}": ${value}`
|
|
23439
23439
|
);
|
|
23440
23440
|
}
|
|
23441
|
-
value =
|
|
23441
|
+
value = num3;
|
|
23442
23442
|
} else if (!this._isServer) {
|
|
23443
23443
|
throw new TypeError(
|
|
23444
23444
|
`Invalid value for parameter "${key}": ${value}`
|
|
23445
23445
|
);
|
|
23446
23446
|
}
|
|
23447
23447
|
} else if (key === "server_max_window_bits") {
|
|
23448
|
-
const
|
|
23449
|
-
if (!Number.isInteger(
|
|
23448
|
+
const num3 = +value;
|
|
23449
|
+
if (!Number.isInteger(num3) || num3 < 8 || num3 > 15) {
|
|
23450
23450
|
throw new TypeError(
|
|
23451
23451
|
`Invalid value for parameter "${key}": ${value}`
|
|
23452
23452
|
);
|
|
23453
23453
|
}
|
|
23454
|
-
value =
|
|
23454
|
+
value = num3;
|
|
23455
23455
|
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
23456
23456
|
if (value !== true) {
|
|
23457
23457
|
throw new TypeError(
|
|
@@ -24165,8 +24165,8 @@ var require_receiver = __commonJS({
|
|
|
24165
24165
|
return;
|
|
24166
24166
|
}
|
|
24167
24167
|
const buf = this.consume(8);
|
|
24168
|
-
const
|
|
24169
|
-
if (
|
|
24168
|
+
const num3 = buf.readUInt32BE(0);
|
|
24169
|
+
if (num3 > Math.pow(2, 53 - 32) - 1) {
|
|
24170
24170
|
const error = this.createError(
|
|
24171
24171
|
RangeError,
|
|
24172
24172
|
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
@@ -24177,7 +24177,7 @@ var require_receiver = __commonJS({
|
|
|
24177
24177
|
cb(error);
|
|
24178
24178
|
return;
|
|
24179
24179
|
}
|
|
24180
|
-
this._payloadLength =
|
|
24180
|
+
this._payloadLength = num3 * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
24181
24181
|
this.haveLength(cb);
|
|
24182
24182
|
}
|
|
24183
24183
|
/**
|
|
@@ -24915,14 +24915,14 @@ var require_sender = __commonJS({
|
|
|
24915
24915
|
* @param {Function} [cb] Callback
|
|
24916
24916
|
* @private
|
|
24917
24917
|
*/
|
|
24918
|
-
sendFrame(
|
|
24919
|
-
if (
|
|
24918
|
+
sendFrame(list2, cb) {
|
|
24919
|
+
if (list2.length === 2) {
|
|
24920
24920
|
this._socket.cork();
|
|
24921
|
-
this._socket.write(
|
|
24922
|
-
this._socket.write(
|
|
24921
|
+
this._socket.write(list2[0]);
|
|
24922
|
+
this._socket.write(list2[1], cb);
|
|
24923
24923
|
this._socket.uncork();
|
|
24924
24924
|
} else {
|
|
24925
|
-
this._socket.write(
|
|
24925
|
+
this._socket.write(list2[0], cb);
|
|
24926
24926
|
}
|
|
24927
24927
|
}
|
|
24928
24928
|
};
|
|
@@ -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: createHash3 } = __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 = createHash3("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: createHash3 } = __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 = createHash3("sha1").update(key + GUID).digest("base64");
|
|
26699
26699
|
const headers = [
|
|
26700
26700
|
"HTTP/1.1 101 Switching Protocols",
|
|
26701
26701
|
"Upgrade: websocket",
|
|
@@ -27332,7 +27332,7 @@ var require_react_jsx_runtime_development = __commonJS({
|
|
|
27332
27332
|
if (process.env.NODE_ENV !== "production") {
|
|
27333
27333
|
(function() {
|
|
27334
27334
|
"use strict";
|
|
27335
|
-
var
|
|
27335
|
+
var React17 = require_react();
|
|
27336
27336
|
var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.element");
|
|
27337
27337
|
var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
|
|
27338
27338
|
var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
@@ -27358,7 +27358,7 @@ var require_react_jsx_runtime_development = __commonJS({
|
|
|
27358
27358
|
}
|
|
27359
27359
|
return null;
|
|
27360
27360
|
}
|
|
27361
|
-
var ReactSharedInternals =
|
|
27361
|
+
var ReactSharedInternals = React17.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
27362
27362
|
function error(format) {
|
|
27363
27363
|
{
|
|
27364
27364
|
{
|
|
@@ -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 jsx12 = jsxWithValidationDynamic;
|
|
28212
|
+
var jsxs10 = jsxWithValidationStatic;
|
|
28213
28213
|
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
28214
|
-
exports.jsx =
|
|
28215
|
-
exports.jsxs =
|
|
28214
|
+
exports.jsx = jsx12;
|
|
28215
|
+
exports.jsxs = jsxs10;
|
|
28216
28216
|
})();
|
|
28217
28217
|
}
|
|
28218
28218
|
}
|
|
@@ -32514,10 +32514,10 @@ var Output = class {
|
|
|
32514
32514
|
transformers
|
|
32515
32515
|
});
|
|
32516
32516
|
}
|
|
32517
|
-
clip(
|
|
32517
|
+
clip(clip3) {
|
|
32518
32518
|
this.operations.push({
|
|
32519
32519
|
type: "clip",
|
|
32520
|
-
clip:
|
|
32520
|
+
clip: clip3
|
|
32521
32521
|
});
|
|
32522
32522
|
}
|
|
32523
32523
|
unclip() {
|
|
@@ -32551,40 +32551,40 @@ var Output = class {
|
|
|
32551
32551
|
const { text, transformers } = operation;
|
|
32552
32552
|
let { x, y } = operation;
|
|
32553
32553
|
let lines = text.split("\n");
|
|
32554
|
-
const
|
|
32555
|
-
if (
|
|
32556
|
-
const clipHorizontally = typeof
|
|
32557
|
-
const clipVertically = typeof
|
|
32554
|
+
const clip3 = clips.at(-1);
|
|
32555
|
+
if (clip3) {
|
|
32556
|
+
const clipHorizontally = typeof clip3?.x1 === "number" && typeof clip3?.x2 === "number";
|
|
32557
|
+
const clipVertically = typeof clip3?.y1 === "number" && typeof clip3?.y2 === "number";
|
|
32558
32558
|
if (clipHorizontally) {
|
|
32559
32559
|
const width = widestLine(text);
|
|
32560
|
-
if (x + width <
|
|
32560
|
+
if (x + width < clip3.x1 || x > clip3.x2) {
|
|
32561
32561
|
continue;
|
|
32562
32562
|
}
|
|
32563
32563
|
}
|
|
32564
32564
|
if (clipVertically) {
|
|
32565
32565
|
const height = lines.length;
|
|
32566
|
-
if (y + height <
|
|
32566
|
+
if (y + height < clip3.y1 || y > clip3.y2) {
|
|
32567
32567
|
continue;
|
|
32568
32568
|
}
|
|
32569
32569
|
}
|
|
32570
32570
|
if (clipHorizontally) {
|
|
32571
32571
|
lines = lines.map((line) => {
|
|
32572
|
-
const from = x <
|
|
32572
|
+
const from = x < clip3.x1 ? clip3.x1 - x : 0;
|
|
32573
32573
|
const width = stringWidth(line);
|
|
32574
|
-
const to = x + width >
|
|
32574
|
+
const to = x + width > clip3.x2 ? clip3.x2 - x : width;
|
|
32575
32575
|
return sliceAnsi2(line, from, to);
|
|
32576
32576
|
});
|
|
32577
|
-
if (x <
|
|
32578
|
-
x =
|
|
32577
|
+
if (x < clip3.x1) {
|
|
32578
|
+
x = clip3.x1;
|
|
32579
32579
|
}
|
|
32580
32580
|
}
|
|
32581
32581
|
if (clipVertically) {
|
|
32582
|
-
const from = y <
|
|
32582
|
+
const from = y < clip3.y1 ? clip3.y1 - y : 0;
|
|
32583
32583
|
const height = lines.length;
|
|
32584
|
-
const to = y + height >
|
|
32584
|
+
const to = y + height > clip3.y2 ? clip3.y2 - y : height;
|
|
32585
32585
|
lines = lines.slice(from, to);
|
|
32586
|
-
if (y <
|
|
32587
|
-
y =
|
|
32586
|
+
if (y < clip3.y1) {
|
|
32587
|
+
y = clip3.y1;
|
|
32588
32588
|
}
|
|
32589
32589
|
}
|
|
32590
32590
|
}
|
|
@@ -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);
|
|
@@ -33957,14 +33963,21 @@ function resolveEngineBin(env3 = process.env, from) {
|
|
|
33957
33963
|
}
|
|
33958
33964
|
|
|
33959
33965
|
// src/engine/catalog.ts
|
|
33966
|
+
var LATENT_ID = "latent";
|
|
33967
|
+
var VENICE_ID = "venice";
|
|
33960
33968
|
function describeConnection(provider, integration) {
|
|
33969
|
+
if (provider.id === LATENT_ID) return { kind: "latent", via: "paid from your credits" };
|
|
33961
33970
|
const conn = integration?.connections[0];
|
|
33971
|
+
if (provider.id === VENICE_ID && conn?.type === "credential") return { kind: "key", via: "your Venice key \xB7 DIEM first" };
|
|
33962
33972
|
if (conn?.type === "env") return { kind: "env", via: `env ${conn.name}` };
|
|
33963
33973
|
if (conn?.type === "credential") {
|
|
33964
33974
|
if (conn.method === "oauth") return { kind: "account", via: "account sign-in" };
|
|
33965
33975
|
if (conn.method === "external") return { kind: "local", via: "local login" };
|
|
33966
33976
|
return { kind: "key", via: "API key" };
|
|
33967
33977
|
}
|
|
33978
|
+
if (provider.settings?.apiKey !== "public" && provider.activation === "enabled" && /-compatible$/.test(provider.package ?? "")) {
|
|
33979
|
+
return { kind: "local", via: "custom endpoint" };
|
|
33980
|
+
}
|
|
33968
33981
|
if (provider.settings?.apiKey === "public" || provider.activation === "enabled") {
|
|
33969
33982
|
return { kind: "builtin", via: "built in \xB7 free models" };
|
|
33970
33983
|
}
|
|
@@ -33986,9 +33999,9 @@ function toModel(m) {
|
|
|
33986
33999
|
}
|
|
33987
34000
|
function buildCatalog(providers, integrations, models) {
|
|
33988
34001
|
const byId = new Map(integrations.map((i) => [i.id, i]));
|
|
33989
|
-
const
|
|
34002
|
+
const list2 = models.filter((m) => m.enabled !== false && m.status !== "deprecated").map(toModel);
|
|
33990
34003
|
const count = /* @__PURE__ */ new Map();
|
|
33991
|
-
for (const m of
|
|
34004
|
+
for (const m of list2) count.set(m.providerID, (count.get(m.providerID) ?? 0) + 1);
|
|
33992
34005
|
const out = providers.map((p) => {
|
|
33993
34006
|
const integrationID = p.integrationID ?? p.id;
|
|
33994
34007
|
return {
|
|
@@ -34002,9 +34015,12 @@ function buildCatalog(providers, integrations, models) {
|
|
|
34002
34015
|
for (const [id, n] of count) {
|
|
34003
34016
|
if (!out.some((p) => p.id === id)) out.push({ id, name: id, integrationID: id, kind: "unknown", via: "connected", models: n });
|
|
34004
34017
|
}
|
|
34005
|
-
|
|
34006
|
-
|
|
34007
|
-
|
|
34018
|
+
out.sort((a2, b) => providerRank(a2) - providerRank(b) || a2.models - b.models || a2.name.localeCompare(b.name));
|
|
34019
|
+
return { providers: out, models: list2 };
|
|
34020
|
+
}
|
|
34021
|
+
var KIND_RANK = { latent: 0, account: 2, key: 3, local: 4, env: 5, unknown: 6, builtin: 7 };
|
|
34022
|
+
function providerRank(p) {
|
|
34023
|
+
return p.id === VENICE_ID && p.kind !== "builtin" ? 1 : KIND_RANK[p.kind];
|
|
34008
34024
|
}
|
|
34009
34025
|
var STATUS_RANK = {
|
|
34010
34026
|
ok: 0,
|
|
@@ -34017,7 +34033,7 @@ var STATUS_RANK = {
|
|
|
34017
34033
|
function searchModels(catalog, query, opts = {}) {
|
|
34018
34034
|
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
34019
34035
|
const providerName = new Map(catalog.providers.map((p) => [p.id, p.name]));
|
|
34020
|
-
const
|
|
34036
|
+
const providerRank2 = new Map(catalog.providers.map((p, i) => [p.id, i]));
|
|
34021
34037
|
const status2 = opts.status ?? (() => "unknown");
|
|
34022
34038
|
const hits = catalog.models.filter((m) => {
|
|
34023
34039
|
if (opts.provider && m.providerID !== opts.provider) return false;
|
|
@@ -34035,7 +34051,7 @@ function searchModels(catalog, query, opts = {}) {
|
|
|
34035
34051
|
return 2;
|
|
34036
34052
|
};
|
|
34037
34053
|
return hits.sort(
|
|
34038
|
-
(a2, b) => Number(b.key === opts.current) - Number(a2.key === opts.current) || STATUS_RANK[status2(a2.key)] - STATUS_RANK[status2(b.key)] || score(a2) - score(b) || (
|
|
34054
|
+
(a2, b) => Number(b.key === opts.current) - Number(a2.key === opts.current) || STATUS_RANK[status2(a2.key)] - STATUS_RANK[status2(b.key)] || score(a2) - score(b) || (providerRank2.get(a2.providerID) ?? 99) - (providerRank2.get(b.providerID) ?? 99) || b.released - a2.released || a2.name.localeCompare(b.name)
|
|
34039
34055
|
);
|
|
34040
34056
|
}
|
|
34041
34057
|
function fmtContext(n) {
|
|
@@ -34047,7 +34063,7 @@ function fmtPrice(m, kind) {
|
|
|
34047
34063
|
if (m.costIn === null) return kind === "account" || kind === "local" ? "plan" : "";
|
|
34048
34064
|
if (!m.costIn && !m.costOut) return "free";
|
|
34049
34065
|
const n = (v) => v === null ? "?" : v >= 10 ? String(Math.round(v)) : String(+v.toFixed(2));
|
|
34050
|
-
return `$${n(m.costIn)}/${n(m.costOut)}`;
|
|
34066
|
+
return kind === "latent" ? `${n(m.costIn)}/${n(m.costOut)} cr` : `$${n(m.costIn)}/${n(m.costOut)}`;
|
|
34051
34067
|
}
|
|
34052
34068
|
function fmtTokens(n) {
|
|
34053
34069
|
if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
|
|
@@ -34061,6 +34077,7 @@ function parseKey(key) {
|
|
|
34061
34077
|
return { providerID: key.slice(0, i), id: key.slice(i + 1) };
|
|
34062
34078
|
}
|
|
34063
34079
|
var POPULAR_INTEGRATIONS = [
|
|
34080
|
+
"claude-agent",
|
|
34064
34081
|
"anthropic",
|
|
34065
34082
|
"openai",
|
|
34066
34083
|
"google",
|
|
@@ -34075,7 +34092,7 @@ var POPULAR_INTEGRATIONS = [
|
|
|
34075
34092
|
];
|
|
34076
34093
|
function searchIntegrations(integrations, query) {
|
|
34077
34094
|
const q = query.trim().toLowerCase();
|
|
34078
|
-
const usable2 = integrations.filter((i) => i.methods.some((m) => m.type === "key" || m.type === "oauth"));
|
|
34095
|
+
const usable2 = integrations.filter((i) => i.methods.some((m) => m.type === "key" || m.type === "oauth" || m.type === "external"));
|
|
34079
34096
|
const rank = (i) => {
|
|
34080
34097
|
const p = POPULAR_INTEGRATIONS.indexOf(i.id);
|
|
34081
34098
|
return p === -1 ? POPULAR_INTEGRATIONS.length : p;
|
|
@@ -34102,6 +34119,344 @@ function pickerRows(catalog, query, opts = {}) {
|
|
|
34102
34119
|
return rows;
|
|
34103
34120
|
}
|
|
34104
34121
|
|
|
34122
|
+
// src/engine/mcp.ts
|
|
34123
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync4, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
34124
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
34125
|
+
|
|
34126
|
+
// src/engine/customProvider.ts
|
|
34127
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync3, renameSync, writeFileSync, copyFileSync } from "node:fs";
|
|
34128
|
+
import { homedir as homedir2 } from "node:os";
|
|
34129
|
+
import { join as join2 } from "node:path";
|
|
34130
|
+
var KIND_PACKAGE = {
|
|
34131
|
+
openai: "@opencode/ai/providers/openai-compatible",
|
|
34132
|
+
anthropic: "@opencode/ai/providers/anthropic-compatible"
|
|
34133
|
+
};
|
|
34134
|
+
var KIND_LABEL = {
|
|
34135
|
+
openai: "OpenAI-compatible",
|
|
34136
|
+
anthropic: "Anthropic-compatible"
|
|
34137
|
+
};
|
|
34138
|
+
var CONFIG_FILES = ["opencode.json", "opencode.jsonc"];
|
|
34139
|
+
function slugify(name) {
|
|
34140
|
+
return name.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
34141
|
+
}
|
|
34142
|
+
function providerIdFor(name, taken, custom) {
|
|
34143
|
+
const base = slugify(name) || "custom";
|
|
34144
|
+
if (custom.has(base) || !taken.has(base)) return base;
|
|
34145
|
+
for (let i = 0; ; i++) {
|
|
34146
|
+
const id = i === 0 ? `${base}-custom` : `${base}-custom-${i + 1}`;
|
|
34147
|
+
if (custom.has(id) || !taken.has(id)) return id;
|
|
34148
|
+
}
|
|
34149
|
+
}
|
|
34150
|
+
function normalizeBaseURL(raw) {
|
|
34151
|
+
const s2 = raw.trim();
|
|
34152
|
+
let u;
|
|
34153
|
+
try {
|
|
34154
|
+
u = new URL(s2);
|
|
34155
|
+
} catch {
|
|
34156
|
+
throw new Error("That is not a URL. Example: https://api.example.com/v1");
|
|
34157
|
+
}
|
|
34158
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("The base URL must start with https:// or http://");
|
|
34159
|
+
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");
|
|
34160
|
+
return u.toString().replace(/\/+$/, "");
|
|
34161
|
+
}
|
|
34162
|
+
function parseModelList(raw) {
|
|
34163
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34164
|
+
for (const part of raw.split(/[\s,]+/)) {
|
|
34165
|
+
const id = part.trim();
|
|
34166
|
+
if (id) seen.add(id);
|
|
34167
|
+
}
|
|
34168
|
+
return [...seen];
|
|
34169
|
+
}
|
|
34170
|
+
function providerEntry(input) {
|
|
34171
|
+
const models = {};
|
|
34172
|
+
for (const id of input.models) models[id] = modelEntry(id, input.details?.[id]);
|
|
34173
|
+
return {
|
|
34174
|
+
name: input.name.trim(),
|
|
34175
|
+
package: KIND_PACKAGE[input.kind],
|
|
34176
|
+
settings: { baseURL: input.baseURL },
|
|
34177
|
+
models
|
|
34178
|
+
};
|
|
34179
|
+
}
|
|
34180
|
+
function modelEntry(id, d) {
|
|
34181
|
+
const out = { name: d?.name || id };
|
|
34182
|
+
if (d?.context) out.limit = { context: d.context, ...d.output ? { output: d.output } : {} };
|
|
34183
|
+
if (d?.cost) {
|
|
34184
|
+
out.cost = [{ input: d.cost.input, output: d.cost.output, ...d.cost.cacheRead != null ? { cache: { read: d.cost.cacheRead } } : {} }];
|
|
34185
|
+
}
|
|
34186
|
+
return out;
|
|
34187
|
+
}
|
|
34188
|
+
function parseJsonc(text) {
|
|
34189
|
+
let out = "";
|
|
34190
|
+
let hadComments = false;
|
|
34191
|
+
let i = 0;
|
|
34192
|
+
while (i < text.length) {
|
|
34193
|
+
const ch = text[i];
|
|
34194
|
+
if (ch === '"') {
|
|
34195
|
+
let j = i + 1;
|
|
34196
|
+
while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
|
|
34197
|
+
out += text.slice(i, j + 1);
|
|
34198
|
+
i = j + 1;
|
|
34199
|
+
} else if (ch === "/" && text[i + 1] === "/") {
|
|
34200
|
+
hadComments = true;
|
|
34201
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
34202
|
+
} else if (ch === "/" && text[i + 1] === "*") {
|
|
34203
|
+
hadComments = true;
|
|
34204
|
+
const end2 = text.indexOf("*/", i + 2);
|
|
34205
|
+
i = end2 < 0 ? text.length : end2 + 2;
|
|
34206
|
+
} else {
|
|
34207
|
+
if (ch === "}" || ch === "]") {
|
|
34208
|
+
const m = out.match(/,\s*$/);
|
|
34209
|
+
if (m) out = out.slice(0, out.length - m[0].length) + m[0].slice(1);
|
|
34210
|
+
}
|
|
34211
|
+
out += ch;
|
|
34212
|
+
i++;
|
|
34213
|
+
}
|
|
34214
|
+
}
|
|
34215
|
+
return { value: out.trim() ? JSON.parse(out) : {}, hadComments };
|
|
34216
|
+
}
|
|
34217
|
+
function mergeProvider(existing, id, entry, defaultModel) {
|
|
34218
|
+
const { value, hadComments } = existing ? parseJsonc(existing) : { value: {}, hadComments: false };
|
|
34219
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The engine config file is not a JSON object.");
|
|
34220
|
+
const config = value;
|
|
34221
|
+
const providers = config.providers;
|
|
34222
|
+
if (providers !== void 0 && (typeof providers !== "object" || providers === null || Array.isArray(providers))) {
|
|
34223
|
+
throw new Error('The engine config has a "providers" value that is not an object.');
|
|
34224
|
+
}
|
|
34225
|
+
const next = { ...config, providers: { ...providers ?? {}, [id]: entry } };
|
|
34226
|
+
if (!("$schema" in next)) next.$schema = "https://opencode.ai/config.json";
|
|
34227
|
+
if (defaultModel && !next.model) next.model = defaultModel;
|
|
34228
|
+
return { text: JSON.stringify(next, null, 2) + "\n", hadComments };
|
|
34229
|
+
}
|
|
34230
|
+
function configuredProviderIds(text) {
|
|
34231
|
+
if (!text) return /* @__PURE__ */ new Set();
|
|
34232
|
+
try {
|
|
34233
|
+
const v = parseJsonc(text).value;
|
|
34234
|
+
return new Set(Object.keys(v?.providers ?? {}));
|
|
34235
|
+
} catch {
|
|
34236
|
+
return /* @__PURE__ */ new Set();
|
|
34237
|
+
}
|
|
34238
|
+
}
|
|
34239
|
+
function defaultConfigDir(env3 = process.env) {
|
|
34240
|
+
return join2(env3.XDG_CONFIG_HOME || join2(homedir2(), ".config"), "opencode");
|
|
34241
|
+
}
|
|
34242
|
+
function configFileIn(dir, exists = existsSync3) {
|
|
34243
|
+
const present = CONFIG_FILES.map((f) => join2(dir, f)).filter(exists);
|
|
34244
|
+
return present.at(-1) ?? join2(dir, "opencode.json");
|
|
34245
|
+
}
|
|
34246
|
+
function readConfigText(file) {
|
|
34247
|
+
try {
|
|
34248
|
+
return readFileSync3(file, "utf8");
|
|
34249
|
+
} catch {
|
|
34250
|
+
return null;
|
|
34251
|
+
}
|
|
34252
|
+
}
|
|
34253
|
+
function writeProviderConfig(file, id, input, defaultModel) {
|
|
34254
|
+
const existing = readConfigText(file);
|
|
34255
|
+
const { text, hadComments } = mergeProvider(existing, id, providerEntry(input), defaultModel);
|
|
34256
|
+
mkdirSync(join2(file, ".."), { recursive: true });
|
|
34257
|
+
let backup;
|
|
34258
|
+
if (existing !== null && hadComments) {
|
|
34259
|
+
backup = file + ".bak";
|
|
34260
|
+
copyFileSync(file, backup);
|
|
34261
|
+
}
|
|
34262
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
34263
|
+
writeFileSync(tmp, text);
|
|
34264
|
+
renameSync(tmp, file);
|
|
34265
|
+
return { file, backup };
|
|
34266
|
+
}
|
|
34267
|
+
async function discoverModels(kind, baseURL, key, timeoutMs = 1e4) {
|
|
34268
|
+
const headers = kind === "anthropic" ? { "anthropic-version": "2023-06-01", ...key ? { "x-api-key": key } : {} } : key ? { authorization: `Bearer ${key}` } : {};
|
|
34269
|
+
const res = await fetch(baseURL + "/models", { headers, signal: AbortSignal.timeout(timeoutMs) });
|
|
34270
|
+
if (!res.ok) throw new Error(`${baseURL}/models answered ${res.status}`);
|
|
34271
|
+
return parseModelsResponse(await res.json());
|
|
34272
|
+
}
|
|
34273
|
+
function parseModelsResponse(body) {
|
|
34274
|
+
const data = body?.data ?? body?.models;
|
|
34275
|
+
if (!Array.isArray(data)) throw new Error("The /models answer has no model list.");
|
|
34276
|
+
return parseModelList(
|
|
34277
|
+
data.map((m) => typeof m === "string" ? m : typeof m === "object" && m ? String(m.id ?? "") : "").join(" ")
|
|
34278
|
+
);
|
|
34279
|
+
}
|
|
34280
|
+
|
|
34281
|
+
// src/engine/mcp.ts
|
|
34282
|
+
function toMcpServer(raw) {
|
|
34283
|
+
const st = typeof raw.status === "string" ? { status: raw.status } : raw.status ?? {};
|
|
34284
|
+
return {
|
|
34285
|
+
name: raw.name,
|
|
34286
|
+
status: st.status ?? "pending",
|
|
34287
|
+
...st.error ? { error: st.error } : {},
|
|
34288
|
+
...raw.title ? { title: raw.title } : {},
|
|
34289
|
+
...raw.integrationID ? { integrationID: raw.integrationID } : {}
|
|
34290
|
+
};
|
|
34291
|
+
}
|
|
34292
|
+
var STATUS_LABEL = {
|
|
34293
|
+
connected: "connected",
|
|
34294
|
+
pending: "starting\u2026",
|
|
34295
|
+
disabled: "off",
|
|
34296
|
+
failed: "failed",
|
|
34297
|
+
needs_auth: "needs sign-in"
|
|
34298
|
+
};
|
|
34299
|
+
function statusLabel(s2) {
|
|
34300
|
+
return STATUS_LABEL[s2] ?? s2;
|
|
34301
|
+
}
|
|
34302
|
+
function tokenize3(line) {
|
|
34303
|
+
const out = [];
|
|
34304
|
+
let cur = "";
|
|
34305
|
+
let has = false;
|
|
34306
|
+
let quote = null;
|
|
34307
|
+
for (let i = 0; i < line.length; i++) {
|
|
34308
|
+
const ch = line[i];
|
|
34309
|
+
if (quote) {
|
|
34310
|
+
if (ch === quote) quote = null;
|
|
34311
|
+
else if (ch === "\\" && quote === '"' && i + 1 < line.length) cur += line[++i];
|
|
34312
|
+
else cur += ch;
|
|
34313
|
+
} else if (ch === '"' || ch === "'") {
|
|
34314
|
+
quote = ch;
|
|
34315
|
+
has = true;
|
|
34316
|
+
} else if (ch === "\\" && i + 1 < line.length) {
|
|
34317
|
+
cur += line[++i];
|
|
34318
|
+
has = true;
|
|
34319
|
+
} else if (/\s/.test(ch)) {
|
|
34320
|
+
if (has) out.push(cur);
|
|
34321
|
+
cur = "";
|
|
34322
|
+
has = false;
|
|
34323
|
+
} else {
|
|
34324
|
+
cur += ch;
|
|
34325
|
+
has = true;
|
|
34326
|
+
}
|
|
34327
|
+
}
|
|
34328
|
+
if (quote) throw new Error("A quote is not closed.");
|
|
34329
|
+
if (has) out.push(cur);
|
|
34330
|
+
return out;
|
|
34331
|
+
}
|
|
34332
|
+
var MCP_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
|
|
34333
|
+
function pair(flag, v) {
|
|
34334
|
+
const i = v ? v.indexOf("=") : -1;
|
|
34335
|
+
if (!v || i <= 0) throw new Error(`${flag} needs name=value`);
|
|
34336
|
+
return [v.slice(0, i), v.slice(i + 1)];
|
|
34337
|
+
}
|
|
34338
|
+
function parseMcpAdd(input) {
|
|
34339
|
+
const t = typeof input === "string" ? tokenize3(input) : [...input];
|
|
34340
|
+
if (t[0] === "mcp" && t[1] === "add") t.splice(0, 2);
|
|
34341
|
+
const headers = {};
|
|
34342
|
+
const env3 = {};
|
|
34343
|
+
let name = "";
|
|
34344
|
+
let url;
|
|
34345
|
+
const rest = [];
|
|
34346
|
+
for (let i = 0; i < t.length; i++) {
|
|
34347
|
+
const a2 = t[i];
|
|
34348
|
+
if (a2 === "--") {
|
|
34349
|
+
rest.push(...t.slice(i + 1));
|
|
34350
|
+
break;
|
|
34351
|
+
}
|
|
34352
|
+
if (a2 === "--url") url = t[++i];
|
|
34353
|
+
else if (a2.startsWith("--url=")) url = a2.slice(6);
|
|
34354
|
+
else if (a2 === "--header") {
|
|
34355
|
+
const [k, v] = pair("--header", t[++i]);
|
|
34356
|
+
headers[k] = v;
|
|
34357
|
+
} else if (a2 === "--env") {
|
|
34358
|
+
const [k, v] = pair("--env", t[++i]);
|
|
34359
|
+
env3[k] = v;
|
|
34360
|
+
} else if (a2 === "--global") continue;
|
|
34361
|
+
else if (!name) name = a2;
|
|
34362
|
+
else rest.push(a2);
|
|
34363
|
+
}
|
|
34364
|
+
if (!name) throw new Error("Give the server a name first, e.g. github https://api.example.com/mcp");
|
|
34365
|
+
if (!MCP_NAME_RE.test(name)) throw new Error("The name may use letters, digits, - _ and . (up to 64).");
|
|
34366
|
+
if (!url && rest.length === 1 && /^[a-z][a-z0-9+.-]*:\/\//i.test(rest[0])) url = rest.shift();
|
|
34367
|
+
if (url) {
|
|
34368
|
+
if (rest.length) throw new Error("A remote server takes a URL, not a command.");
|
|
34369
|
+
let u;
|
|
34370
|
+
try {
|
|
34371
|
+
u = new URL(url);
|
|
34372
|
+
} catch {
|
|
34373
|
+
throw new Error("That URL is not valid.");
|
|
34374
|
+
}
|
|
34375
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error("The URL must start with https:// or http://");
|
|
34376
|
+
if (Object.keys(env3).length) throw new Error("--env is for local servers; a remote one takes --header.");
|
|
34377
|
+
return { name, type: "remote", url, headers, env: {} };
|
|
34378
|
+
}
|
|
34379
|
+
if (!rest.length) throw new Error("Add a URL (remote server) or the command that starts it (local server).");
|
|
34380
|
+
if (Object.keys(headers).length) throw new Error("--header is for remote servers; a local one takes --env.");
|
|
34381
|
+
return { name, type: "local", command: rest, headers: {}, env: env3 };
|
|
34382
|
+
}
|
|
34383
|
+
function mcpAddArgv(s2, scope = "global") {
|
|
34384
|
+
const argv = ["mcp", "add", ...scope === "global" ? ["--global"] : []];
|
|
34385
|
+
if (s2.type === "remote") {
|
|
34386
|
+
argv.push("--url", s2.url);
|
|
34387
|
+
for (const [k, v] of Object.entries(s2.headers)) argv.push("--header", `${k}=${v}`);
|
|
34388
|
+
argv.push(s2.name);
|
|
34389
|
+
} else {
|
|
34390
|
+
for (const [k, v] of Object.entries(s2.env)) argv.push("--env", `${k}=${v}`);
|
|
34391
|
+
argv.push(s2.name, "--", ...s2.command);
|
|
34392
|
+
}
|
|
34393
|
+
return argv;
|
|
34394
|
+
}
|
|
34395
|
+
function removeMcpFromText(text, name) {
|
|
34396
|
+
const { value, hadComments } = parseJsonc(text);
|
|
34397
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return { text, removed: false, hadComments };
|
|
34398
|
+
const config = value;
|
|
34399
|
+
const mcp = config.mcp;
|
|
34400
|
+
if (!mcp || typeof mcp !== "object") return { text, removed: false, hadComments };
|
|
34401
|
+
const servers = mcp.servers;
|
|
34402
|
+
let next = null;
|
|
34403
|
+
if (servers && typeof servers === "object" && name in servers) {
|
|
34404
|
+
const { [name]: _gone, ...keep } = servers;
|
|
34405
|
+
next = { ...config, mcp: { ...mcp, servers: keep } };
|
|
34406
|
+
} else if (name !== "servers" && name in mcp) {
|
|
34407
|
+
const { [name]: _gone, ...keep } = mcp;
|
|
34408
|
+
next = { ...config, mcp: keep };
|
|
34409
|
+
}
|
|
34410
|
+
if (!next) return { text, removed: false, hadComments };
|
|
34411
|
+
return { text: JSON.stringify(next, null, 2) + "\n", removed: true, hadComments };
|
|
34412
|
+
}
|
|
34413
|
+
function candidateConfigFiles(globalDir, cwd2, exists = existsSync4) {
|
|
34414
|
+
const out = CONFIG_FILES.map((f) => join3(globalDir, f)).filter(exists);
|
|
34415
|
+
let dir = cwd2;
|
|
34416
|
+
for (; ; ) {
|
|
34417
|
+
for (const base of [dir, join3(dir, ".opencode")]) for (const f of CONFIG_FILES) if (exists(join3(base, f))) out.push(join3(base, f));
|
|
34418
|
+
const up = dirname2(dir);
|
|
34419
|
+
if (up === dir) break;
|
|
34420
|
+
dir = up;
|
|
34421
|
+
}
|
|
34422
|
+
return [...new Set(out)];
|
|
34423
|
+
}
|
|
34424
|
+
function removeMcpFromFiles(files, name) {
|
|
34425
|
+
for (const file of files) {
|
|
34426
|
+
let text;
|
|
34427
|
+
try {
|
|
34428
|
+
text = readFileSync4(file, "utf8");
|
|
34429
|
+
} catch {
|
|
34430
|
+
continue;
|
|
34431
|
+
}
|
|
34432
|
+
let r;
|
|
34433
|
+
try {
|
|
34434
|
+
r = removeMcpFromText(text, name);
|
|
34435
|
+
} catch {
|
|
34436
|
+
continue;
|
|
34437
|
+
}
|
|
34438
|
+
if (!r.removed) continue;
|
|
34439
|
+
let backup;
|
|
34440
|
+
if (r.hadComments) {
|
|
34441
|
+
backup = file + ".bak";
|
|
34442
|
+
copyFileSync2(file, backup);
|
|
34443
|
+
}
|
|
34444
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
34445
|
+
writeFileSync2(tmp, r.text);
|
|
34446
|
+
renameSync2(tmp, file);
|
|
34447
|
+
return { file, backup };
|
|
34448
|
+
}
|
|
34449
|
+
return null;
|
|
34450
|
+
}
|
|
34451
|
+
function mcpSummary(list2) {
|
|
34452
|
+
return {
|
|
34453
|
+
total: list2.length,
|
|
34454
|
+
connected: list2.filter((s2) => s2.status === "connected").length,
|
|
34455
|
+
needsAuth: list2.filter((s2) => s2.status === "needs_auth").length,
|
|
34456
|
+
failed: list2.filter((s2) => s2.status === "failed").length
|
|
34457
|
+
};
|
|
34458
|
+
}
|
|
34459
|
+
|
|
34105
34460
|
// src/engine/server.ts
|
|
34106
34461
|
var SAFE_PERMISSIONS = [
|
|
34107
34462
|
{ action: "shell", resource: "*", effect: "ask" },
|
|
@@ -34123,6 +34478,9 @@ var Engine = class _Engine {
|
|
|
34123
34478
|
url;
|
|
34124
34479
|
auth;
|
|
34125
34480
|
child;
|
|
34481
|
+
/** The binary and project this server runs (unset for `attach`). */
|
|
34482
|
+
bin;
|
|
34483
|
+
cwd;
|
|
34126
34484
|
/** Start a private server in `cwd` (the user's project). */
|
|
34127
34485
|
static async start(opts) {
|
|
34128
34486
|
const bin = opts.bin ?? resolveEngineBin()?.path;
|
|
@@ -34173,7 +34531,10 @@ ${seen.slice(-800)}`));
|
|
|
34173
34531
|
});
|
|
34174
34532
|
child.stdout.resume();
|
|
34175
34533
|
child.stderr.resume();
|
|
34176
|
-
|
|
34534
|
+
const engine = new _Engine(url, auth2, child);
|
|
34535
|
+
engine.bin = bin;
|
|
34536
|
+
engine.cwd = opts.cwd;
|
|
34537
|
+
return engine;
|
|
34177
34538
|
}
|
|
34178
34539
|
/** Attach to an already running server (tests, `--server`). */
|
|
34179
34540
|
static attach(url, password) {
|
|
@@ -34233,9 +34594,51 @@ ${seen.slice(-800)}`));
|
|
|
34233
34594
|
return buildCatalog(providers.data, integrations, models.data);
|
|
34234
34595
|
}
|
|
34235
34596
|
/** Store an API key for a provider. The key goes to the local engine only. */
|
|
34597
|
+
/** The engine's global config directory, as it reports it (`GET /api/config`). */
|
|
34598
|
+
async configDir() {
|
|
34599
|
+
try {
|
|
34600
|
+
const r = await this.call(
|
|
34601
|
+
"GET",
|
|
34602
|
+
"/api/config"
|
|
34603
|
+
);
|
|
34604
|
+
const list2 = Array.isArray(r) ? r : r.data ?? [];
|
|
34605
|
+
const dir = list2.find((x) => x.type === "directory" && x.path);
|
|
34606
|
+
return dir?.path ?? null;
|
|
34607
|
+
} catch {
|
|
34608
|
+
return null;
|
|
34609
|
+
}
|
|
34610
|
+
}
|
|
34611
|
+
/**
|
|
34612
|
+
* Re-read the config files. Running sessions carry on; the event stream
|
|
34613
|
+
* stays open. The new providers can lag the response by a moment, so
|
|
34614
|
+
* `waitForIntegration` polls for the one we expect.
|
|
34615
|
+
*/
|
|
34616
|
+
async reloadConfig() {
|
|
34617
|
+
await this.call("POST", "/api/location/reload");
|
|
34618
|
+
}
|
|
34619
|
+
async waitForIntegration(id, timeoutMs = 1e4) {
|
|
34620
|
+
const until = Date.now() + timeoutMs;
|
|
34621
|
+
let last;
|
|
34622
|
+
while (Date.now() < until) {
|
|
34623
|
+
try {
|
|
34624
|
+
return (await this.call("GET", `/api/integration/${encodeURIComponent(id)}`)).data;
|
|
34625
|
+
} catch (e) {
|
|
34626
|
+
last = e;
|
|
34627
|
+
}
|
|
34628
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
34629
|
+
}
|
|
34630
|
+
throw new EngineError(`The engine did not pick up provider "${id}" after reloading its config. ${last instanceof Error ? last.message : ""}`.trim());
|
|
34631
|
+
}
|
|
34236
34632
|
async connectKey(integrationID, key) {
|
|
34237
34633
|
await this.call("POST", `/api/integration/${encodeURIComponent(integrationID)}/connect/key`, { key });
|
|
34238
34634
|
}
|
|
34635
|
+
/**
|
|
34636
|
+
* A login another program on this machine holds (e.g. Claude Agent → the
|
|
34637
|
+
* user's `claude` CLI). The engine checks it and connects, or says why not.
|
|
34638
|
+
*/
|
|
34639
|
+
async connectExternal(integrationID, methodID) {
|
|
34640
|
+
await this.call("POST", `/api/integration/${encodeURIComponent(integrationID)}/connect/external`, { methodID });
|
|
34641
|
+
}
|
|
34239
34642
|
async beginOAuth(integrationID, methodID, answer) {
|
|
34240
34643
|
const r = await this.call(
|
|
34241
34644
|
"POST",
|
|
@@ -34265,6 +34668,60 @@ ${seen.slice(-800)}`));
|
|
|
34265
34668
|
).catch(() => {
|
|
34266
34669
|
});
|
|
34267
34670
|
}
|
|
34671
|
+
async integration(id) {
|
|
34672
|
+
return (await this.call("GET", `/api/integration/${encodeURIComponent(id)}`)).data;
|
|
34673
|
+
}
|
|
34674
|
+
/** MCP servers from every config the engine read (OpenCode's included), with live status. */
|
|
34675
|
+
async mcpList() {
|
|
34676
|
+
const r = await this.call("GET", "/api/mcp");
|
|
34677
|
+
return (r.data ?? []).map(toMcpServer);
|
|
34678
|
+
}
|
|
34679
|
+
/** Start a configured server for this session (also one that is off in the config). */
|
|
34680
|
+
async mcpConnect(name) {
|
|
34681
|
+
await this.call("POST", `/api/experimental/mcp/${encodeURIComponent(name)}/connect`);
|
|
34682
|
+
}
|
|
34683
|
+
/** Stop a server for this session; the config is left as it is. */
|
|
34684
|
+
async mcpDisconnect(name) {
|
|
34685
|
+
await this.call("POST", `/api/experimental/mcp/${encodeURIComponent(name)}/disconnect`);
|
|
34686
|
+
}
|
|
34687
|
+
/** Drop a server from the running engine (the config file is a separate step). */
|
|
34688
|
+
async mcpDrop(name) {
|
|
34689
|
+
await this.call("DELETE", `/api/experimental/mcp/${encodeURIComponent(name)}`).catch(() => {
|
|
34690
|
+
});
|
|
34691
|
+
}
|
|
34692
|
+
/**
|
|
34693
|
+
* Run one of the engine's own CLI commands (e.g. `mcp add`) to completion,
|
|
34694
|
+
* in the session's project. Output is captured, never printed.
|
|
34695
|
+
*/
|
|
34696
|
+
async runCli(argv, timeoutMs = 3e4) {
|
|
34697
|
+
const bin = this.bin ?? resolveEngineBin()?.path;
|
|
34698
|
+
if (!bin) throw new EngineError(ENGINE_NOT_FOUND);
|
|
34699
|
+
return new Promise((resolve2, reject) => {
|
|
34700
|
+
const child = spawn(bin, argv, { cwd: this.cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
34701
|
+
let out = "";
|
|
34702
|
+
const timer = setTimeout(() => child.kill(), timeoutMs);
|
|
34703
|
+
child.stdout.on("data", (b) => out += b.toString());
|
|
34704
|
+
child.stderr.on("data", (b) => out += b.toString());
|
|
34705
|
+
child.once("error", (e) => {
|
|
34706
|
+
clearTimeout(timer);
|
|
34707
|
+
reject(new EngineError(`could not run opencode: ${e.message}`));
|
|
34708
|
+
});
|
|
34709
|
+
child.once("exit", (code) => {
|
|
34710
|
+
clearTimeout(timer);
|
|
34711
|
+
resolve2({ code: code ?? 1, out });
|
|
34712
|
+
});
|
|
34713
|
+
});
|
|
34714
|
+
}
|
|
34715
|
+
/** Poll until `name` shows up after a config reload. */
|
|
34716
|
+
async waitForMcp(name, timeoutMs = 1e4) {
|
|
34717
|
+
const until = Date.now() + timeoutMs;
|
|
34718
|
+
while (Date.now() < until) {
|
|
34719
|
+
const hit = (await this.mcpList().catch(() => [])).find((s2) => s2.name === name);
|
|
34720
|
+
if (hit) return hit;
|
|
34721
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
34722
|
+
}
|
|
34723
|
+
throw new EngineError(`The engine did not pick up MCP server "${name}" after reloading its config.`);
|
|
34724
|
+
}
|
|
34268
34725
|
/** The agent's own slash commands (/init, /review, …). */
|
|
34269
34726
|
async commands() {
|
|
34270
34727
|
try {
|
|
@@ -34341,43 +34798,50 @@ ${seen.slice(-800)}`));
|
|
|
34341
34798
|
};
|
|
34342
34799
|
|
|
34343
34800
|
// src/index.tsx
|
|
34344
|
-
import { spawnSync } from "node:child_process";
|
|
34801
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
34345
34802
|
|
|
34346
34803
|
// src/ui/Root.tsx
|
|
34347
|
-
var
|
|
34804
|
+
var import_react28 = __toESM(require_react(), 1);
|
|
34348
34805
|
|
|
34349
34806
|
// src/engine/models.ts
|
|
34350
|
-
import { mkdirSync as
|
|
34351
|
-
import { join as
|
|
34807
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
34808
|
+
import { join as join5 } from "node:path";
|
|
34352
34809
|
|
|
34353
34810
|
// src/ads/config.ts
|
|
34354
|
-
import {
|
|
34355
|
-
import {
|
|
34356
|
-
import {
|
|
34811
|
+
import { createHash } from "node:crypto";
|
|
34812
|
+
import { homedir as homedir3, hostname } from "node:os";
|
|
34813
|
+
import { join as join4 } from "node:path";
|
|
34814
|
+
import { chmodSync, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
34357
34815
|
var DEFAULT_SERVER = "https://api.latentprotocol.xyz";
|
|
34358
34816
|
var AGENT_LATENTCODE = "latentcode";
|
|
34359
34817
|
function configDir() {
|
|
34360
|
-
return
|
|
34818
|
+
return join4(homedir3(), ".latent-protocol");
|
|
34361
34819
|
}
|
|
34362
34820
|
function configFile() {
|
|
34363
|
-
return
|
|
34821
|
+
return join4(configDir(), "config.json");
|
|
34364
34822
|
}
|
|
34365
34823
|
function deviceIdFile() {
|
|
34366
|
-
return
|
|
34824
|
+
return join4(configDir(), "device_id");
|
|
34367
34825
|
}
|
|
34368
34826
|
var DEVICE_CREDENTIAL_RE = /^[0-9a-f]{32}\.\d+\.[A-Za-z0-9_-]+$/i;
|
|
34369
34827
|
var WALLET_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
34370
34828
|
function loadConfig() {
|
|
34371
34829
|
try {
|
|
34372
|
-
return JSON.parse(
|
|
34830
|
+
return JSON.parse(readFileSync5(configFile(), "utf8"));
|
|
34373
34831
|
} catch {
|
|
34374
34832
|
return {};
|
|
34375
34833
|
}
|
|
34376
34834
|
}
|
|
34377
34835
|
function saveConfig(data) {
|
|
34378
|
-
|
|
34836
|
+
mkdirSync2(configDir(), { recursive: true });
|
|
34379
34837
|
const next = { ...loadConfig(), ...data };
|
|
34380
|
-
|
|
34838
|
+
writeFileSync3(configFile(), JSON.stringify(next, null, 2) + "\n", { mode: 384 });
|
|
34839
|
+
if (next.latent_key || next.sync_key) {
|
|
34840
|
+
try {
|
|
34841
|
+
chmodSync(configFile(), 384);
|
|
34842
|
+
} catch {
|
|
34843
|
+
}
|
|
34844
|
+
}
|
|
34381
34845
|
return next;
|
|
34382
34846
|
}
|
|
34383
34847
|
function resolveServer(cfg = loadConfig()) {
|
|
@@ -34387,19 +34851,25 @@ function resolveWallet(cfg = loadConfig()) {
|
|
|
34387
34851
|
const w = cfg.wallet || process.env.ADS_WALLET || "";
|
|
34388
34852
|
return WALLET_RE.test(w) ? w : "";
|
|
34389
34853
|
}
|
|
34390
|
-
function adsEnabled(cfg = loadConfig()) {
|
|
34854
|
+
function adsEnabled(cfg = loadConfig(), key = "latentcode_ads") {
|
|
34391
34855
|
const env3 = process.env.ADS_ENABLED;
|
|
34392
34856
|
if (env3 !== void 0) return !["false", "0", "no"].includes(env3.toLowerCase());
|
|
34393
|
-
return cfg
|
|
34857
|
+
return cfg[key] !== false;
|
|
34394
34858
|
}
|
|
34395
34859
|
function deviceId() {
|
|
34396
34860
|
try {
|
|
34397
|
-
const existing =
|
|
34861
|
+
const existing = readFileSync5(deviceIdFile(), "utf8").trim();
|
|
34398
34862
|
if (DEVICE_CREDENTIAL_RE.test(existing)) return existing;
|
|
34399
34863
|
} catch {
|
|
34400
34864
|
}
|
|
34401
34865
|
return "";
|
|
34402
34866
|
}
|
|
34867
|
+
function deviceKeyId() {
|
|
34868
|
+
const cred = deviceId();
|
|
34869
|
+
if (cred) return cred.split(".")[0];
|
|
34870
|
+
return createHash("sha256").update(`${hostname()}
|
|
34871
|
+
${homedir3()}`).digest("hex").slice(0, 32);
|
|
34872
|
+
}
|
|
34403
34873
|
async function ensureDeviceCredential(server) {
|
|
34404
34874
|
const current = deviceId();
|
|
34405
34875
|
if (current) return current;
|
|
@@ -34418,8 +34888,8 @@ async function ensureDeviceCredential(server) {
|
|
|
34418
34888
|
}
|
|
34419
34889
|
if (!DEVICE_CREDENTIAL_RE.test(credential)) return "";
|
|
34420
34890
|
try {
|
|
34421
|
-
|
|
34422
|
-
|
|
34891
|
+
mkdirSync2(configDir(), { recursive: true });
|
|
34892
|
+
writeFileSync3(deviceIdFile(), credential, { flag: "wx" });
|
|
34423
34893
|
return credential;
|
|
34424
34894
|
} catch {
|
|
34425
34895
|
return deviceId() || credential;
|
|
@@ -34428,12 +34898,13 @@ async function ensureDeviceCredential(server) {
|
|
|
34428
34898
|
|
|
34429
34899
|
// src/engine/models.ts
|
|
34430
34900
|
var UNSUPPORTED_RE = /not supported|not available|does not have access|model_not_found|unsupported model/i;
|
|
34901
|
+
var LIMIT_RE = /usage limit|rate.?limit|limit (?:reached|exceeded)|reached your (?:\w+ )?limit|hit your (?:\w+ )?limit|exceeded your (?:current )?quota|too many requests/i;
|
|
34431
34902
|
function classifyError(err, now = Date.now()) {
|
|
34432
34903
|
const e = err && typeof err === "object" ? err : { message: String(err) };
|
|
34433
34904
|
const message = typeof e.message === "string" ? e.message : String(err ?? "");
|
|
34434
34905
|
const reason = String(e.reason ?? e.type ?? "");
|
|
34435
34906
|
const status2 = typeof e.status === "number" ? e.status : 0;
|
|
34436
|
-
if (/rate.?limit/i.test(reason) || status2 === 429) {
|
|
34907
|
+
if (/rate.?limit/i.test(reason) || status2 === 429 || LIMIT_RE.test(message)) {
|
|
34437
34908
|
const retry = typeof e.retryAfterMs === "number" ? e.retryAfterMs : 15 * 6e4;
|
|
34438
34909
|
return { status: "rate-limited", message, until: now + retry, at: now };
|
|
34439
34910
|
}
|
|
@@ -34444,7 +34915,7 @@ function classifyError(err, now = Date.now()) {
|
|
|
34444
34915
|
return { status: "error", message, at: now };
|
|
34445
34916
|
}
|
|
34446
34917
|
function storeFile() {
|
|
34447
|
-
return
|
|
34918
|
+
return join5(configDir(), "latentcode-models.json");
|
|
34448
34919
|
}
|
|
34449
34920
|
var ModelStore = class _ModelStore {
|
|
34450
34921
|
constructor(persist = true, initial) {
|
|
@@ -34455,7 +34926,7 @@ var ModelStore = class _ModelStore {
|
|
|
34455
34926
|
v;
|
|
34456
34927
|
static read() {
|
|
34457
34928
|
try {
|
|
34458
|
-
return JSON.parse(
|
|
34929
|
+
return JSON.parse(readFileSync6(storeFile(), "utf8"));
|
|
34459
34930
|
} catch {
|
|
34460
34931
|
return {};
|
|
34461
34932
|
}
|
|
@@ -34472,8 +34943,8 @@ var ModelStore = class _ModelStore {
|
|
|
34472
34943
|
Object.entries(this.v).filter(([, x]) => x.status === "ok" || x.status === "unsupported")
|
|
34473
34944
|
);
|
|
34474
34945
|
try {
|
|
34475
|
-
|
|
34476
|
-
|
|
34946
|
+
mkdirSync3(configDir(), { recursive: true });
|
|
34947
|
+
writeFileSync4(storeFile(), JSON.stringify(durable, null, 2) + "\n");
|
|
34477
34948
|
} catch {
|
|
34478
34949
|
}
|
|
34479
34950
|
}
|
|
@@ -34500,9 +34971,99 @@ function chooseStartModel(def, all, store) {
|
|
|
34500
34971
|
return ok ? { model: ok, switchedFrom: def } : { model: def };
|
|
34501
34972
|
}
|
|
34502
34973
|
|
|
34974
|
+
// src/ads/controller.ts
|
|
34975
|
+
import { randomUUID } from "node:crypto";
|
|
34976
|
+
|
|
34977
|
+
// src/ads/sanitize.ts
|
|
34978
|
+
var ESC_SEQ = /\x1b\][\s\S]*?(?:\x07|\x1b\\|$)|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[ -/]*[0-~]|\x1b[@-_]/g;
|
|
34979
|
+
var CONTROL = /[\x00-\x1f\x7f-\x9f]/g;
|
|
34980
|
+
var BIDI = /[--]/g;
|
|
34981
|
+
function sanitizeAdText(input, max = 140) {
|
|
34982
|
+
let s2 = String(input ?? "");
|
|
34983
|
+
s2 = s2.replace(ESC_SEQ, "").replace(CONTROL, " ").replace(BIDI, "");
|
|
34984
|
+
s2 = s2.replace(/\s+/g, " ").trim();
|
|
34985
|
+
if (max > 0 && s2.length > max) s2 = `${s2.slice(0, Math.max(0, max - 1)).trimEnd()}\u2026`;
|
|
34986
|
+
return s2;
|
|
34987
|
+
}
|
|
34988
|
+
var AD_LIMITS = { title: 30, body: 140, cta_text: 24 };
|
|
34989
|
+
|
|
34990
|
+
// src/ads/adline.ts
|
|
34991
|
+
var WORD = /[\p{L}\p{N}]/u;
|
|
34992
|
+
var LEAD_SEP = /^[\s\-:–—]+/;
|
|
34993
|
+
function clampField(value, max) {
|
|
34994
|
+
const t = value.trim();
|
|
34995
|
+
if (t.length <= max) return t;
|
|
34996
|
+
return `${t.slice(0, Math.max(1, max - 1)).trimEnd()}\u2026`;
|
|
34997
|
+
}
|
|
34998
|
+
function dedupeBrand(brand, body) {
|
|
34999
|
+
let t = body.trim();
|
|
35000
|
+
const b = brand.trim();
|
|
35001
|
+
if (!b) return t;
|
|
35002
|
+
const lb = b.toLowerCase();
|
|
35003
|
+
while (t.toLowerCase().startsWith(lb)) {
|
|
35004
|
+
const after = t.charAt(b.length);
|
|
35005
|
+
if (after !== "" && WORD.test(after)) break;
|
|
35006
|
+
const rest = t.slice(b.length).replace(LEAD_SEP, "");
|
|
35007
|
+
if (rest === t) break;
|
|
35008
|
+
t = rest;
|
|
35009
|
+
if (t === "") break;
|
|
35010
|
+
}
|
|
35011
|
+
return t;
|
|
35012
|
+
}
|
|
35013
|
+
function composeAdCopy(title, body) {
|
|
35014
|
+
const brandRaw = sanitizeAdText(title, 0);
|
|
35015
|
+
const bodyRaw = sanitizeAdText(body, 0);
|
|
35016
|
+
return { brand: clampField(brandRaw, 30), line: clampField(dedupeBrand(brandRaw, bodyRaw), 60) };
|
|
35017
|
+
}
|
|
35018
|
+
function isSafeUrl(raw, allowLoopbackHttp = false) {
|
|
35019
|
+
if (typeof raw !== "string" || !raw) return false;
|
|
35020
|
+
if (/[\x00-\x20\x7f-\x9f]/.test(raw)) return false;
|
|
35021
|
+
try {
|
|
35022
|
+
const u = new URL(raw);
|
|
35023
|
+
if (u.username || u.password) return false;
|
|
35024
|
+
if (u.protocol === "https:") return true;
|
|
35025
|
+
return allowLoopbackHttp && u.protocol === "http:" && (u.hostname === "127.0.0.1" || u.hostname === "localhost");
|
|
35026
|
+
} catch {
|
|
35027
|
+
return false;
|
|
35028
|
+
}
|
|
35029
|
+
}
|
|
35030
|
+
function displayUrl(url) {
|
|
35031
|
+
return url.startsWith("https://") ? url.slice("https://".length).replace(/\/$/, "") : "";
|
|
35032
|
+
}
|
|
35033
|
+
function clickLink(server, ad, wallet, ctaUrl) {
|
|
35034
|
+
const base = server.replace(/\/+$/, "");
|
|
35035
|
+
if (!ad.click_token || !isSafeUrl(base, true)) return ctaUrl;
|
|
35036
|
+
return `${base}/ad/click?ad=${encodeURIComponent(ad.ad_id)}&w=${encodeURIComponent(wallet)}&t=${encodeURIComponent(ad.click_token)}`;
|
|
35037
|
+
}
|
|
35038
|
+
function linkShape(env3 = process.env, platform2 = process.platform) {
|
|
35039
|
+
if (env3.LATENTCODE_LINKS === "osc8" || env3.LATENTCODE_LINKS === "plain" || env3.LATENTCODE_LINKS === "hybrid") {
|
|
35040
|
+
return env3.LATENTCODE_LINKS;
|
|
35041
|
+
}
|
|
35042
|
+
if (env3.TMUX) return "plain";
|
|
35043
|
+
if (env3.SSH_TTY || env3.SSH_CONNECTION) return "hybrid";
|
|
35044
|
+
if (env3.KITTY_WINDOW_ID || env3.WEZTERM_PANE || env3.ITERM_SESSION_ID || env3.GHOSTTY_RESOURCES_DIR) return "osc8";
|
|
35045
|
+
if (env3.ALACRITTY_SOCKET || env3.ALACRITTY_WINDOW_ID) return "plain";
|
|
35046
|
+
const term = env3.TERM_PROGRAM || "";
|
|
35047
|
+
if (term === "vscode" || term === "iTerm.app" || term === "WezTerm" || term === "ghostty") return "osc8";
|
|
35048
|
+
if (term === "Apple_Terminal" || term === "WarpTerminal") return "plain";
|
|
35049
|
+
if (env3.WT_SESSION) return "osc8";
|
|
35050
|
+
return platform2 === "win32" ? "plain" : "hybrid";
|
|
35051
|
+
}
|
|
35052
|
+
function osc8(text, url) {
|
|
35053
|
+
if (!isSafeUrl(url, true)) return text;
|
|
35054
|
+
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
35055
|
+
}
|
|
35056
|
+
var BADGE_COLORS = ["#F87171", "#FB923C", "#FBBF24", "#A3E635", "#34D399", "#22D3EE", "#60A5FA", "#A78BFA", "#F472B6"];
|
|
35057
|
+
function adBadge(brand) {
|
|
35058
|
+
const letter = ([...brand].find((c) => /[\p{L}\p{N}]/u.test(c)) ?? "").toLocaleUpperCase();
|
|
35059
|
+
let h = 2166136261;
|
|
35060
|
+
for (const c of brand.toLowerCase()) h = Math.imul(h ^ c.codePointAt(0), 16777619);
|
|
35061
|
+
return { letter: letter || "\u2022", color: BADGE_COLORS[(h >>> 0) % BADGE_COLORS.length] };
|
|
35062
|
+
}
|
|
35063
|
+
|
|
34503
35064
|
// src/ads/classify.ts
|
|
34504
|
-
import { existsSync as
|
|
34505
|
-
import { join as
|
|
35065
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
35066
|
+
import { join as join6 } from "node:path";
|
|
34506
35067
|
var KEYWORDS = {
|
|
34507
35068
|
"frontend-ui": [
|
|
34508
35069
|
"react",
|
|
@@ -34655,10 +35216,10 @@ var MANIFESTS = [
|
|
|
34655
35216
|
function readManifestText(cwd2) {
|
|
34656
35217
|
const parts = [];
|
|
34657
35218
|
for (const name of MANIFESTS) {
|
|
34658
|
-
const p =
|
|
34659
|
-
if (!
|
|
35219
|
+
const p = join6(cwd2, name);
|
|
35220
|
+
if (!existsSync5(p)) continue;
|
|
34660
35221
|
try {
|
|
34661
|
-
parts.push(
|
|
35222
|
+
parts.push(readFileSync7(p, "utf8"));
|
|
34662
35223
|
} catch {
|
|
34663
35224
|
}
|
|
34664
35225
|
}
|
|
@@ -34695,43 +35256,29 @@ function classifyPrompt(prompt, cwd2 = process.cwd()) {
|
|
|
34695
35256
|
return best;
|
|
34696
35257
|
}
|
|
34697
35258
|
|
|
34698
|
-
// src/ads/sanitize.ts
|
|
34699
|
-
var ESC_SEQ = /\x1b\][\s\S]*?(?:\x07|\x1b\\|$)|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[ -/]*[0-~]|\x1b[@-_]/g;
|
|
34700
|
-
var CONTROL = /[\x00-\x1f\x7f-\x9f]/g;
|
|
34701
|
-
var BIDI = /[--]/g;
|
|
34702
|
-
function sanitizeAdText(input, max = 140) {
|
|
34703
|
-
let s2 = String(input ?? "");
|
|
34704
|
-
s2 = s2.replace(ESC_SEQ, "").replace(CONTROL, " ").replace(BIDI, "");
|
|
34705
|
-
s2 = s2.replace(/\s+/g, " ").trim();
|
|
34706
|
-
if (max > 0 && s2.length > max) s2 = `${s2.slice(0, Math.max(0, max - 1)).trimEnd()}\u2026`;
|
|
34707
|
-
return s2;
|
|
34708
|
-
}
|
|
34709
|
-
var AD_LIMITS = { title: 30, body: 140, cta_text: 24 };
|
|
34710
|
-
|
|
34711
35259
|
// src/ads/controller.ts
|
|
34712
|
-
var MIN_VISIBLE_MS =
|
|
34713
|
-
var ROTATE_MS =
|
|
35260
|
+
var MIN_VISIBLE_MS = 1e4;
|
|
35261
|
+
var ROTATE_MS = 1e4;
|
|
35262
|
+
var HOLD_MS = 27e4;
|
|
35263
|
+
var ACTIVE_MS = 6e4;
|
|
34714
35264
|
function safeUrl(raw) {
|
|
34715
|
-
|
|
34716
|
-
if (/[\x00-\x1f\x7f-\x9f\s]/.test(raw)) return "";
|
|
34717
|
-
try {
|
|
34718
|
-
const u = new URL(raw);
|
|
34719
|
-
return u.protocol === "https:" ? u.toString() : "";
|
|
34720
|
-
} catch {
|
|
34721
|
-
return "";
|
|
34722
|
-
}
|
|
35265
|
+
return raw && isSafeUrl(raw) ? new URL(raw).toString() : "";
|
|
34723
35266
|
}
|
|
34724
|
-
function toDisplayAd(ad) {
|
|
34725
|
-
const
|
|
34726
|
-
|
|
34727
|
-
|
|
35267
|
+
function toDisplayAd(ad, opts = {}) {
|
|
35268
|
+
const { brand, line } = composeAdCopy(ad.title, ad.body);
|
|
35269
|
+
if (!brand && !line) return null;
|
|
35270
|
+
const url = safeUrl(ad.cta_url);
|
|
34728
35271
|
return {
|
|
34729
35272
|
ad,
|
|
34730
|
-
title,
|
|
34731
|
-
body,
|
|
35273
|
+
title: brand,
|
|
35274
|
+
body: line,
|
|
34732
35275
|
ctaText: sanitizeAdText(ad.cta_text, AD_LIMITS.cta_text) || "Learn more",
|
|
34733
|
-
url
|
|
34734
|
-
|
|
35276
|
+
url,
|
|
35277
|
+
link: url && opts.server && opts.wallet ? clickLink(opts.server, ad, opts.wallet, url) : url,
|
|
35278
|
+
shownUrl: displayUrl(url),
|
|
35279
|
+
earn: typeof ad.earn_amount === "number" && Number.isFinite(ad.earn_amount) ? ad.earn_amount : 0,
|
|
35280
|
+
eventUuid: randomUUID(),
|
|
35281
|
+
fetchedAt: opts.now ?? Date.now()
|
|
34735
35282
|
};
|
|
34736
35283
|
}
|
|
34737
35284
|
var AdController = class {
|
|
@@ -34741,12 +35288,17 @@ var AdController = class {
|
|
|
34741
35288
|
shownAt = 0;
|
|
34742
35289
|
visibleMs = 0;
|
|
34743
35290
|
billed = false;
|
|
35291
|
+
verdict = null;
|
|
34744
35292
|
lastTick = 0;
|
|
34745
35293
|
fetching = false;
|
|
35294
|
+
/** Generation of the request in flight; a stale one never blocks a new turn. */
|
|
35295
|
+
fetchingGen = -1;
|
|
34746
35296
|
generation = 0;
|
|
34747
35297
|
context = "general";
|
|
34748
35298
|
impressions = 0;
|
|
34749
35299
|
sessionEarned = 0;
|
|
35300
|
+
adIndex = 0;
|
|
35301
|
+
lastActivity = 0;
|
|
34750
35302
|
listeners = /* @__PURE__ */ new Set();
|
|
34751
35303
|
/** Cached for useSyncExternalStore — must be referentially stable between emits. */
|
|
34752
35304
|
snap = null;
|
|
@@ -34757,6 +35309,8 @@ var AdController = class {
|
|
|
34757
35309
|
now: opts.now ?? Date.now,
|
|
34758
35310
|
minVisibleMs: opts.minVisibleMs ?? MIN_VISIBLE_MS,
|
|
34759
35311
|
rotateMs: opts.rotateMs ?? ROTATE_MS,
|
|
35312
|
+
holdMs: opts.holdMs ?? HOLD_MS,
|
|
35313
|
+
activeMs: opts.activeMs ?? ACTIVE_MS,
|
|
34760
35314
|
classify: opts.classify ?? ((p, cwd2) => classifyPrompt(p, cwd2))
|
|
34761
35315
|
};
|
|
34762
35316
|
opts.focus.onChange(() => this.emit());
|
|
@@ -34787,85 +35341,125 @@ var AdController = class {
|
|
|
34787
35341
|
if (this.snap) return this.snap;
|
|
34788
35342
|
return this.snap = {
|
|
34789
35343
|
status: this.status,
|
|
34790
|
-
current: this.
|
|
35344
|
+
current: this.current,
|
|
35345
|
+
adIndex: this.adIndex,
|
|
35346
|
+
idle: !this.working,
|
|
34791
35347
|
visibleMs: this.visibleMs,
|
|
34792
35348
|
billed: this.billed,
|
|
35349
|
+
verdict: this.verdict,
|
|
34793
35350
|
focusTracked: this.o.focus.known,
|
|
34794
35351
|
impressions: this.impressions,
|
|
34795
35352
|
sessionEarned: this.sessionEarned,
|
|
34796
35353
|
context: this.context
|
|
34797
35354
|
};
|
|
34798
35355
|
}
|
|
35356
|
+
/** The user typed or pasted: idle dwell may count for the next ACTIVE_MS. */
|
|
35357
|
+
noteActivity() {
|
|
35358
|
+
this.lastActivity = this.o.now();
|
|
35359
|
+
}
|
|
34799
35360
|
/** Called on execution start/end. `prompt` is classified locally, never sent. */
|
|
34800
35361
|
setWorking(working, prompt = "") {
|
|
34801
35362
|
if (working === this.working) return;
|
|
34802
35363
|
this.working = working;
|
|
34803
35364
|
this.lastTick = this.o.now();
|
|
35365
|
+
this.lastActivity = this.lastTick;
|
|
34804
35366
|
if (working) {
|
|
34805
35367
|
this.context = this.o.classify(prompt, this.o.cwd);
|
|
34806
|
-
|
|
34807
|
-
|
|
35368
|
+
if (this.current && !this.billed && !this.holding()) this.clear();
|
|
35369
|
+
if (!this.holding()) void this.fetchNext();
|
|
35370
|
+
} else if (!this.current) {
|
|
34808
35371
|
this.clear();
|
|
35372
|
+
} else {
|
|
35373
|
+
this.generation += 1;
|
|
34809
35374
|
}
|
|
34810
35375
|
this.emit();
|
|
34811
35376
|
}
|
|
35377
|
+
attentive(now) {
|
|
35378
|
+
return this.o.focus.focused && (this.working || now - this.lastActivity < this.o.activeMs);
|
|
35379
|
+
}
|
|
35380
|
+
/** An un-billed ad that may still be shown and billed. */
|
|
35381
|
+
holding() {
|
|
35382
|
+
return !!this.current && !this.billed && this.o.now() - this.current.fetchedAt < this.o.holdMs;
|
|
35383
|
+
}
|
|
34812
35384
|
/** Advance the attention clock. Call every ~250ms. */
|
|
34813
35385
|
tick() {
|
|
34814
35386
|
const now = this.o.now();
|
|
34815
35387
|
const dt = Math.max(0, now - this.lastTick);
|
|
34816
35388
|
this.lastTick = now;
|
|
34817
|
-
if (!this.
|
|
34818
|
-
if (this.
|
|
35389
|
+
if (!this.current) return;
|
|
35390
|
+
if (!this.billed && !this.holding()) {
|
|
35391
|
+
this.clear();
|
|
35392
|
+
if (this.working) void this.fetchNext();
|
|
35393
|
+
this.emit();
|
|
35394
|
+
return;
|
|
35395
|
+
}
|
|
35396
|
+
if (!this.working && this.billed && now - this.current.fetchedAt >= this.o.holdMs) {
|
|
35397
|
+
this.clear();
|
|
35398
|
+
this.emit();
|
|
35399
|
+
return;
|
|
35400
|
+
}
|
|
35401
|
+
if (!this.billed && this.attentive(now)) {
|
|
35402
|
+
this.visibleMs += dt;
|
|
35403
|
+
this.emit();
|
|
35404
|
+
}
|
|
34819
35405
|
if (!this.billed && this.visibleMs >= this.o.minVisibleMs) {
|
|
34820
35406
|
this.billed = true;
|
|
34821
|
-
this.
|
|
34822
|
-
this.sessionEarned += this.current.earn;
|
|
35407
|
+
const shown = this.current;
|
|
34823
35408
|
void this.o.api.impression({
|
|
34824
|
-
ad:
|
|
35409
|
+
ad: shown.ad,
|
|
34825
35410
|
wallet: this.o.wallet,
|
|
34826
35411
|
context: this.context,
|
|
34827
35412
|
displayedMs: this.visibleMs,
|
|
34828
|
-
focusTracked: this.o.focus.known
|
|
35413
|
+
focusTracked: this.o.focus.known,
|
|
35414
|
+
eventUuid: shown.eventUuid
|
|
35415
|
+
}).catch(() => "error").then((result) => {
|
|
35416
|
+
if (this.current === shown) this.verdict = result;
|
|
35417
|
+
if (result === "tracked") {
|
|
35418
|
+
this.impressions += 1;
|
|
35419
|
+
this.sessionEarned += shown.earn;
|
|
35420
|
+
}
|
|
35421
|
+
this.emit();
|
|
34829
35422
|
});
|
|
34830
35423
|
this.emit();
|
|
34831
35424
|
}
|
|
34832
|
-
if (this.billed && now - this.shownAt >= this.o.rotateMs && !this.fetching) {
|
|
35425
|
+
if (this.working && this.billed && now - this.shownAt >= this.o.rotateMs && !this.fetching) {
|
|
34833
35426
|
void this.fetchNext();
|
|
34834
35427
|
}
|
|
34835
35428
|
}
|
|
34836
|
-
/** User
|
|
35429
|
+
/** User asked to open the ad (keyboard): the tracked link, or null. The server counts the click on redirect. */
|
|
34837
35430
|
click() {
|
|
34838
|
-
|
|
34839
|
-
if (!ad || !ad.url) return null;
|
|
34840
|
-
void this.o.api.click({ ad: ad.ad, wallet: this.o.wallet, context: this.context });
|
|
34841
|
-
return ad.url;
|
|
35431
|
+
return this.current?.link || null;
|
|
34842
35432
|
}
|
|
34843
35433
|
clear() {
|
|
34844
35434
|
this.generation += 1;
|
|
34845
35435
|
this.current = null;
|
|
34846
35436
|
this.visibleMs = 0;
|
|
34847
35437
|
this.billed = false;
|
|
35438
|
+
this.verdict = null;
|
|
34848
35439
|
}
|
|
34849
35440
|
async fetchNext() {
|
|
34850
|
-
if (this.status !== "ok" || this.fetching) return;
|
|
34851
|
-
this.fetching = true;
|
|
34852
35441
|
const gen = this.generation;
|
|
35442
|
+
if (this.status !== "ok" || this.fetching && this.fetchingGen === gen) return;
|
|
35443
|
+
this.fetching = true;
|
|
35444
|
+
this.fetchingGen = gen;
|
|
34853
35445
|
try {
|
|
34854
35446
|
const ad = await this.o.api.request({ wallet: this.o.wallet, context: this.context, sessionId: this.o.sessionId });
|
|
34855
35447
|
if (gen !== this.generation || !this.working || this.status !== "ok") return;
|
|
34856
|
-
const display = ad ? toDisplayAd(ad) : null;
|
|
35448
|
+
const display = ad ? toDisplayAd(ad, { server: this.o.api.server, wallet: this.o.wallet, now: this.o.now() }) : null;
|
|
34857
35449
|
if (!display) {
|
|
34858
35450
|
if (this.current) this.shownAt = this.o.now();
|
|
34859
35451
|
return;
|
|
34860
35452
|
}
|
|
34861
35453
|
this.current = display;
|
|
35454
|
+
this.adIndex += 1;
|
|
34862
35455
|
this.shownAt = this.o.now();
|
|
34863
35456
|
this.lastTick = this.shownAt;
|
|
34864
35457
|
this.visibleMs = 0;
|
|
34865
35458
|
this.billed = false;
|
|
35459
|
+
this.verdict = null;
|
|
34866
35460
|
this.emit();
|
|
34867
35461
|
} finally {
|
|
34868
|
-
this.fetching = false;
|
|
35462
|
+
if (this.fetchingGen === gen) this.fetching = false;
|
|
34869
35463
|
}
|
|
34870
35464
|
}
|
|
34871
35465
|
emit() {
|
|
@@ -34874,23 +35468,20 @@ var AdController = class {
|
|
|
34874
35468
|
}
|
|
34875
35469
|
};
|
|
34876
35470
|
|
|
34877
|
-
// src/ads/api.ts
|
|
34878
|
-
import { randomUUID } from "node:crypto";
|
|
34879
|
-
|
|
34880
35471
|
// src/ads/killswitch.ts
|
|
34881
|
-
import { existsSync as
|
|
34882
|
-
import { join as
|
|
35472
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
35473
|
+
import { join as join7 } from "node:path";
|
|
34883
35474
|
var KILL_TTL_MS = 5 * 6e4;
|
|
34884
35475
|
var KILL_STALE_GRACE_MS = 60 * 6e4;
|
|
34885
35476
|
var KILL_SOFT_GRACE_MS = 10 * 6e4;
|
|
34886
35477
|
var GUARD_TRIP_AFTER = 5;
|
|
34887
35478
|
var GUARD_COOLDOWN_MS = 10 * 6e4;
|
|
34888
35479
|
function healthFile() {
|
|
34889
|
-
return
|
|
35480
|
+
return join7(configDir(), "latentcode-health.json");
|
|
34890
35481
|
}
|
|
34891
35482
|
function load() {
|
|
34892
35483
|
try {
|
|
34893
|
-
const s2 = JSON.parse(
|
|
35484
|
+
const s2 = JSON.parse(readFileSync8(healthFile(), "utf8"));
|
|
34894
35485
|
return s2.server === resolveServer() ? s2 : {};
|
|
34895
35486
|
} catch {
|
|
34896
35487
|
return {};
|
|
@@ -34898,8 +35489,8 @@ function load() {
|
|
|
34898
35489
|
}
|
|
34899
35490
|
function save(s2) {
|
|
34900
35491
|
try {
|
|
34901
|
-
|
|
34902
|
-
|
|
35492
|
+
mkdirSync4(configDir(), { recursive: true });
|
|
35493
|
+
writeFileSync5(healthFile(), JSON.stringify({ ...s2, server: resolveServer() }));
|
|
34903
35494
|
} catch {
|
|
34904
35495
|
}
|
|
34905
35496
|
}
|
|
@@ -34957,8 +35548,11 @@ function recordServerResult(ok, now = Date.now()) {
|
|
|
34957
35548
|
|
|
34958
35549
|
// src/ads/api.ts
|
|
34959
35550
|
var SURFACE_WORKING_BAR = "status_line";
|
|
34960
|
-
function httpAdApi(server = resolveServer()) {
|
|
35551
|
+
function httpAdApi(server = resolveServer(), identity = {}) {
|
|
35552
|
+
const agent = identity.agent ?? AGENT_LATENTCODE;
|
|
35553
|
+
const surface = identity.surface ?? SURFACE_WORKING_BAR;
|
|
34961
35554
|
return {
|
|
35555
|
+
server,
|
|
34962
35556
|
async request({ wallet, context, sessionId }) {
|
|
34963
35557
|
void refreshKillswitch(server);
|
|
34964
35558
|
if (!shouldServe().ok) return null;
|
|
@@ -34969,9 +35563,9 @@ function httpAdApi(server = resolveServer()) {
|
|
|
34969
35563
|
headers: { "Content-Type": "application/json" },
|
|
34970
35564
|
body: JSON.stringify({
|
|
34971
35565
|
user_wallet: wallet,
|
|
34972
|
-
agent
|
|
35566
|
+
agent,
|
|
34973
35567
|
context: context.slice(0, 100),
|
|
34974
|
-
surface
|
|
35568
|
+
surface,
|
|
34975
35569
|
tags: context ? [context] : [],
|
|
34976
35570
|
session_id: sessionId,
|
|
34977
35571
|
device_id: device
|
|
@@ -34987,8 +35581,8 @@ function httpAdApi(server = resolveServer()) {
|
|
|
34987
35581
|
return null;
|
|
34988
35582
|
}
|
|
34989
35583
|
},
|
|
34990
|
-
async impression({ ad, wallet, context, displayedMs, focusTracked }) {
|
|
34991
|
-
if (!shouldServe().ok) return;
|
|
35584
|
+
async impression({ ad, wallet, context, displayedMs, focusTracked, eventUuid }) {
|
|
35585
|
+
if (!shouldServe().ok) return "error";
|
|
34992
35586
|
const device = await ensureDeviceCredential(server);
|
|
34993
35587
|
try {
|
|
34994
35588
|
const res = await fetch(`${server}/ad/impression`, {
|
|
@@ -34998,11 +35592,11 @@ function httpAdApi(server = resolveServer()) {
|
|
|
34998
35592
|
ad_id: ad.ad_id,
|
|
34999
35593
|
user_wallet: wallet,
|
|
35000
35594
|
token: ad.impression_token ?? "",
|
|
35001
|
-
agent
|
|
35002
|
-
surface
|
|
35595
|
+
agent,
|
|
35596
|
+
surface,
|
|
35003
35597
|
context,
|
|
35004
35598
|
device_id: device,
|
|
35005
|
-
event_uuid:
|
|
35599
|
+
event_uuid: eventUuid,
|
|
35006
35600
|
displayed_ms: Math.round(displayedMs),
|
|
35007
35601
|
// Attention signal: the dwell above was measured with real terminal
|
|
35008
35602
|
// focus events, not assumed. Servers that don't know it ignore it.
|
|
@@ -35011,34 +35605,45 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35011
35605
|
signal: AbortSignal.timeout(2e3)
|
|
35012
35606
|
});
|
|
35013
35607
|
recordServerResult(res.status < 500);
|
|
35608
|
+
if (!res.ok) return "error";
|
|
35609
|
+
const status2 = (await res.json().catch(() => ({}))).status;
|
|
35610
|
+
return status2 === "tracked" || status2 === "skipped" || status2 === "unearned" ? status2 : "error";
|
|
35014
35611
|
} catch {
|
|
35015
35612
|
recordServerResult(false);
|
|
35613
|
+
return "error";
|
|
35016
35614
|
}
|
|
35017
35615
|
},
|
|
35018
|
-
async
|
|
35019
|
-
const device = await ensureDeviceCredential(server);
|
|
35616
|
+
async creditQuote() {
|
|
35020
35617
|
try {
|
|
35021
|
-
await fetch(`${server}/
|
|
35022
|
-
|
|
35023
|
-
|
|
35024
|
-
|
|
35025
|
-
|
|
35026
|
-
|
|
35027
|
-
|
|
35028
|
-
|
|
35029
|
-
context,
|
|
35030
|
-
device_id: device
|
|
35031
|
-
}),
|
|
35032
|
-
signal: AbortSignal.timeout(2e3)
|
|
35033
|
-
});
|
|
35618
|
+
const res = await fetch(`${server}/credit/quote`, { signal: AbortSignal.timeout(4e3) });
|
|
35619
|
+
if (!res.ok) return null;
|
|
35620
|
+
const q = await res.json();
|
|
35621
|
+
return {
|
|
35622
|
+
bonus: Number(q.bonus ?? 1),
|
|
35623
|
+
buybackPrice: Number(q.sell_price ?? q.buyback_price ?? 0),
|
|
35624
|
+
buybackEnabled: Boolean(q.buyback_enabled)
|
|
35625
|
+
};
|
|
35034
35626
|
} catch {
|
|
35627
|
+
return null;
|
|
35035
35628
|
}
|
|
35036
35629
|
},
|
|
35037
35630
|
async balance(wallet) {
|
|
35038
35631
|
try {
|
|
35039
35632
|
const res = await fetch(`${server}/earnings/${wallet}`, { signal: AbortSignal.timeout(4e3) });
|
|
35040
35633
|
if (!res.ok) return null;
|
|
35041
|
-
|
|
35634
|
+
const e = await res.json();
|
|
35635
|
+
return Number(e.credits ?? e.balance ?? 0);
|
|
35636
|
+
} catch {
|
|
35637
|
+
return null;
|
|
35638
|
+
}
|
|
35639
|
+
},
|
|
35640
|
+
async creditSummary(wallet) {
|
|
35641
|
+
try {
|
|
35642
|
+
const res = await fetch(`${server}/credit/${wallet}/summary`, { signal: AbortSignal.timeout(4e3) });
|
|
35643
|
+
if (!res.ok) return null;
|
|
35644
|
+
const c = await res.json();
|
|
35645
|
+
const mode = c.mode === "auto_sell" || c.mode === "auto_list" ? c.mode : "keep";
|
|
35646
|
+
return { credits: Number(c.credits ?? 0), mode, bonus: Number(c.bonus ?? 1), sellPrice: Number(c.sell_price ?? 0) };
|
|
35042
35647
|
} catch {
|
|
35043
35648
|
return null;
|
|
35044
35649
|
}
|
|
@@ -35046,6 +35651,84 @@ function httpAdApi(server = resolveServer()) {
|
|
|
35046
35651
|
};
|
|
35047
35652
|
}
|
|
35048
35653
|
|
|
35654
|
+
// src/engine/latentProvider.ts
|
|
35655
|
+
var LATENT_PROVIDER_ID = "latent";
|
|
35656
|
+
var LATENT_NAME = "Latent";
|
|
35657
|
+
var LATENT_VENICE_NAME = "Latent \xB7 via Venice";
|
|
35658
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : void 0;
|
|
35659
|
+
function parseLatentModels(body) {
|
|
35660
|
+
const data = body?.data;
|
|
35661
|
+
if (!Array.isArray(data)) throw new Error("The /models answer has no model list.");
|
|
35662
|
+
const details = {};
|
|
35663
|
+
let venice = false;
|
|
35664
|
+
const ids = [];
|
|
35665
|
+
for (const m of data) {
|
|
35666
|
+
if (typeof m === "string") {
|
|
35667
|
+
ids.push(m);
|
|
35668
|
+
continue;
|
|
35669
|
+
}
|
|
35670
|
+
if (!m || typeof m !== "object" || typeof m.id !== "string") continue;
|
|
35671
|
+
const e = m;
|
|
35672
|
+
const id = e.id;
|
|
35673
|
+
ids.push(id);
|
|
35674
|
+
if (e.provider === "venice") venice = true;
|
|
35675
|
+
const pr = e.pricing ?? {};
|
|
35676
|
+
const d = {};
|
|
35677
|
+
if (typeof e.name === "string" && e.name) d.name = e.name;
|
|
35678
|
+
const ctx = num(e.context_length);
|
|
35679
|
+
if (ctx) d.context = ctx;
|
|
35680
|
+
const out = num(e.max_output_tokens);
|
|
35681
|
+
if (out) d.output = out;
|
|
35682
|
+
if (num(pr.input) !== void 0 && num(pr.output) !== void 0) {
|
|
35683
|
+
d.cost = { input: num(pr.input), output: num(pr.output), ...num(pr.cache_input) !== void 0 ? { cacheRead: num(pr.cache_input) } : {} };
|
|
35684
|
+
}
|
|
35685
|
+
if (Object.keys(d).length) details[id] = d;
|
|
35686
|
+
}
|
|
35687
|
+
return { models: parseModelList(ids.join(" ")), details, venice };
|
|
35688
|
+
}
|
|
35689
|
+
async function discoverLatentModels(baseURL, key, timeoutMs = 1e4) {
|
|
35690
|
+
const res = await fetch(baseURL + "/models", { headers: { authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(timeoutMs) });
|
|
35691
|
+
if (!res.ok) throw new Error(`${baseURL}/models answered ${res.status}`);
|
|
35692
|
+
return parseLatentModels(await res.json());
|
|
35693
|
+
}
|
|
35694
|
+
var LATENT_KEY_RE = /^lk_[A-Za-z0-9_-]{20,}$/;
|
|
35695
|
+
function latentBaseURL(server) {
|
|
35696
|
+
return server.replace(/\/+$/, "") + "/v1";
|
|
35697
|
+
}
|
|
35698
|
+
async function connectLatentKey(engine, server, key, discover = discoverLatentModels, suggested) {
|
|
35699
|
+
const k = key.trim();
|
|
35700
|
+
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.");
|
|
35701
|
+
const baseURL = latentBaseURL(server);
|
|
35702
|
+
let found;
|
|
35703
|
+
try {
|
|
35704
|
+
found = await discover(baseURL, k);
|
|
35705
|
+
} catch (e) {
|
|
35706
|
+
const why = e instanceof Error ? e.message : String(e);
|
|
35707
|
+
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}).`);
|
|
35708
|
+
}
|
|
35709
|
+
const models = found.models;
|
|
35710
|
+
if (!models.length) throw new Error("Latent lists no models right now. Try again in a minute.");
|
|
35711
|
+
const file = configFileIn(await engine.configDir() ?? defaultConfigDir());
|
|
35712
|
+
const pick = suggested && models.includes(suggested) ? suggested : void 0;
|
|
35713
|
+
const defaultModel = pick ? `${LATENT_PROVIDER_ID}/${pick}` : void 0;
|
|
35714
|
+
const name = found.venice ? LATENT_VENICE_NAME : LATENT_NAME;
|
|
35715
|
+
const written = writeProviderConfig(file, LATENT_PROVIDER_ID, { name, kind: "openai", baseURL, models, details: found.details }, defaultModel);
|
|
35716
|
+
await engine.reloadConfig();
|
|
35717
|
+
await engine.waitForIntegration(LATENT_PROVIDER_ID);
|
|
35718
|
+
await engine.connectKey(LATENT_PROVIDER_ID, k);
|
|
35719
|
+
return { id: LATENT_PROVIDER_ID, models, file: written.file, backup: written.backup, defaultModel };
|
|
35720
|
+
}
|
|
35721
|
+
async function connectPendingLatentKey(engine, server, store, discover = discoverLatentModels) {
|
|
35722
|
+
const cfg = store.load();
|
|
35723
|
+
if (!cfg.latent_key) return null;
|
|
35724
|
+
const res = await connectLatentKey(engine, server, cfg.latent_key, discover, cfg.latent_default_model);
|
|
35725
|
+
store.save({ latent_key: void 0, latent_default_model: void 0, sync_key: cfg.latent_key });
|
|
35726
|
+
return res;
|
|
35727
|
+
}
|
|
35728
|
+
function credits(balanceUsd, bonus) {
|
|
35729
|
+
return balanceUsd * (bonus > 0 ? bonus : 1);
|
|
35730
|
+
}
|
|
35731
|
+
|
|
35049
35732
|
// src/ui/theme.ts
|
|
35050
35733
|
var C = {
|
|
35051
35734
|
accent: "#A78BFA",
|
|
@@ -35109,10 +35792,131 @@ function fmtUsd(n) {
|
|
|
35109
35792
|
return `$${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 2)}`;
|
|
35110
35793
|
}
|
|
35111
35794
|
|
|
35795
|
+
// src/account/sync.ts
|
|
35796
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
35797
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync6, mkdirSync as mkdirSync5 } from "node:fs";
|
|
35798
|
+
import { join as join8 } from "node:path";
|
|
35799
|
+
var clip2 = (s2, n = 64) => s2.length > n ? s2.slice(0, n) : s2;
|
|
35800
|
+
function buildSyncState(opts) {
|
|
35801
|
+
const count = /* @__PURE__ */ new Map();
|
|
35802
|
+
for (const m of opts.catalog.models) count.set(m.providerID, (count.get(m.providerID) ?? 0) + 1);
|
|
35803
|
+
return {
|
|
35804
|
+
app_version: clip2(opts.appVersion),
|
|
35805
|
+
engine_version: clip2(opts.engineVersion),
|
|
35806
|
+
default_model: clip2(opts.model, 128),
|
|
35807
|
+
providers: opts.catalog.providers.slice(0, 100).map((p) => ({
|
|
35808
|
+
id: clip2(p.id),
|
|
35809
|
+
name: clip2(p.name),
|
|
35810
|
+
kind: clip2(p.kind),
|
|
35811
|
+
models: count.get(p.id) ?? 0
|
|
35812
|
+
})),
|
|
35813
|
+
mcp: opts.mcp.slice(0, 100).map((s2) => ({
|
|
35814
|
+
name: clip2(s2.name),
|
|
35815
|
+
// The engine gives remote servers a sign-in integration; local ones have none.
|
|
35816
|
+
type: s2.integrationID ? "remote" : "local",
|
|
35817
|
+
status: clip2(String(s2.status))
|
|
35818
|
+
}))
|
|
35819
|
+
};
|
|
35820
|
+
}
|
|
35821
|
+
function syncHash(s2, salt = "") {
|
|
35822
|
+
const norm = {
|
|
35823
|
+
...s2,
|
|
35824
|
+
providers: [...s2.providers].sort((a2, b) => a2.id.localeCompare(b.id)),
|
|
35825
|
+
mcp: [...s2.mcp].sort((a2, b) => a2.name.localeCompare(b.name))
|
|
35826
|
+
};
|
|
35827
|
+
return createHash2("sha256").update(salt + "\n" + JSON.stringify(norm)).digest("hex").slice(0, 32);
|
|
35828
|
+
}
|
|
35829
|
+
function fileHashStore(file = join8(configDir(), "latentcode-sync.json")) {
|
|
35830
|
+
return {
|
|
35831
|
+
get() {
|
|
35832
|
+
try {
|
|
35833
|
+
return JSON.parse(readFileSync9(file, "utf8")).hash ?? null;
|
|
35834
|
+
} catch {
|
|
35835
|
+
return null;
|
|
35836
|
+
}
|
|
35837
|
+
},
|
|
35838
|
+
set(hash) {
|
|
35839
|
+
try {
|
|
35840
|
+
mkdirSync5(join8(file, ".."), { recursive: true });
|
|
35841
|
+
writeFileSync6(file, JSON.stringify({ hash, at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
|
|
35842
|
+
} catch {
|
|
35843
|
+
}
|
|
35844
|
+
}
|
|
35845
|
+
};
|
|
35846
|
+
}
|
|
35847
|
+
var StateSync = class {
|
|
35848
|
+
constructor(d) {
|
|
35849
|
+
this.d = d;
|
|
35850
|
+
}
|
|
35851
|
+
d;
|
|
35852
|
+
timer = null;
|
|
35853
|
+
running = null;
|
|
35854
|
+
again = false;
|
|
35855
|
+
stopped = false;
|
|
35856
|
+
/** Something may have changed: send (debounced) if it did. */
|
|
35857
|
+
kick(delayMs = this.d.debounceMs ?? 5e3) {
|
|
35858
|
+
if (this.stopped) return;
|
|
35859
|
+
if (this.timer) clearTimeout(this.timer);
|
|
35860
|
+
this.timer = setTimeout(() => {
|
|
35861
|
+
this.timer = null;
|
|
35862
|
+
void this.flush();
|
|
35863
|
+
}, delayMs);
|
|
35864
|
+
this.timer.unref?.();
|
|
35865
|
+
}
|
|
35866
|
+
/** Send now if the state differs from what the server last got. Never throws. */
|
|
35867
|
+
async flush() {
|
|
35868
|
+
if (this.running) {
|
|
35869
|
+
this.again = true;
|
|
35870
|
+
await this.running;
|
|
35871
|
+
return "skipped";
|
|
35872
|
+
}
|
|
35873
|
+
let result = "skipped";
|
|
35874
|
+
this.running = (async () => {
|
|
35875
|
+
result = await this.once();
|
|
35876
|
+
})();
|
|
35877
|
+
try {
|
|
35878
|
+
await this.running;
|
|
35879
|
+
} finally {
|
|
35880
|
+
this.running = null;
|
|
35881
|
+
}
|
|
35882
|
+
if (this.again) {
|
|
35883
|
+
this.again = false;
|
|
35884
|
+
return this.flush();
|
|
35885
|
+
}
|
|
35886
|
+
return result;
|
|
35887
|
+
}
|
|
35888
|
+
stop() {
|
|
35889
|
+
this.stopped = true;
|
|
35890
|
+
if (this.timer) clearTimeout(this.timer);
|
|
35891
|
+
}
|
|
35892
|
+
async once() {
|
|
35893
|
+
const key = this.d.key();
|
|
35894
|
+
if (!key || !this.d.enabled()) return "skipped";
|
|
35895
|
+
try {
|
|
35896
|
+
const state = await this.d.collect();
|
|
35897
|
+
const hash = syncHash(state, `${this.d.server}
|
|
35898
|
+
${createHash2("sha256").update(key).digest("hex").slice(0, 16)}`);
|
|
35899
|
+
if (this.d.lastHash?.get() === hash) return "same";
|
|
35900
|
+
const res = await (this.d.fetch ?? fetch)(`${this.d.server}/latentcode/state`, {
|
|
35901
|
+
method: "POST",
|
|
35902
|
+
headers: { authorization: `Bearer ${key}`, "content-type": "application/json" },
|
|
35903
|
+
body: JSON.stringify(state),
|
|
35904
|
+
signal: AbortSignal.timeout(5e3)
|
|
35905
|
+
});
|
|
35906
|
+
if (!res.ok) return "failed";
|
|
35907
|
+
this.d.lastHash?.set(hash);
|
|
35908
|
+
return "sent";
|
|
35909
|
+
} catch {
|
|
35910
|
+
return "failed";
|
|
35911
|
+
}
|
|
35912
|
+
}
|
|
35913
|
+
};
|
|
35914
|
+
|
|
35112
35915
|
// src/boot.ts
|
|
35113
35916
|
var BOOT_STEPS = [
|
|
35114
35917
|
{ id: "engine", label: "Engine", status: "pending", detail: "" },
|
|
35115
35918
|
{ id: "providers", label: "Providers", status: "pending", detail: "" },
|
|
35919
|
+
{ id: "mcp", label: "MCP", status: "pending", detail: "" },
|
|
35116
35920
|
{ id: "model", label: "Model", status: "pending", detail: "" },
|
|
35117
35921
|
{ id: "safety", label: "Safety", status: "pending", detail: "" },
|
|
35118
35922
|
{ id: "earn", label: "Earn", status: "pending", detail: "" }
|
|
@@ -35148,20 +35952,40 @@ async function boot(args, focus, report) {
|
|
|
35148
35952
|
return { value, detail: `opencode${bin.version ? " " + bin.version : ""} \xB7 ${where} \xB7 private, this session only` };
|
|
35149
35953
|
});
|
|
35150
35954
|
const models = new ModelStore();
|
|
35955
|
+
let latentStart;
|
|
35956
|
+
let latentNote = "";
|
|
35151
35957
|
const [catalog, commands] = await step("providers", async () => {
|
|
35958
|
+
try {
|
|
35959
|
+
const res = await connectPendingLatentKey(engine, resolveServer(), { load: loadConfig, save: (p) => void saveConfig(p) });
|
|
35960
|
+
if (res) {
|
|
35961
|
+
latentStart = res.defaultModel;
|
|
35962
|
+
latentNote = "Latent connected";
|
|
35963
|
+
}
|
|
35964
|
+
} catch (e) {
|
|
35965
|
+
latentNote = `Latent not connected yet (${firstLine(e)})`;
|
|
35966
|
+
}
|
|
35152
35967
|
const value = await Promise.all([engine.catalog(), engine.commands()]);
|
|
35153
35968
|
const c = value[0];
|
|
35154
35969
|
const verified = c.models.filter((m) => models.get(m.key)?.status === "ok").length;
|
|
35155
35970
|
return {
|
|
35156
35971
|
value,
|
|
35157
35972
|
status: c.models.length ? "ok" : "warn",
|
|
35158
|
-
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"
|
|
35973
|
+
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}` : "")
|
|
35974
|
+
};
|
|
35975
|
+
});
|
|
35976
|
+
await step("mcp", async () => {
|
|
35977
|
+
const list2 = await engine.mcpList().catch(() => []);
|
|
35978
|
+
const sum = mcpSummary(list2);
|
|
35979
|
+
return {
|
|
35980
|
+
value: null,
|
|
35981
|
+
status: "ok",
|
|
35982
|
+
detail: list2.length ? `${listNames(list2.map((s2) => s2.name))} \xB7 from your OpenCode config${sum.needsAuth ? ` \xB7 ${sum.needsAuth} need sign-in (/mcp)` : ""}` : "none \u2014 /mcp to add one (shared with OpenCode)"
|
|
35159
35983
|
};
|
|
35160
35984
|
});
|
|
35161
35985
|
const permissions = args.auto ? [] : SAFE_PERMISSIONS;
|
|
35162
35986
|
let startNotice;
|
|
35163
35987
|
const session = await step("model", async () => {
|
|
35164
|
-
let start = args.model;
|
|
35988
|
+
let start = args.model ?? (latentStart ? parseKey(latentStart) ?? void 0 : void 0);
|
|
35165
35989
|
if (!start) {
|
|
35166
35990
|
const def = await engine.defaultModel();
|
|
35167
35991
|
const defKey = def ? `${def.providerID}/${def.id}` : null;
|
|
@@ -35199,6 +36023,21 @@ async function boot(args, focus, report) {
|
|
|
35199
36023
|
const detail = !enabled ? "off \u2014 /ads on to earn while the agent works" : wallet ? `on \xB7 pays into ${shortWallet(wallet)}` : "no wallet yet \u2014 /login to start earning";
|
|
35200
36024
|
return { value: { wallet, server, api, controller }, status: enabled && wallet ? "ok" : "warn", detail };
|
|
35201
36025
|
});
|
|
36026
|
+
const engineVersion = resolveEngineBin()?.version ?? "";
|
|
36027
|
+
const sync = new StateSync({
|
|
36028
|
+
server: earn.server,
|
|
36029
|
+
key: () => loadConfig().sync_key,
|
|
36030
|
+
enabled: () => loadConfig().sync !== false,
|
|
36031
|
+
lastHash: fileHashStore(),
|
|
36032
|
+
collect: async () => buildSyncState({
|
|
36033
|
+
appVersion: true ? "0.1.0-alpha.10" : "",
|
|
36034
|
+
engineVersion,
|
|
36035
|
+
model: await engine.defaultModel().then((m) => m ? `${m.providerID}/${m.id}` : session.key),
|
|
36036
|
+
catalog: await engine.catalog(),
|
|
36037
|
+
mcp: await engine.mcpList().catch(() => [])
|
|
36038
|
+
})
|
|
36039
|
+
});
|
|
36040
|
+
sync.kick(15e3);
|
|
35202
36041
|
return {
|
|
35203
36042
|
engine,
|
|
35204
36043
|
permissions,
|
|
@@ -35210,6 +36049,7 @@ async function boot(args, focus, report) {
|
|
|
35210
36049
|
models,
|
|
35211
36050
|
cwd: args.cwd,
|
|
35212
36051
|
startNotice,
|
|
36052
|
+
sync,
|
|
35213
36053
|
...earn
|
|
35214
36054
|
};
|
|
35215
36055
|
}
|
|
@@ -35218,8 +36058,8 @@ function firstLine(e) {
|
|
|
35218
36058
|
}
|
|
35219
36059
|
|
|
35220
36060
|
// src/ui/App.tsx
|
|
35221
|
-
var
|
|
35222
|
-
import { homedir as
|
|
36061
|
+
var import_react27 = __toESM(require_react(), 1);
|
|
36062
|
+
import { homedir as homedir4 } from "node:os";
|
|
35223
36063
|
|
|
35224
36064
|
// src/util/open.ts
|
|
35225
36065
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -35252,7 +36092,7 @@ function initialState(sessionID, model = "") {
|
|
|
35252
36092
|
};
|
|
35253
36093
|
}
|
|
35254
36094
|
var str = (v) => typeof v === "string" ? v : v == null ? "" : JSON.stringify(v);
|
|
35255
|
-
var
|
|
36095
|
+
var num2 = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
35256
36096
|
function upsert(items, id, make, patch) {
|
|
35257
36097
|
const i = items.findIndex((it) => it.id === id);
|
|
35258
36098
|
if (i === -1) return [...items, make()];
|
|
@@ -35271,8 +36111,8 @@ function fileChange(metadata) {
|
|
|
35271
36111
|
let deletions = 0;
|
|
35272
36112
|
const patches = [];
|
|
35273
36113
|
for (const f of files) {
|
|
35274
|
-
additions +=
|
|
35275
|
-
deletions +=
|
|
36114
|
+
additions += num2(f.additions);
|
|
36115
|
+
deletions += num2(f.deletions);
|
|
35276
36116
|
if (typeof f.patch === "string") patches.push(f.patch);
|
|
35277
36117
|
}
|
|
35278
36118
|
return { diff: patches.join("\n") || void 0, additions, deletions };
|
|
@@ -35339,7 +36179,7 @@ function reduce(state, ev, now = Date.now()) {
|
|
|
35339
36179
|
case "session.reasoning.started":
|
|
35340
36180
|
case "session.reasoning.delta":
|
|
35341
36181
|
case "session.reasoning.ended": {
|
|
35342
|
-
const id = `reasoning:${str(d.assistantMessageID)}:${
|
|
36182
|
+
const id = `reasoning:${str(d.assistantMessageID)}:${num2(d.ordinal)}`;
|
|
35343
36183
|
const done = ev.type === "session.reasoning.ended";
|
|
35344
36184
|
const items = upsert(
|
|
35345
36185
|
state.items,
|
|
@@ -35352,7 +36192,7 @@ function reduce(state, ev, now = Date.now()) {
|
|
|
35352
36192
|
case "session.text.started":
|
|
35353
36193
|
case "session.text.delta":
|
|
35354
36194
|
case "session.text.ended": {
|
|
35355
|
-
const id = `text:${str(d.assistantMessageID)}:${
|
|
36195
|
+
const id = `text:${str(d.assistantMessageID)}:${num2(d.ordinal)}`;
|
|
35356
36196
|
const done = ev.type === "session.text.ended";
|
|
35357
36197
|
const items = upsert(
|
|
35358
36198
|
state.items,
|
|
@@ -35404,8 +36244,8 @@ function reduce(state, ev, now = Date.now()) {
|
|
|
35404
36244
|
const t = d.tokens ?? {};
|
|
35405
36245
|
return {
|
|
35406
36246
|
...state,
|
|
35407
|
-
cost:
|
|
35408
|
-
tokens: { input:
|
|
36247
|
+
cost: num2(d.cost),
|
|
36248
|
+
tokens: { input: num2(t.input), output: num2(t.output), reasoning: num2(t.reasoning) }
|
|
35409
36249
|
};
|
|
35410
36250
|
}
|
|
35411
36251
|
case "permission.asked": {
|
|
@@ -35452,6 +36292,197 @@ function reduce(state, ev, now = Date.now()) {
|
|
|
35452
36292
|
}
|
|
35453
36293
|
}
|
|
35454
36294
|
|
|
36295
|
+
// src/ui/StatusPanel.tsx
|
|
36296
|
+
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
36297
|
+
var fmtTok = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
|
|
36298
|
+
var fmtUsd2 = (n) => `$${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 2)}`;
|
|
36299
|
+
var fmtCredits = (n) => `${n.toFixed(n !== 0 && Math.abs(n) < 0.01 ? 4 : 3)} cr`;
|
|
36300
|
+
function Rule({ width }) {
|
|
36301
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u2500".repeat(Math.max(0, width)) });
|
|
36302
|
+
}
|
|
36303
|
+
function verdictLabel(v) {
|
|
36304
|
+
switch (v) {
|
|
36305
|
+
case "tracked":
|
|
36306
|
+
return { text: `${G.ok} view counted`, tone: "ok" };
|
|
36307
|
+
case "unearned":
|
|
36308
|
+
return { text: "view not paid on this device", tone: "warn" };
|
|
36309
|
+
case "skipped":
|
|
36310
|
+
return { text: "view not counted", tone: "faint" };
|
|
36311
|
+
case "error":
|
|
36312
|
+
return { text: "view not counted \xB7 server unreachable", tone: "warn" };
|
|
36313
|
+
default:
|
|
36314
|
+
return { text: "counting view\u2026", tone: "faint" };
|
|
36315
|
+
}
|
|
36316
|
+
}
|
|
36317
|
+
function Progress({ ms, of, billed, verdict }) {
|
|
36318
|
+
if (billed) {
|
|
36319
|
+
const l = verdictLabel(verdict);
|
|
36320
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: l.tone === "ok" ? C.ok : l.tone === "warn" ? C.warn : C.faint, children: l.text });
|
|
36321
|
+
}
|
|
36322
|
+
const n = 10;
|
|
36323
|
+
const filled = Math.min(n, Math.floor(ms / of * n));
|
|
36324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
|
|
36325
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.earn, children: "\u25B0".repeat(filled) }),
|
|
36326
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.border, children: "\u25B1".repeat(n - filled) }),
|
|
36327
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
36328
|
+
" ",
|
|
36329
|
+
Math.floor(ms / 1e3),
|
|
36330
|
+
"s / ",
|
|
36331
|
+
Math.round(of / 1e3),
|
|
36332
|
+
"s"
|
|
36333
|
+
] })
|
|
36334
|
+
] });
|
|
36335
|
+
}
|
|
36336
|
+
function StatusPanel(p) {
|
|
36337
|
+
const inner = p.width - 4;
|
|
36338
|
+
const frame = p.working ? C.accent : C.border;
|
|
36339
|
+
const name = p.model || "no model";
|
|
36340
|
+
const prov = p.provider ? ` \xB7 ${p.provider}` : "";
|
|
36341
|
+
const variant = p.variant ? ` ${p.variant}` : "";
|
|
36342
|
+
const spent = p.cost ? p.latent ? fmtCredits(p.cost) : fmtUsd2(p.cost) : "";
|
|
36343
|
+
const usage2 = [p.tokens ? `${fmtTok(p.tokens)} tok` : "", spent].filter(Boolean).join(" \xB7 ");
|
|
36344
|
+
const rightLen = usage2 ? usage2.length + 2 : 0;
|
|
36345
|
+
const leftBudget = p.width - 9 - rightLen;
|
|
36346
|
+
const leftText = clip(`${name}${variant}${prov}`, Math.max(8, leftBudget));
|
|
36347
|
+
const fill = Math.max(1, p.width - 8 - leftText.length - rightLen);
|
|
36348
|
+
const top = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36349
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: frame, children: "\u256D\u2500 " }),
|
|
36350
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: p.latent ? C.earn : p.working ? C.accent : C.ok, children: G.dot }),
|
|
36351
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
|
|
36352
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, color: C.text, children: leftText.slice(0, name.length) }),
|
|
36353
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.accent2, children: leftText.slice(name.length, name.length + variant.length) }),
|
|
36354
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.muted, children: leftText.slice(name.length + variant.length) }),
|
|
36355
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: frame, children: [
|
|
36356
|
+
" ",
|
|
36357
|
+
"\u2500".repeat(fill)
|
|
36358
|
+
] }),
|
|
36359
|
+
usage2 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
36360
|
+
" ",
|
|
36361
|
+
usage2,
|
|
36362
|
+
" "
|
|
36363
|
+
] }) : null,
|
|
36364
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: frame, children: "\u2500\u256E" })
|
|
36365
|
+
] });
|
|
36366
|
+
const earnings = p.earn === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36367
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
|
|
36368
|
+
G.earn,
|
|
36369
|
+
" "
|
|
36370
|
+
] }),
|
|
36371
|
+
p.balance != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
36372
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, bold: true, children: [
|
|
36373
|
+
p.balance.toFixed(3),
|
|
36374
|
+
" cr"
|
|
36375
|
+
] }),
|
|
36376
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " \xB7 " })
|
|
36377
|
+
] }) : null,
|
|
36378
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.earn, children: [
|
|
36379
|
+
"+",
|
|
36380
|
+
p.sessionCredits.toFixed(3)
|
|
36381
|
+
] }),
|
|
36382
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
36383
|
+
inner >= 84 ? " this session" : "",
|
|
36384
|
+
" \xB7 ",
|
|
36385
|
+
p.views,
|
|
36386
|
+
" view",
|
|
36387
|
+
p.views === 1 ? "" : "s"
|
|
36388
|
+
] })
|
|
36389
|
+
] }) : p.earn === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
36390
|
+
G.earn,
|
|
36391
|
+
" Earn off \xB7 /ads on"
|
|
36392
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.warn, children: [
|
|
36393
|
+
G.earn,
|
|
36394
|
+
" /login to start earning"
|
|
36395
|
+
] });
|
|
36396
|
+
const ad = p.earn === "ok" ? p.ad : null;
|
|
36397
|
+
let body;
|
|
36398
|
+
if (ad) {
|
|
36399
|
+
const badge = adBadge(ad.title || ad.body);
|
|
36400
|
+
const cta = ad.link ? `${ad.ctaText || "Open"} ${G.arrow}` : "";
|
|
36401
|
+
const ctaLen = cta ? cta.length + 8 : 0;
|
|
36402
|
+
const brand = ad.title || ad.body;
|
|
36403
|
+
const rest = ad.title && ad.body ? ` \u2014 ${ad.body}` : "";
|
|
36404
|
+
const copyText = clip(brand + rest, Math.max(10, inner - 4 - ctaLen));
|
|
36405
|
+
const copy = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
|
|
36406
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, underline: !!ad.link && p.osc8Links, children: copyText.slice(0, brand.length) }),
|
|
36407
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.muted, children: copyText.slice(brand.length) })
|
|
36408
|
+
] });
|
|
36409
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
36410
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36411
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, bold: true, children: "SPONSORED" }),
|
|
36412
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, children: [
|
|
36413
|
+
"AD \xB7 ",
|
|
36414
|
+
String(p.adIndex ?? 1).padStart(2, "0")
|
|
36415
|
+
] })
|
|
36416
|
+
] }),
|
|
36417
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36418
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36419
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { backgroundColor: badge.color, color: "#111827", bold: true, children: ` ${badge.letter} ` }),
|
|
36420
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: " " }),
|
|
36421
|
+
p.osc8Links && ad.link ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Transform, { transform: (o) => osc8(o, ad.link), children: copy }) : copy
|
|
36422
|
+
] }),
|
|
36423
|
+
cta ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { children: [
|
|
36424
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.accent2, bold: true, children: cta }),
|
|
36425
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " ctrl+o" })
|
|
36426
|
+
] }) : null
|
|
36427
|
+
] }),
|
|
36428
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Rule, { width: inner }),
|
|
36429
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36430
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36431
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Progress, { ms: p.visibleMs ?? 0, of: p.minVisibleMs ?? 1e4, billed: !!p.billed, verdict: p.verdict }),
|
|
36432
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: C.faint, children: " \xB7 Powered by Latent Ads" })
|
|
36433
|
+
] }),
|
|
36434
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexShrink: 0, marginLeft: 2, children: earnings })
|
|
36435
|
+
] })
|
|
36436
|
+
] });
|
|
36437
|
+
} else {
|
|
36438
|
+
body = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36439
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: C.faint, wrap: "truncate-end", children: [
|
|
36440
|
+
p.wallet ? p.wallet : "",
|
|
36441
|
+
p.earn === "ok" ? `${p.wallet ? " \xB7 " : ""}ads show while the agent works` : ""
|
|
36442
|
+
] }),
|
|
36443
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexShrink: 0, marginLeft: 2, children: earnings })
|
|
36444
|
+
] });
|
|
36445
|
+
}
|
|
36446
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { flexDirection: "column", width: p.width, children: [
|
|
36447
|
+
top,
|
|
36448
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexDirection: "column", borderStyle: "round", borderTop: false, borderColor: frame, paddingX: 1, width: p.width, children: body })
|
|
36449
|
+
] });
|
|
36450
|
+
}
|
|
36451
|
+
|
|
36452
|
+
// src/engine/overflow.ts
|
|
36453
|
+
var OVERFLOW_MIN_CREDITS = 0.5;
|
|
36454
|
+
var OVERFLOW_FALLBACKS = ["claude-sonnet-5-5", "claude-opus-5-5", "z-ai-glm-5-3", "qwen3-coder-480b-a35b-instruct-turbo"];
|
|
36455
|
+
var compact = (s2) => s2.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
36456
|
+
function bareId(key) {
|
|
36457
|
+
const i = key.indexOf("/");
|
|
36458
|
+
return i >= 0 ? key.slice(i + 1) : key;
|
|
36459
|
+
}
|
|
36460
|
+
function overflowTarget(failedKey, catalog) {
|
|
36461
|
+
const latent = catalog.models.filter((m) => m.providerID === LATENT_ID);
|
|
36462
|
+
if (!latent.length) return null;
|
|
36463
|
+
const failed = catalog.models.find((m) => m.key === failedKey);
|
|
36464
|
+
const wants = [compact(bareId(bareId(failedKey))), failed ? compact(failed.name) : ""].filter((w) => w.length >= 3);
|
|
36465
|
+
for (const w of wants) {
|
|
36466
|
+
const exact = latent.find((m) => compact(m.id) === w || compact(m.name) === w);
|
|
36467
|
+
if (exact) return exact;
|
|
36468
|
+
}
|
|
36469
|
+
for (const w of wants) {
|
|
36470
|
+
const near = latent.filter((m) => compact(m.id).includes(w) || compact(m.name).includes(w)).sort((a2, b) => a2.id.length - b.id.length);
|
|
36471
|
+
if (near[0]) return near[0];
|
|
36472
|
+
}
|
|
36473
|
+
for (const id of OVERFLOW_FALLBACKS) {
|
|
36474
|
+
const m = latent.find((x) => x.id === id);
|
|
36475
|
+
if (m) return m;
|
|
36476
|
+
}
|
|
36477
|
+
return latent[0];
|
|
36478
|
+
}
|
|
36479
|
+
function overflowOffer(model, verdict, catalog, balance, offered) {
|
|
36480
|
+
if (verdict.status !== "rate-limited" || !model || model.startsWith(`${LATENT_ID}/`)) return null;
|
|
36481
|
+
if (balance === null || balance < OVERFLOW_MIN_CREDITS || offered.has(model)) return null;
|
|
36482
|
+
const to = overflowTarget(model, catalog);
|
|
36483
|
+
return to ? { from: model, to, credits: balance } : null;
|
|
36484
|
+
}
|
|
36485
|
+
|
|
35455
36486
|
// src/ui/components.tsx
|
|
35456
36487
|
var import_react22 = __toESM(require_react(), 1);
|
|
35457
36488
|
|
|
@@ -35668,7 +36699,7 @@ function parseDiff(patch, max = 14) {
|
|
|
35668
36699
|
}
|
|
35669
36700
|
|
|
35670
36701
|
// src/ui/components.tsx
|
|
35671
|
-
var
|
|
36702
|
+
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
35672
36703
|
function useTermSize() {
|
|
35673
36704
|
const { stdout } = use_stdout_default();
|
|
35674
36705
|
const read = () => ({ cols: stdout.columns || 80, rows: stdout.rows || 24 });
|
|
@@ -35688,21 +36719,21 @@ function Spinner({ color = C.accent }) {
|
|
|
35688
36719
|
const t = setInterval(() => setI((n) => (n + 1) % SPINNER.length), 90);
|
|
35689
36720
|
return () => clearInterval(t);
|
|
35690
36721
|
}, []);
|
|
35691
|
-
return /* @__PURE__ */ (0,
|
|
36722
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color, children: SPINNER[i] });
|
|
35692
36723
|
}
|
|
35693
36724
|
function Logo({ version }) {
|
|
35694
|
-
return /* @__PURE__ */ (0,
|
|
35695
|
-
/* @__PURE__ */ (0,
|
|
35696
|
-
/* @__PURE__ */ (0,
|
|
35697
|
-
/* @__PURE__ */ (0,
|
|
35698
|
-
row2 === 1 && version ? /* @__PURE__ */ (0,
|
|
36725
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box_default, { flexDirection: "column", children: [0, 1].map((row2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36726
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.accent, children: LOGO.latent[row2] }),
|
|
36727
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
36728
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.accent2, children: LOGO.code[row2] }),
|
|
36729
|
+
row2 === 1 && version ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35699
36730
|
" v",
|
|
35700
36731
|
version
|
|
35701
36732
|
] }) : null
|
|
35702
36733
|
] }, row2)) });
|
|
35703
36734
|
}
|
|
35704
36735
|
function Panel(props) {
|
|
35705
|
-
return /* @__PURE__ */ (0,
|
|
36736
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
35706
36737
|
Box_default,
|
|
35707
36738
|
{
|
|
35708
36739
|
flexDirection: "column",
|
|
@@ -35712,21 +36743,21 @@ function Panel(props) {
|
|
|
35712
36743
|
width: props.width,
|
|
35713
36744
|
marginTop: 1,
|
|
35714
36745
|
children: [
|
|
35715
|
-
/* @__PURE__ */ (0,
|
|
35716
|
-
/* @__PURE__ */ (0,
|
|
35717
|
-
props.right ? /* @__PURE__ */ (0,
|
|
36746
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
36747
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { bold: true, color: props.color ?? C.accent, children: props.title }),
|
|
36748
|
+
props.right ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: props.right }) : null
|
|
35718
36749
|
] }),
|
|
35719
36750
|
props.children,
|
|
35720
|
-
props.footer ? /* @__PURE__ */ (0,
|
|
36751
|
+
props.footer ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box_default, { marginTop: 1, children: props.footer }) : null
|
|
35721
36752
|
]
|
|
35722
36753
|
}
|
|
35723
36754
|
);
|
|
35724
36755
|
}
|
|
35725
36756
|
function Hints({ items }) {
|
|
35726
|
-
return /* @__PURE__ */ (0,
|
|
35727
|
-
i ? /* @__PURE__ */ (0,
|
|
35728
|
-
/* @__PURE__ */ (0,
|
|
35729
|
-
/* @__PURE__ */ (0,
|
|
36757
|
+
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: [
|
|
36758
|
+
i ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: " \xB7 " }) : null,
|
|
36759
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.muted, children: k }),
|
|
36760
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35730
36761
|
" ",
|
|
35731
36762
|
label2
|
|
35732
36763
|
] })
|
|
@@ -35744,16 +36775,16 @@ function usePaste(handler, active = true) {
|
|
|
35744
36775
|
}
|
|
35745
36776
|
function FieldText({ state, mask, placeholder }) {
|
|
35746
36777
|
if (!state.text && placeholder) {
|
|
35747
|
-
return /* @__PURE__ */ (0,
|
|
35748
|
-
/* @__PURE__ */ (0,
|
|
35749
|
-
/* @__PURE__ */ (0,
|
|
36778
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36779
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { inverse: true, children: " " }),
|
|
36780
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: placeholder })
|
|
35750
36781
|
] });
|
|
35751
36782
|
}
|
|
35752
36783
|
const shown = mask ? { ...state, text: "\u2022".repeat(state.text.length) } : state;
|
|
35753
36784
|
const { before, at, after } = splitAtCursor(shown);
|
|
35754
|
-
return /* @__PURE__ */ (0,
|
|
36785
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
35755
36786
|
before,
|
|
35756
|
-
/* @__PURE__ */ (0,
|
|
36787
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { inverse: true, children: at }),
|
|
35757
36788
|
after
|
|
35758
36789
|
] });
|
|
35759
36790
|
}
|
|
@@ -35779,64 +36810,64 @@ function useLineField(opts) {
|
|
|
35779
36810
|
return { state, text: state.text, set: (t) => update(setText(ref.current, t)) };
|
|
35780
36811
|
}
|
|
35781
36812
|
function Spans({ spans }) {
|
|
35782
|
-
return /* @__PURE__ */ (0,
|
|
36813
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: spans.map((s2, i) => {
|
|
35783
36814
|
switch (s2.t) {
|
|
35784
36815
|
case "bold":
|
|
35785
|
-
return /* @__PURE__ */ (0,
|
|
36816
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { bold: true, children: s2.v }, i);
|
|
35786
36817
|
case "italic":
|
|
35787
|
-
return /* @__PURE__ */ (0,
|
|
36818
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { italic: true, children: s2.v }, i);
|
|
35788
36819
|
case "code":
|
|
35789
|
-
return /* @__PURE__ */ (0,
|
|
36820
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.code, children: s2.v }, i);
|
|
35790
36821
|
case "link":
|
|
35791
|
-
return /* @__PURE__ */ (0,
|
|
35792
|
-
/* @__PURE__ */ (0,
|
|
35793
|
-
s2.url !== s2.v ? /* @__PURE__ */ (0,
|
|
36822
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { children: [
|
|
36823
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { underline: true, children: s2.v }),
|
|
36824
|
+
s2.url !== s2.v ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35794
36825
|
" (",
|
|
35795
36826
|
s2.url,
|
|
35796
36827
|
")"
|
|
35797
36828
|
] }) : null
|
|
35798
36829
|
] }, i);
|
|
35799
36830
|
default:
|
|
35800
|
-
return /* @__PURE__ */ (0,
|
|
36831
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: s2.v }, i);
|
|
35801
36832
|
}
|
|
35802
36833
|
}) });
|
|
35803
36834
|
}
|
|
35804
36835
|
function BlockView({ b }) {
|
|
35805
36836
|
switch (b.t) {
|
|
35806
36837
|
case "h":
|
|
35807
|
-
return /* @__PURE__ */ (0,
|
|
36838
|
+
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 }) });
|
|
35808
36839
|
case "li":
|
|
35809
|
-
return /* @__PURE__ */ (0,
|
|
35810
|
-
/* @__PURE__ */ (0,
|
|
36840
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { marginLeft: b.indent * 2, children: [
|
|
36841
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.accent, children: [
|
|
35811
36842
|
b.marker,
|
|
35812
36843
|
" "
|
|
35813
36844
|
] }),
|
|
35814
|
-
/* @__PURE__ */ (0,
|
|
36845
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) })
|
|
35815
36846
|
] });
|
|
35816
36847
|
case "quote":
|
|
35817
|
-
return /* @__PURE__ */ (0,
|
|
35818
|
-
/* @__PURE__ */ (0,
|
|
36848
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { children: [
|
|
36849
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Text, { color: C.faint, children: [
|
|
35819
36850
|
G.thin,
|
|
35820
36851
|
" "
|
|
35821
36852
|
] }),
|
|
35822
|
-
/* @__PURE__ */ (0,
|
|
36853
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.muted, italic: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) })
|
|
35823
36854
|
] });
|
|
35824
36855
|
case "code":
|
|
35825
|
-
return /* @__PURE__ */ (0,
|
|
35826
|
-
b.lang ? /* @__PURE__ */ (0,
|
|
35827
|
-
/* @__PURE__ */ (0,
|
|
36856
|
+
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: [
|
|
36857
|
+
b.lang ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: b.lang }) : null,
|
|
36858
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.code, children: b.lines.join("\n") || " " })
|
|
35828
36859
|
] });
|
|
35829
36860
|
case "rule":
|
|
35830
|
-
return /* @__PURE__ */ (0,
|
|
36861
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: C.faint, children: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500" });
|
|
35831
36862
|
case "gap":
|
|
35832
|
-
return /* @__PURE__ */ (0,
|
|
36863
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " });
|
|
35833
36864
|
default:
|
|
35834
|
-
return /* @__PURE__ */ (0,
|
|
36865
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spans, { spans: b.spans }) });
|
|
35835
36866
|
}
|
|
35836
36867
|
}
|
|
35837
36868
|
function Markdown({ text }) {
|
|
35838
36869
|
const blocks = parseMarkdown(text);
|
|
35839
|
-
return /* @__PURE__ */ (0,
|
|
36870
|
+
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)) });
|
|
35840
36871
|
}
|
|
35841
36872
|
function windowAround(total, selected, size) {
|
|
35842
36873
|
if (total <= size) return { start: 0, end: total };
|
|
@@ -35856,8 +36887,11 @@ var COMMANDS = [
|
|
|
35856
36887
|
{ name: "model", args: "[name]", desc: "Switch model \u2014 search, filter by provider, set effort", group: "Models", aliases: ["models"] },
|
|
35857
36888
|
{ name: "providers", desc: "Connected providers and what each one offers", group: "Models" },
|
|
35858
36889
|
{ name: "connect", args: "[provider]", desc: "Connect a provider: API key or account sign-in", group: "Models" },
|
|
36890
|
+
{ name: "mcp", args: "[add name url|cmd\u2026]", desc: "MCP servers (shared with OpenCode): status, sign in, add, remove", group: "Models" },
|
|
35859
36891
|
{ name: "login", desc: "Connect the wallet Earn mode pays into", group: "Earn", aliases: ["wallet"] },
|
|
35860
|
-
{ name: "earn", desc: "Earnings: this session and your
|
|
36892
|
+
{ name: "earn", desc: "Earnings: this session and your Latent Credit", group: "Earn" },
|
|
36893
|
+
{ name: "credits", desc: "Latent Credit: balance, bonus, mode, sell price", group: "Earn", aliases: ["credit"] },
|
|
36894
|
+
{ name: "key", args: "lk_\u2026", desc: "Use your Latent Key as a provider \u2014 earnings become model usage", group: "Earn" },
|
|
35861
36895
|
{ name: "ads", args: "on|off", desc: "Turn Earn mode (the sponsored line) on or off", group: "Earn" },
|
|
35862
36896
|
{ name: "new", desc: "Start a fresh session", group: "Session" },
|
|
35863
36897
|
{ name: "compact", desc: "Summarise the conversation to free up context", group: "Session" },
|
|
@@ -35865,16 +36899,16 @@ var COMMANDS = [
|
|
|
35865
36899
|
{ name: "help", desc: "Keys and commands", group: "App", aliases: ["?"] },
|
|
35866
36900
|
{ name: "exit", desc: "Quit LatentCode", group: "App", aliases: ["quit"] }
|
|
35867
36901
|
];
|
|
35868
|
-
function findCommand(name,
|
|
36902
|
+
function findCommand(name, list2 = COMMANDS) {
|
|
35869
36903
|
const n = name.toLowerCase();
|
|
35870
|
-
return
|
|
36904
|
+
return list2.find((c) => c.name === n || c.aliases?.includes(n));
|
|
35871
36905
|
}
|
|
35872
|
-
function matchCommands(input,
|
|
36906
|
+
function matchCommands(input, list2 = COMMANDS) {
|
|
35873
36907
|
if (!input.startsWith("/") || /\s/.test(input)) return [];
|
|
35874
36908
|
const q = input.slice(1).toLowerCase();
|
|
35875
|
-
const starts =
|
|
35876
|
-
const contains =
|
|
35877
|
-
return q ? [...starts, ...contains] :
|
|
36909
|
+
const starts = list2.filter((c) => c.name.startsWith(q) || c.aliases?.some((a2) => a2.startsWith(q)));
|
|
36910
|
+
const contains = list2.filter((c) => !starts.includes(c) && (c.name.includes(q) || c.desc.toLowerCase().includes(q)));
|
|
36911
|
+
return q ? [...starts, ...contains] : list2;
|
|
35878
36912
|
}
|
|
35879
36913
|
function parseCommandLine(line) {
|
|
35880
36914
|
const m = line.slice(1).trim().match(/^(\S*)\s*([\s\S]*)$/);
|
|
@@ -35882,7 +36916,7 @@ function parseCommandLine(line) {
|
|
|
35882
36916
|
}
|
|
35883
36917
|
|
|
35884
36918
|
// src/ui/Transcript.tsx
|
|
35885
|
-
var
|
|
36919
|
+
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
|
35886
36920
|
function lastLines(text, n) {
|
|
35887
36921
|
const lines = text.trimEnd().split("\n");
|
|
35888
36922
|
return lines.length <= n ? lines.join("\n") : lines.slice(-n).join("\n");
|
|
@@ -35937,55 +36971,55 @@ function ToolView({ item, cwd: cwd2, width }) {
|
|
|
35937
36971
|
const diff2 = item.diff ? parseDiff(item.diff) : null;
|
|
35938
36972
|
const showOutput = item.output && (failed || !QUIET.has(item.name)) && !diff2;
|
|
35939
36973
|
const out = showOutput ? firstLines(item.output, failed ? 8 : 6) : null;
|
|
35940
|
-
return /* @__PURE__ */ (0,
|
|
35941
|
-
/* @__PURE__ */ (0,
|
|
35942
|
-
running ? /* @__PURE__ */ (0,
|
|
35943
|
-
/* @__PURE__ */ (0,
|
|
36974
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", width, children: [
|
|
36975
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
36976
|
+
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 }),
|
|
36977
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { bold: true, color: t.verb === "$" ? C.accent2 : void 0, children: [
|
|
35944
36978
|
" ",
|
|
35945
36979
|
t.verb
|
|
35946
36980
|
] }),
|
|
35947
|
-
/* @__PURE__ */ (0,
|
|
36981
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
35948
36982
|
" ",
|
|
35949
36983
|
clip(t.target, Math.max(20, width - t.verb.length - 24))
|
|
35950
36984
|
] }),
|
|
35951
|
-
t.extra ? /* @__PURE__ */ (0,
|
|
36985
|
+
t.extra ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35952
36986
|
" ",
|
|
35953
36987
|
t.extra
|
|
35954
36988
|
] }) : null,
|
|
35955
|
-
item.additions || item.deletions ? /* @__PURE__ */ (0,
|
|
35956
|
-
/* @__PURE__ */ (0,
|
|
36989
|
+
item.additions || item.deletions ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
36990
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.add, children: [
|
|
35957
36991
|
" +",
|
|
35958
36992
|
item.additions ?? 0
|
|
35959
36993
|
] }),
|
|
35960
|
-
/* @__PURE__ */ (0,
|
|
36994
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.del, children: [
|
|
35961
36995
|
" \u2212",
|
|
35962
36996
|
item.deletions ?? 0
|
|
35963
36997
|
] })
|
|
35964
36998
|
] }) : null,
|
|
35965
|
-
item.ms !== void 0 && item.ms >= 1e3 ? /* @__PURE__ */ (0,
|
|
36999
|
+
item.ms !== void 0 && item.ms >= 1e3 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35966
37000
|
" \xB7 ",
|
|
35967
37001
|
fmtDuration(item.ms)
|
|
35968
37002
|
] }) : null
|
|
35969
37003
|
] }),
|
|
35970
|
-
diff2 && diff2.lines.length ? /* @__PURE__ */ (0,
|
|
35971
|
-
diff2.lines.map((l, i) => /* @__PURE__ */ (0,
|
|
37004
|
+
diff2 && diff2.lines.length ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", marginLeft: 2, children: [
|
|
37005
|
+
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: [
|
|
35972
37006
|
l.t === "add" ? "+ " : l.t === "del" ? "\u2212 " : l.t === "hunk" ? "" : " ",
|
|
35973
37007
|
l.t === "hunk" ? "\u22EF" : l.text
|
|
35974
37008
|
] }, i)),
|
|
35975
|
-
diff2.more ? /* @__PURE__ */ (0,
|
|
37009
|
+
diff2.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35976
37010
|
"\u2026 ",
|
|
35977
37011
|
diff2.more,
|
|
35978
37012
|
" more lines"
|
|
35979
37013
|
] }) : null
|
|
35980
37014
|
] }) : null,
|
|
35981
|
-
out ? /* @__PURE__ */ (0,
|
|
35982
|
-
/* @__PURE__ */ (0,
|
|
37015
|
+
out ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginLeft: 2, children: [
|
|
37016
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35983
37017
|
G.elbow,
|
|
35984
37018
|
" "
|
|
35985
37019
|
] }) }),
|
|
35986
|
-
/* @__PURE__ */ (0,
|
|
35987
|
-
/* @__PURE__ */ (0,
|
|
35988
|
-
out.more ? /* @__PURE__ */ (0,
|
|
37020
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
37021
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: failed ? C.err : C.muted, children: out.text }),
|
|
37022
|
+
out.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
35989
37023
|
"\u2026 ",
|
|
35990
37024
|
out.more,
|
|
35991
37025
|
" more lines"
|
|
@@ -35999,25 +37033,25 @@ var NOTICE_MARK = { info: G.bullet, ok: G.ok, warn: G.warn, error: G.no };
|
|
|
35999
37033
|
function ItemView({ item, live, cwd: cwd2, width, maxLines }) {
|
|
36000
37034
|
switch (item.kind) {
|
|
36001
37035
|
case "user":
|
|
36002
|
-
return /* @__PURE__ */ (0,
|
|
36003
|
-
/* @__PURE__ */ (0,
|
|
37036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
37037
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.accent, bold: true, children: [
|
|
36004
37038
|
G.prompt,
|
|
36005
37039
|
" "
|
|
36006
37040
|
] }) }),
|
|
36007
|
-
/* @__PURE__ */ (0,
|
|
37041
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { bold: true, children: item.text })
|
|
36008
37042
|
] });
|
|
36009
37043
|
case "reasoning": {
|
|
36010
37044
|
const text = item.text.trim();
|
|
36011
37045
|
if (!text) return null;
|
|
36012
37046
|
const shown = live ? lastLines(text, 4) : firstLines(text, 2);
|
|
36013
|
-
return /* @__PURE__ */ (0,
|
|
36014
|
-
/* @__PURE__ */ (0,
|
|
37047
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
37048
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36015
37049
|
G.thin,
|
|
36016
37050
|
" "
|
|
36017
37051
|
] }) }),
|
|
36018
|
-
/* @__PURE__ */ (0,
|
|
36019
|
-
/* @__PURE__ */ (0,
|
|
36020
|
-
typeof shown !== "string" && shown.more ? /* @__PURE__ */ (0,
|
|
37052
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
37053
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.faint, italic: true, children: typeof shown === "string" ? shown : shown.text }),
|
|
37054
|
+
typeof shown !== "string" && shown.more ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36021
37055
|
"\u2026 thought for ",
|
|
36022
37056
|
shown.more,
|
|
36023
37057
|
" more lines"
|
|
@@ -36026,25 +37060,25 @@ function ItemView({ item, live, cwd: cwd2, width, maxLines }) {
|
|
|
36026
37060
|
] });
|
|
36027
37061
|
}
|
|
36028
37062
|
case "text":
|
|
36029
|
-
return /* @__PURE__ */ (0,
|
|
37063
|
+
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 }) });
|
|
36030
37064
|
case "tool":
|
|
36031
|
-
return /* @__PURE__ */ (0,
|
|
37065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolView, { item, cwd: cwd2, width });
|
|
36032
37066
|
case "error":
|
|
36033
|
-
return /* @__PURE__ */ (0,
|
|
36034
|
-
/* @__PURE__ */ (0,
|
|
37067
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
37068
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.err, children: [
|
|
36035
37069
|
G.no,
|
|
36036
37070
|
" "
|
|
36037
37071
|
] }) }),
|
|
36038
|
-
/* @__PURE__ */ (0,
|
|
37072
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.err, wrap: "wrap", children: item.text })
|
|
36039
37073
|
] });
|
|
36040
37074
|
case "notice": {
|
|
36041
37075
|
const tone = item.tone ?? "info";
|
|
36042
|
-
return /* @__PURE__ */ (0,
|
|
36043
|
-
/* @__PURE__ */ (0,
|
|
37076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, width, children: [
|
|
37077
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: NOTICE_COLOR[tone], children: [
|
|
36044
37078
|
NOTICE_MARK[tone],
|
|
36045
37079
|
" "
|
|
36046
37080
|
] }) }),
|
|
36047
|
-
/* @__PURE__ */ (0,
|
|
37081
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: tone === "info" ? C.muted : NOTICE_COLOR[tone], wrap: "wrap", children: item.text })
|
|
36048
37082
|
] });
|
|
36049
37083
|
}
|
|
36050
37084
|
}
|
|
@@ -36058,19 +37092,19 @@ function PermissionPrompt({ perm, selected, cwd: cwd2, width }) {
|
|
|
36058
37092
|
const options = ["Allow once", "Always allow", "Reject"];
|
|
36059
37093
|
const keys = ["y", "a", "n"];
|
|
36060
37094
|
const what = perm.resources.map((r) => relPath(r, cwd2)).join(", ") || perm.message || "";
|
|
36061
|
-
return /* @__PURE__ */ (0,
|
|
36062
|
-
/* @__PURE__ */ (0,
|
|
36063
|
-
/* @__PURE__ */ (0,
|
|
36064
|
-
/* @__PURE__ */ (0,
|
|
37095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { marginTop: 1, borderStyle: "round", borderColor: C.warn, paddingX: 1, flexDirection: "column", width, children: [
|
|
37096
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box_default, { justifyContent: "space-between", children: [
|
|
37097
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { bold: true, color: C.warn, children: PERMISSION_TITLE[perm.action] ?? `Allow ${perm.action}?` }),
|
|
37098
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { color: C.faint, children: perm.action })
|
|
36065
37099
|
] }),
|
|
36066
|
-
/* @__PURE__ */ (0,
|
|
37100
|
+
/* @__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: [
|
|
36067
37101
|
perm.action === "shell" ? "$ " : "",
|
|
36068
37102
|
clip(what, 600)
|
|
36069
37103
|
] }) }),
|
|
36070
|
-
/* @__PURE__ */ (0,
|
|
37104
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text, { children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { children: [
|
|
36071
37105
|
i ? " " : "",
|
|
36072
|
-
/* @__PURE__ */ (0,
|
|
36073
|
-
/* @__PURE__ */ (0,
|
|
37106
|
+
/* @__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} ` }),
|
|
37107
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Text, { color: C.faint, children: [
|
|
36074
37108
|
" ",
|
|
36075
37109
|
keys[i]
|
|
36076
37110
|
] })
|
|
@@ -36080,22 +37114,22 @@ function PermissionPrompt({ perm, selected, cwd: cwd2, width }) {
|
|
|
36080
37114
|
|
|
36081
37115
|
// src/ui/panels/ModelPicker.tsx
|
|
36082
37116
|
var import_react23 = __toESM(require_react(), 1);
|
|
36083
|
-
var
|
|
37117
|
+
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
36084
37118
|
function Mark({ status: status2, testing }) {
|
|
36085
|
-
if (testing) return /* @__PURE__ */ (0,
|
|
37119
|
+
if (testing) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Spinner, {});
|
|
36086
37120
|
switch (status2) {
|
|
36087
37121
|
case "ok":
|
|
36088
|
-
return /* @__PURE__ */ (0,
|
|
37122
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.ok, children: G.ok });
|
|
36089
37123
|
case "unsupported":
|
|
36090
|
-
return /* @__PURE__ */ (0,
|
|
37124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, children: G.no });
|
|
36091
37125
|
case "rate-limited":
|
|
36092
|
-
return /* @__PURE__ */ (0,
|
|
37126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.warn, children: G.wait });
|
|
36093
37127
|
case "auth":
|
|
36094
|
-
return /* @__PURE__ */ (0,
|
|
37128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.warn, children: G.key });
|
|
36095
37129
|
case "error":
|
|
36096
|
-
return /* @__PURE__ */ (0,
|
|
37130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.err, children: G.warn });
|
|
36097
37131
|
default:
|
|
36098
|
-
return /* @__PURE__ */ (0,
|
|
37132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "\xB7" });
|
|
36099
37133
|
}
|
|
36100
37134
|
}
|
|
36101
37135
|
function ModelPicker(p) {
|
|
@@ -36177,21 +37211,21 @@ function ModelPicker(p) {
|
|
|
36177
37211
|
const below = models.filter((m) => rows.findIndex((r) => r.t === "model" && r.m === m) >= start + visible).length;
|
|
36178
37212
|
const inner = p.width - 4;
|
|
36179
37213
|
const wCtx = 5;
|
|
36180
|
-
const wPrice =
|
|
37214
|
+
const wPrice = 13;
|
|
36181
37215
|
const wNote = 14;
|
|
36182
37216
|
const rest = inner - 4 - wCtx - wPrice - wNote - 3;
|
|
36183
37217
|
const wName = Math.max(16, Math.min(32, Math.floor(rest * 0.5)));
|
|
36184
37218
|
const wId = Math.max(0, rest - wName);
|
|
36185
37219
|
const kindOf = (id) => p.catalog.providers.find((x) => x.id === id)?.kind ?? "unknown";
|
|
36186
37220
|
const verified = p.catalog.models.filter((m) => p.status(m.key) === "ok").length;
|
|
36187
|
-
return /* @__PURE__ */ (0,
|
|
37221
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
36188
37222
|
Panel,
|
|
36189
37223
|
{
|
|
36190
37224
|
title: "Models",
|
|
36191
37225
|
right: `${p.catalog.models.length} models \xB7 ${verified} verified with your account`,
|
|
36192
37226
|
width: p.width,
|
|
36193
37227
|
color: C.accent,
|
|
36194
|
-
footer: /* @__PURE__ */ (0,
|
|
37228
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
36195
37229
|
Hints,
|
|
36196
37230
|
{
|
|
36197
37231
|
items: [
|
|
@@ -36205,36 +37239,36 @@ function ModelPicker(p) {
|
|
|
36205
37239
|
}
|
|
36206
37240
|
),
|
|
36207
37241
|
children: [
|
|
36208
|
-
/* @__PURE__ */ (0,
|
|
36209
|
-
/* @__PURE__ */ (0,
|
|
37242
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37243
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
36210
37244
|
G.search,
|
|
36211
37245
|
" "
|
|
36212
37246
|
] }),
|
|
36213
|
-
/* @__PURE__ */ (0,
|
|
37247
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FieldText, { state: field.state, placeholder: "type to search \u2014 name, id or provider" })
|
|
36214
37248
|
] }),
|
|
36215
|
-
/* @__PURE__ */ (0,
|
|
37249
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, flexWrap: "wrap", children: tabs.map((id, i) => {
|
|
36216
37250
|
const prov = p.catalog.providers.find((x) => x.id === id);
|
|
36217
37251
|
const text = prov ? `${prov.name} ${prov.models}` : `All ${p.catalog.models.length}`;
|
|
36218
|
-
return /* @__PURE__ */ (0,
|
|
37252
|
+
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");
|
|
36219
37253
|
}) }),
|
|
36220
|
-
/* @__PURE__ */ (0,
|
|
36221
|
-
above ? /* @__PURE__ */ (0,
|
|
37254
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37255
|
+
above ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36222
37256
|
" ",
|
|
36223
37257
|
G.up,
|
|
36224
37258
|
" ",
|
|
36225
37259
|
above,
|
|
36226
37260
|
" more"
|
|
36227
37261
|
] }) : null,
|
|
36228
|
-
shown.length === 0 ? /* @__PURE__ */ (0,
|
|
37262
|
+
shown.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.muted, children: [
|
|
36229
37263
|
" No model matches \u201C",
|
|
36230
37264
|
field.text,
|
|
36231
37265
|
"\u201D."
|
|
36232
37266
|
] }) : null,
|
|
36233
37267
|
shown.map((r, i) => {
|
|
36234
37268
|
if (r.t === "head") {
|
|
36235
|
-
return /* @__PURE__ */ (0,
|
|
36236
|
-
/* @__PURE__ */ (0,
|
|
36237
|
-
/* @__PURE__ */ (0,
|
|
37269
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37270
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: true, color: C.muted, children: r.label }),
|
|
37271
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36238
37272
|
" ",
|
|
36239
37273
|
r.hint
|
|
36240
37274
|
] })
|
|
@@ -36245,33 +37279,33 @@ function ModelPicker(p) {
|
|
|
36245
37279
|
const st = p.status(m.key);
|
|
36246
37280
|
const dead = st === "unsupported";
|
|
36247
37281
|
const note = m.key === p.current ? "current" : st === "unsupported" ? "not on your plan" : st !== "unknown" && st !== "ok" ? label(st) : "";
|
|
36248
|
-
return /* @__PURE__ */ (0,
|
|
36249
|
-
/* @__PURE__ */ (0,
|
|
37282
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37283
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.accent, children: [
|
|
36250
37284
|
on2 ? G.prompt : " ",
|
|
36251
37285
|
" "
|
|
36252
37286
|
] }),
|
|
36253
|
-
/* @__PURE__ */ (0,
|
|
36254
|
-
/* @__PURE__ */ (0,
|
|
36255
|
-
/* @__PURE__ */ (0,
|
|
36256
|
-
/* @__PURE__ */ (0,
|
|
37287
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Mark, { status: st, testing: testing.has(m.key) }),
|
|
37288
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { children: " " }),
|
|
37289
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { bold: on2, color: dead ? C.faint : on2 ? C.text : void 0, children: pad(m.name, wName) }),
|
|
37290
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36257
37291
|
" ",
|
|
36258
37292
|
pad(field.text || !provider ? m.key : m.id, wId)
|
|
36259
37293
|
] }),
|
|
36260
|
-
/* @__PURE__ */ (0,
|
|
37294
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.muted, children: [
|
|
36261
37295
|
" ",
|
|
36262
37296
|
padStart(fmtContext(m.context), wCtx)
|
|
36263
37297
|
] }),
|
|
36264
|
-
/* @__PURE__ */ (0,
|
|
37298
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: m.costIn === 0 && m.costOut === 0 ? C.ok : C.muted, children: [
|
|
36265
37299
|
" ",
|
|
36266
37300
|
padStart(fmtPrice(m, kindOf(m.providerID)), wPrice)
|
|
36267
37301
|
] }),
|
|
36268
|
-
note ? /* @__PURE__ */ (0,
|
|
37302
|
+
note ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: m.key === p.current ? C.accent2 : dead ? C.faint : C.warn, children: [
|
|
36269
37303
|
" ",
|
|
36270
37304
|
note
|
|
36271
37305
|
] }) : null
|
|
36272
37306
|
] }, m.key);
|
|
36273
37307
|
}),
|
|
36274
|
-
below ? /* @__PURE__ */ (0,
|
|
37308
|
+
below ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { color: C.faint, children: [
|
|
36275
37309
|
" ",
|
|
36276
37310
|
G.down,
|
|
36277
37311
|
" ",
|
|
@@ -36279,13 +37313,13 @@ function ModelPicker(p) {
|
|
|
36279
37313
|
" more"
|
|
36280
37314
|
] }) : null
|
|
36281
37315
|
] }),
|
|
36282
|
-
chosen ? /* @__PURE__ */ (0,
|
|
36283
|
-
/* @__PURE__ */ (0,
|
|
36284
|
-
efforts.length > 1 ? efforts.map((e, i) => /* @__PURE__ */ (0,
|
|
37316
|
+
chosen ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37317
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "effort " }),
|
|
37318
|
+
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: [
|
|
36285
37319
|
i === effortAt ? `\u2039 ${e} \u203A` : e,
|
|
36286
37320
|
i < efforts.length - 1 ? " " : ""
|
|
36287
|
-
] }, e)) : /* @__PURE__ */ (0,
|
|
36288
|
-
/* @__PURE__ */ (0,
|
|
37321
|
+
] }, e)) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: "fixed for this model" }),
|
|
37322
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { color: C.faint, children: " ctx \xB7 in/out per 1M tokens ($, or cr = Latent credits)" })
|
|
36289
37323
|
] }) }) : null
|
|
36290
37324
|
]
|
|
36291
37325
|
}
|
|
@@ -36294,8 +37328,8 @@ function ModelPicker(p) {
|
|
|
36294
37328
|
|
|
36295
37329
|
// src/ui/panels/ProviderPanel.tsx
|
|
36296
37330
|
var import_react24 = __toESM(require_react(), 1);
|
|
36297
|
-
var
|
|
36298
|
-
var usable = (i) => i.methods.filter((m) => m.type === "key" || m.type === "oauth");
|
|
37331
|
+
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
|
|
37332
|
+
var usable = (i) => i.methods.filter((m) => m.type === "key" || m.type === "oauth" || m.type === "external");
|
|
36299
37333
|
var needsForm = (m) => "form" in m && Array.isArray(m.form) && m.form.some((f) => !f.hidden && f.required);
|
|
36300
37334
|
var methodLabel = (m) => m.type === "key" ? m.label || "API key" : m.label;
|
|
36301
37335
|
function errText(e) {
|
|
@@ -36309,7 +37343,7 @@ function ProviderPanel(p) {
|
|
|
36309
37343
|
const [error, setError] = (0, import_react24.useState)("");
|
|
36310
37344
|
(0, import_react24.useEffect)(() => {
|
|
36311
37345
|
let live = true;
|
|
36312
|
-
p.engine.integrations().then((
|
|
37346
|
+
p.engine.integrations().then((list2) => live && setIntegrations(list2)).catch((e) => live && setError(errText(e)));
|
|
36313
37347
|
return () => {
|
|
36314
37348
|
live = false;
|
|
36315
37349
|
};
|
|
@@ -36327,21 +37361,29 @@ function ProviderPanel(p) {
|
|
|
36327
37361
|
};
|
|
36328
37362
|
const startMethod = (integration, method) => {
|
|
36329
37363
|
if (method.type === "key") return go({ v: "key", integration });
|
|
37364
|
+
if (method.type === "external") {
|
|
37365
|
+
go({ v: "connecting", integration });
|
|
37366
|
+
p.engine.connectExternal(integration.id, method.id).then(() => finish(integration)).catch((e) => {
|
|
37367
|
+
setView({ v: "pick" });
|
|
37368
|
+
setError(`${errText(e)}${integration.id === "claude-agent" ? " \u2014 install Claude Code and run: claude auth login" : ""}`);
|
|
37369
|
+
});
|
|
37370
|
+
return;
|
|
37371
|
+
}
|
|
36330
37372
|
if (needsForm(method)) {
|
|
36331
37373
|
setError(`${method.label} needs extra details. Quit and run: latentcode auth login`);
|
|
36332
37374
|
return;
|
|
36333
37375
|
}
|
|
36334
37376
|
go({ v: "oauth", integration, method });
|
|
36335
37377
|
};
|
|
36336
|
-
const finish = async (integration) => {
|
|
37378
|
+
const finish = async (integration, note) => {
|
|
36337
37379
|
const next = await p.onConnected(integration.name);
|
|
36338
37380
|
const models = next.providers.filter((x) => x.integrationID === integration.id).reduce((n, x) => n + x.models, 0);
|
|
36339
|
-
go({ v: "done", name: integration.name, models });
|
|
37381
|
+
go({ v: "done", name: integration.name, models, note });
|
|
36340
37382
|
};
|
|
36341
37383
|
const common = { width: p.width, color: C.accent };
|
|
36342
37384
|
switch (view.v) {
|
|
36343
37385
|
case "list":
|
|
36344
|
-
return /* @__PURE__ */ (0,
|
|
37386
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36345
37387
|
ProviderList,
|
|
36346
37388
|
{
|
|
36347
37389
|
...p,
|
|
@@ -36350,7 +37392,7 @@ function ProviderPanel(p) {
|
|
|
36350
37392
|
}
|
|
36351
37393
|
);
|
|
36352
37394
|
case "pick":
|
|
36353
|
-
return /* @__PURE__ */ (0,
|
|
37395
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36354
37396
|
IntegrationPicker,
|
|
36355
37397
|
{
|
|
36356
37398
|
...common,
|
|
@@ -36360,11 +37402,29 @@ function ProviderPanel(p) {
|
|
|
36360
37402
|
query: p.query,
|
|
36361
37403
|
error,
|
|
36362
37404
|
onPick: choose,
|
|
37405
|
+
onCustom: () => go({ v: "custom" }),
|
|
36363
37406
|
onBack: () => p.connect ? p.onClose() : go({ v: "list" })
|
|
36364
37407
|
}
|
|
36365
37408
|
);
|
|
37409
|
+
case "connecting":
|
|
37410
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Panel, { title: `Connect ${view.integration.name}`, width: p.width, color: C.accent, footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["", "this can take a few seconds"]] }), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37411
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
37412
|
+
" ",
|
|
37413
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Checking the login on this machine and loading its models\u2026" })
|
|
37414
|
+
] }) }) });
|
|
37415
|
+
case "custom":
|
|
37416
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
37417
|
+
CustomProviderForm,
|
|
37418
|
+
{
|
|
37419
|
+
...common,
|
|
37420
|
+
engine: p.engine,
|
|
37421
|
+
taken: /* @__PURE__ */ new Set([...(integrations ?? []).map((i) => i.id), ...p.catalog.providers.map((x) => x.id)]),
|
|
37422
|
+
onDone: (integration, note) => finish(integration, note),
|
|
37423
|
+
onBack: () => go({ v: "pick" })
|
|
37424
|
+
}
|
|
37425
|
+
);
|
|
36366
37426
|
case "method":
|
|
36367
|
-
return /* @__PURE__ */ (0,
|
|
37427
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36368
37428
|
MethodPicker,
|
|
36369
37429
|
{
|
|
36370
37430
|
...common,
|
|
@@ -36375,7 +37435,7 @@ function ProviderPanel(p) {
|
|
|
36375
37435
|
}
|
|
36376
37436
|
);
|
|
36377
37437
|
case "key":
|
|
36378
|
-
return /* @__PURE__ */ (0,
|
|
37438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36379
37439
|
KeyEntry,
|
|
36380
37440
|
{
|
|
36381
37441
|
...common,
|
|
@@ -36386,7 +37446,7 @@ function ProviderPanel(p) {
|
|
|
36386
37446
|
}
|
|
36387
37447
|
);
|
|
36388
37448
|
case "oauth":
|
|
36389
|
-
return /* @__PURE__ */ (0,
|
|
37449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36390
37450
|
OAuthFlow,
|
|
36391
37451
|
{
|
|
36392
37452
|
...common,
|
|
@@ -36398,7 +37458,7 @@ function ProviderPanel(p) {
|
|
|
36398
37458
|
}
|
|
36399
37459
|
);
|
|
36400
37460
|
case "done":
|
|
36401
|
-
return /* @__PURE__ */ (0,
|
|
37461
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Done, { ...common, name: view.name, models: view.models, note: view.note, onClose: p.onClose, onModels: () => p.onBrowse("") });
|
|
36402
37462
|
}
|
|
36403
37463
|
}
|
|
36404
37464
|
function ProviderList(p) {
|
|
@@ -36419,39 +37479,39 @@ function ProviderList(p) {
|
|
|
36419
37479
|
const inner = p.width - 4;
|
|
36420
37480
|
const wName = Math.min(24, Math.max(12, ...items.map((x) => x.name.length)) + 1);
|
|
36421
37481
|
const wVia = Math.min(26, Math.max(10, ...items.map((x) => x.via.length)) + 1);
|
|
36422
|
-
return /* @__PURE__ */ (0,
|
|
37482
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36423
37483
|
Panel,
|
|
36424
37484
|
{
|
|
36425
37485
|
title: "Providers",
|
|
36426
37486
|
right: `${items.length} connected \xB7 ${p.catalog.models.length} models`,
|
|
36427
37487
|
width: p.width,
|
|
36428
37488
|
color: C.accent,
|
|
36429
|
-
footer: /* @__PURE__ */ (0,
|
|
37489
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "browse models"], ["c", "connect a provider"], ["esc", "close"]] }),
|
|
36430
37490
|
children: [
|
|
36431
|
-
/* @__PURE__ */ (0,
|
|
37491
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
36432
37492
|
items.map((prov, i) => {
|
|
36433
37493
|
const ok = p.catalog.models.filter((m) => m.providerID === prov.id && p.status(m.key) === "ok").length;
|
|
36434
37494
|
const dot = prov.kind === "builtin" ? C.faint : C.ok;
|
|
36435
|
-
return /* @__PURE__ */ (0,
|
|
36436
|
-
/* @__PURE__ */ (0,
|
|
37495
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37496
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36437
37497
|
i === sel ? G.prompt : " ",
|
|
36438
37498
|
" "
|
|
36439
37499
|
] }),
|
|
36440
|
-
/* @__PURE__ */ (0,
|
|
37500
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: dot, children: [
|
|
36441
37501
|
G.dot,
|
|
36442
37502
|
" "
|
|
36443
37503
|
] }),
|
|
36444
|
-
/* @__PURE__ */ (0,
|
|
36445
|
-
/* @__PURE__ */ (0,
|
|
37504
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: i === sel, children: pad(prov.name, wName) }),
|
|
37505
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36446
37506
|
" ",
|
|
36447
37507
|
pad(prov.via, wVia)
|
|
36448
37508
|
] }),
|
|
36449
|
-
/* @__PURE__ */ (0,
|
|
37509
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36450
37510
|
" ",
|
|
36451
37511
|
String(prov.models).padStart(3),
|
|
36452
37512
|
" models"
|
|
36453
37513
|
] }),
|
|
36454
|
-
ok ? /* @__PURE__ */ (0,
|
|
37514
|
+
ok ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
36455
37515
|
" ",
|
|
36456
37516
|
G.ok,
|
|
36457
37517
|
" ",
|
|
@@ -36460,16 +37520,16 @@ function ProviderList(p) {
|
|
|
36460
37520
|
] }) : null
|
|
36461
37521
|
] }, prov.id);
|
|
36462
37522
|
}),
|
|
36463
|
-
/* @__PURE__ */ (0,
|
|
36464
|
-
/* @__PURE__ */ (0,
|
|
37523
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37524
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36465
37525
|
sel === items.length ? G.prompt : " ",
|
|
36466
37526
|
" "
|
|
36467
37527
|
] }),
|
|
36468
|
-
/* @__PURE__ */ (0,
|
|
37528
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, bold: sel === items.length, children: "+ Connect a provider\u2026" })
|
|
36469
37529
|
] })
|
|
36470
37530
|
] }),
|
|
36471
|
-
/* @__PURE__ */ (0,
|
|
36472
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37531
|
+
/* @__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) }) }),
|
|
37532
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36473
37533
|
]
|
|
36474
37534
|
}
|
|
36475
37535
|
);
|
|
@@ -36487,83 +37547,92 @@ function IntegrationPicker(p) {
|
|
|
36487
37547
|
return true;
|
|
36488
37548
|
}
|
|
36489
37549
|
if (key.upArrow) return void setSel((s2) => Math.max(0, s2 - 1)), true;
|
|
36490
|
-
if (key.downArrow) return void setSel((s2) => Math.min(
|
|
37550
|
+
if (key.downArrow) return void setSel((s2) => Math.min(list2.length, s2 + 1)), true;
|
|
36491
37551
|
if (key.return) {
|
|
36492
|
-
|
|
37552
|
+
if (selected === list2.length) return p.onCustom(), true;
|
|
37553
|
+
const it = list2[selected];
|
|
36493
37554
|
if (it) p.onPick(it);
|
|
36494
37555
|
return true;
|
|
36495
37556
|
}
|
|
36496
37557
|
return false;
|
|
36497
37558
|
}
|
|
36498
37559
|
});
|
|
36499
|
-
const
|
|
36500
|
-
const selected = Math.min(sel,
|
|
36501
|
-
const visible = Math.max(5, Math.min(11, p.rows -
|
|
36502
|
-
const win = windowAround(
|
|
36503
|
-
return /* @__PURE__ */ (0,
|
|
37560
|
+
const list2 = (0, import_react24.useMemo)(() => searchIntegrations(p.integrations ?? [], field.text), [p.integrations, field.text]);
|
|
37561
|
+
const selected = Math.min(sel, list2.length);
|
|
37562
|
+
const visible = Math.max(5, Math.min(11, p.rows - 15));
|
|
37563
|
+
const win = windowAround(list2.length, Math.min(selected, Math.max(0, list2.length - 1)), visible);
|
|
37564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36504
37565
|
Panel,
|
|
36505
37566
|
{
|
|
36506
37567
|
title: "Connect a provider",
|
|
36507
|
-
right: p.integrations ? `${
|
|
37568
|
+
right: p.integrations ? `${list2.length} available` : "",
|
|
36508
37569
|
width: p.width,
|
|
36509
37570
|
color: p.color,
|
|
36510
|
-
footer: /* @__PURE__ */ (0,
|
|
37571
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "choose"], ["esc", field.text ? "clear" : "back"]] }),
|
|
36511
37572
|
children: [
|
|
36512
|
-
/* @__PURE__ */ (0,
|
|
36513
|
-
/* @__PURE__ */ (0,
|
|
37573
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37574
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36514
37575
|
G.search,
|
|
36515
37576
|
" "
|
|
36516
37577
|
] }),
|
|
36517
|
-
/* @__PURE__ */ (0,
|
|
37578
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, placeholder: "search \u2014 Anthropic, OpenRouter, Google\u2026" })
|
|
36518
37579
|
] }),
|
|
36519
|
-
/* @__PURE__ */ (0,
|
|
36520
|
-
!p.integrations && !p.error ? /* @__PURE__ */ (0,
|
|
36521
|
-
/* @__PURE__ */ (0,
|
|
37580
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37581
|
+
!p.integrations && !p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37582
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36522
37583
|
" ",
|
|
36523
|
-
/* @__PURE__ */ (0,
|
|
37584
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Loading providers\u2026" })
|
|
36524
37585
|
] }) : null,
|
|
36525
|
-
p.integrations && !
|
|
37586
|
+
p.integrations && !list2.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36526
37587
|
" Nothing matches \u201C",
|
|
36527
37588
|
field.text,
|
|
36528
37589
|
"\u201D."
|
|
36529
37590
|
] }) : null,
|
|
36530
|
-
win.start > 0 ? /* @__PURE__ */ (0,
|
|
37591
|
+
win.start > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36531
37592
|
" ",
|
|
36532
37593
|
G.up,
|
|
36533
37594
|
" ",
|
|
36534
37595
|
win.start,
|
|
36535
37596
|
" more"
|
|
36536
37597
|
] }) : null,
|
|
36537
|
-
|
|
37598
|
+
list2.slice(win.start, win.end).map((it, i) => {
|
|
36538
37599
|
const on2 = win.start + i === selected;
|
|
36539
37600
|
const labels = usable(it).map((m) => m.type === "key" ? "API key" : m.label);
|
|
36540
37601
|
const methods = labels.slice(0, 2).join(" \xB7 ") + (labels.length > 2 ? ` +${labels.length - 2}` : "");
|
|
36541
|
-
return /* @__PURE__ */ (0,
|
|
36542
|
-
/* @__PURE__ */ (0,
|
|
37602
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37603
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36543
37604
|
on2 ? G.prompt : " ",
|
|
36544
37605
|
" "
|
|
36545
37606
|
] }),
|
|
36546
|
-
/* @__PURE__ */ (0,
|
|
36547
|
-
/* @__PURE__ */ (0,
|
|
37607
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: on2, children: pad(it.name, 26) }),
|
|
37608
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36548
37609
|
" ",
|
|
36549
37610
|
methods
|
|
36550
37611
|
] }),
|
|
36551
|
-
p.connected.has(it.id) ? /* @__PURE__ */ (0,
|
|
37612
|
+
p.connected.has(it.id) ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
36552
37613
|
" ",
|
|
36553
37614
|
G.ok,
|
|
36554
37615
|
" connected"
|
|
36555
37616
|
] }) : null
|
|
36556
37617
|
] }, it.id);
|
|
36557
37618
|
}),
|
|
36558
|
-
win.end <
|
|
37619
|
+
win.end < list2.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36559
37620
|
" ",
|
|
36560
37621
|
G.down,
|
|
36561
37622
|
" ",
|
|
36562
|
-
|
|
37623
|
+
list2.length - win.end,
|
|
36563
37624
|
" more"
|
|
37625
|
+
] }) : null,
|
|
37626
|
+
p.integrations ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37627
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
37628
|
+
selected === list2.length ? G.prompt : " ",
|
|
37629
|
+
" "
|
|
37630
|
+
] }),
|
|
37631
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, bold: selected === list2.length, children: pad("+ Custom provider\u2026", 26) }),
|
|
37632
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: " any OpenAI- or Anthropic-compatible endpoint" })
|
|
36564
37633
|
] }) : null
|
|
36565
37634
|
] }),
|
|
36566
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37635
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36567
37636
|
]
|
|
36568
37637
|
}
|
|
36569
37638
|
);
|
|
@@ -36579,31 +37648,31 @@ function MethodPicker(p) {
|
|
|
36579
37648
|
});
|
|
36580
37649
|
const wLabel = Math.min(40, Math.max(...methods.map((m) => methodLabel(m).length)) + 2);
|
|
36581
37650
|
const env3 = p.integration.methods.find((m) => m.type === "env");
|
|
36582
|
-
return /* @__PURE__ */ (0,
|
|
37651
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36583
37652
|
Panel,
|
|
36584
37653
|
{
|
|
36585
37654
|
title: `Connect ${p.integration.name}`,
|
|
36586
37655
|
width: p.width,
|
|
36587
37656
|
color: p.color,
|
|
36588
|
-
footer: /* @__PURE__ */ (0,
|
|
37657
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "continue"], ["esc", "back"]] }),
|
|
36589
37658
|
children: [
|
|
36590
|
-
/* @__PURE__ */ (0,
|
|
36591
|
-
/* @__PURE__ */ (0,
|
|
36592
|
-
methods.map((m, i) => /* @__PURE__ */ (0,
|
|
36593
|
-
/* @__PURE__ */ (0,
|
|
37659
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37660
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "How do you want to connect?" }),
|
|
37661
|
+
methods.map((m, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37662
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36594
37663
|
i === sel ? G.prompt : " ",
|
|
36595
37664
|
" "
|
|
36596
37665
|
] }),
|
|
36597
|
-
/* @__PURE__ */ (0,
|
|
36598
|
-
/* @__PURE__ */ (0,
|
|
37666
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: i === sel, children: pad(methodLabel(m), wLabel) }),
|
|
37667
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, children: m.type === "oauth" ? "opens your browser" : m.type === "external" ? "uses the login on this machine" : "paste a key" })
|
|
36599
37668
|
] }, m.type + ("id" in m ? m.id : "")))
|
|
36600
37669
|
] }),
|
|
36601
|
-
env3 ? /* @__PURE__ */ (0,
|
|
37670
|
+
env3 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.faint, children: [
|
|
36602
37671
|
"Or set ",
|
|
36603
37672
|
env3.names[0],
|
|
36604
37673
|
" in your shell before starting LatentCode."
|
|
36605
37674
|
] }) }) : null,
|
|
36606
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37675
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: p.error }) : null
|
|
36607
37676
|
]
|
|
36608
37677
|
}
|
|
36609
37678
|
);
|
|
@@ -36629,33 +37698,33 @@ function KeyEntry(p) {
|
|
|
36629
37698
|
return false;
|
|
36630
37699
|
}
|
|
36631
37700
|
});
|
|
36632
|
-
return /* @__PURE__ */ (0,
|
|
37701
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36633
37702
|
Panel,
|
|
36634
37703
|
{
|
|
36635
37704
|
title: `Connect ${p.integration.name}`,
|
|
36636
37705
|
right: "API key",
|
|
36637
37706
|
width: p.width,
|
|
36638
37707
|
color: p.color,
|
|
36639
|
-
footer: /* @__PURE__ */ (0,
|
|
36640
|
-
children: /* @__PURE__ */ (0,
|
|
36641
|
-
/* @__PURE__ */ (0,
|
|
37708
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["enter", "save"], ["esc", "back"]] }),
|
|
37709
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37710
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.muted, children: [
|
|
36642
37711
|
"Paste your ",
|
|
36643
37712
|
p.integration.name,
|
|
36644
37713
|
" API key."
|
|
36645
37714
|
] }),
|
|
36646
|
-
/* @__PURE__ */ (0,
|
|
36647
|
-
/* @__PURE__ */ (0,
|
|
37715
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37716
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36648
37717
|
G.key,
|
|
36649
37718
|
" "
|
|
36650
37719
|
] }),
|
|
36651
|
-
/* @__PURE__ */ (0,
|
|
37720
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, mask: true, placeholder: "paste the key here" })
|
|
36652
37721
|
] }),
|
|
36653
|
-
/* @__PURE__ */ (0,
|
|
36654
|
-
/* @__PURE__ */ (0,
|
|
37722
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37723
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36655
37724
|
" ",
|
|
36656
|
-
/* @__PURE__ */ (0,
|
|
36657
|
-
] }) : /* @__PURE__ */ (0,
|
|
36658
|
-
error ? /* @__PURE__ */ (0,
|
|
37725
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Saving\u2026" })
|
|
37726
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.faint, children: "Stored by the local engine on this machine. Never sent to Latent." }) }),
|
|
37727
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: error }) : null
|
|
36659
37728
|
] })
|
|
36660
37729
|
}
|
|
36661
37730
|
);
|
|
@@ -36722,37 +37791,200 @@ function OAuthFlow(p) {
|
|
|
36722
37791
|
return false;
|
|
36723
37792
|
}
|
|
36724
37793
|
});
|
|
36725
|
-
return /* @__PURE__ */ (0,
|
|
37794
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
36726
37795
|
Panel,
|
|
36727
37796
|
{
|
|
36728
37797
|
title: `Connect ${p.integration.name}`,
|
|
36729
37798
|
right: p.method.label,
|
|
36730
37799
|
width: p.width,
|
|
36731
37800
|
color: p.color,
|
|
36732
|
-
footer: /* @__PURE__ */ (0,
|
|
36733
|
-
children: /* @__PURE__ */ (0,
|
|
36734
|
-
!attempt && !error ? /* @__PURE__ */ (0,
|
|
36735
|
-
/* @__PURE__ */ (0,
|
|
37801
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: codeMode ? [["enter", "submit code"], ["esc", "cancel"]] : [["esc", "cancel"]] }),
|
|
37802
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37803
|
+
!attempt && !error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37804
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36736
37805
|
" ",
|
|
36737
|
-
/* @__PURE__ */ (0,
|
|
37806
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Starting sign-in\u2026" })
|
|
36738
37807
|
] }) : null,
|
|
36739
|
-
attempt ? /* @__PURE__ */ (0,
|
|
36740
|
-
/* @__PURE__ */ (0,
|
|
36741
|
-
/* @__PURE__ */ (0,
|
|
36742
|
-
attempt.instructions ? /* @__PURE__ */ (0,
|
|
36743
|
-
/* @__PURE__ */ (0,
|
|
36744
|
-
/* @__PURE__ */ (0,
|
|
37808
|
+
attempt ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
37809
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Your browser should open. If it does not, open this link:" }),
|
|
37810
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.accent2, wrap: "wrap", children: attempt.url }),
|
|
37811
|
+
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,
|
|
37812
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: codeMode ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37813
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
36745
37814
|
G.key,
|
|
36746
37815
|
" "
|
|
36747
37816
|
] }),
|
|
36748
|
-
/* @__PURE__ */ (0,
|
|
36749
|
-
] }) : error ? null : /* @__PURE__ */ (0,
|
|
36750
|
-
/* @__PURE__ */ (0,
|
|
37817
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, placeholder: "paste the code from the browser" })
|
|
37818
|
+
] }) : error ? null : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37819
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
36751
37820
|
" ",
|
|
36752
|
-
/* @__PURE__ */ (0,
|
|
37821
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Waiting for you to finish in the browser\u2026" })
|
|
36753
37822
|
] }) })
|
|
36754
37823
|
] }) : null,
|
|
36755
|
-
error ? /* @__PURE__ */ (0,
|
|
37824
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, children: error }) : null
|
|
37825
|
+
] })
|
|
37826
|
+
}
|
|
37827
|
+
);
|
|
37828
|
+
}
|
|
37829
|
+
var KINDS = ["openai", "anthropic"];
|
|
37830
|
+
function CustomProviderForm(p) {
|
|
37831
|
+
const [step, setStep] = (0, import_react24.useState)("name");
|
|
37832
|
+
const [name, setName] = (0, import_react24.useState)("");
|
|
37833
|
+
const [kind, setKind] = (0, import_react24.useState)("openai");
|
|
37834
|
+
const [url, setUrl] = (0, import_react24.useState)("");
|
|
37835
|
+
const [key, setKey] = (0, import_react24.useState)("");
|
|
37836
|
+
const [busy, setBusy] = (0, import_react24.useState)("");
|
|
37837
|
+
const [error, setError] = (0, import_react24.useState)("");
|
|
37838
|
+
const order = ["name", "kind", "url", "key", "models"];
|
|
37839
|
+
const back = () => {
|
|
37840
|
+
setError("");
|
|
37841
|
+
const i = order.indexOf(step);
|
|
37842
|
+
if (i <= 0) return p.onBack();
|
|
37843
|
+
const prev = order[i - 1];
|
|
37844
|
+
setStep(prev);
|
|
37845
|
+
field.set(prev === "name" ? name : prev === "url" ? url : prev === "key" ? key : "");
|
|
37846
|
+
};
|
|
37847
|
+
const next = (to, initial = "") => {
|
|
37848
|
+
setError("");
|
|
37849
|
+
setStep(to);
|
|
37850
|
+
field.set(initial);
|
|
37851
|
+
};
|
|
37852
|
+
const save2 = async (modelText) => {
|
|
37853
|
+
setError("");
|
|
37854
|
+
try {
|
|
37855
|
+
let models = parseModelList(modelText);
|
|
37856
|
+
if (!models.length) {
|
|
37857
|
+
setBusy(`Asking ${url}/models\u2026`);
|
|
37858
|
+
try {
|
|
37859
|
+
models = await discoverModels(kind, url, key);
|
|
37860
|
+
} catch (e) {
|
|
37861
|
+
throw new Error(`Could not list the models (${errText(e)}). Type the model ids, separated by commas.`);
|
|
37862
|
+
}
|
|
37863
|
+
if (!models.length) throw new Error("The endpoint lists no models. Type the model ids, separated by commas.");
|
|
37864
|
+
}
|
|
37865
|
+
setBusy("Saving to the engine config\u2026");
|
|
37866
|
+
const dir = await p.engine.configDir() ?? defaultConfigDir();
|
|
37867
|
+
const file = configFileIn(dir);
|
|
37868
|
+
const id = providerIdFor(name, p.taken, configuredProviderIds(readConfigText(file)));
|
|
37869
|
+
const written = writeProviderConfig(file, id, { name, kind, baseURL: url, models });
|
|
37870
|
+
setBusy("Reloading the engine\u2026");
|
|
37871
|
+
await p.engine.reloadConfig();
|
|
37872
|
+
const integration = await p.engine.waitForIntegration(id);
|
|
37873
|
+
if (key) {
|
|
37874
|
+
setBusy("Saving the key\u2026");
|
|
37875
|
+
await p.engine.connectKey(id, key);
|
|
37876
|
+
}
|
|
37877
|
+
const note = `Added as "${id}" (${KIND_LABEL[kind]}, ${models.length} model${models.length === 1 ? "" : "s"}) in ${written.file}.` + (written.backup ? ` Comments in that file could not be kept; the original is at ${written.backup}.` : "") + ` Use it with --model ${id}/${models[0]}.`;
|
|
37878
|
+
await p.onDone(integration, note);
|
|
37879
|
+
} catch (e) {
|
|
37880
|
+
setError(errText(e));
|
|
37881
|
+
setBusy("");
|
|
37882
|
+
}
|
|
37883
|
+
};
|
|
37884
|
+
const field = useLineField({
|
|
37885
|
+
active: !busy && step !== "kind",
|
|
37886
|
+
onChange: () => setError(""),
|
|
37887
|
+
onKey: (_ch, k) => {
|
|
37888
|
+
if (k.escape) return back(), true;
|
|
37889
|
+
if (!k.return) return false;
|
|
37890
|
+
const text = field.text.trim();
|
|
37891
|
+
if (step === "name") {
|
|
37892
|
+
if (!text) return setError("Give it a name, e.g. My Gateway."), true;
|
|
37893
|
+
setName(text);
|
|
37894
|
+
next("kind");
|
|
37895
|
+
} else if (step === "url") {
|
|
37896
|
+
try {
|
|
37897
|
+
const u = normalizeBaseURL(text);
|
|
37898
|
+
setUrl(u);
|
|
37899
|
+
next("key", key);
|
|
37900
|
+
} catch (e) {
|
|
37901
|
+
setError(errText(e));
|
|
37902
|
+
}
|
|
37903
|
+
} else if (step === "key") {
|
|
37904
|
+
setKey(text);
|
|
37905
|
+
next("models");
|
|
37906
|
+
} else if (step === "models") {
|
|
37907
|
+
void save2(text);
|
|
37908
|
+
}
|
|
37909
|
+
return true;
|
|
37910
|
+
}
|
|
37911
|
+
});
|
|
37912
|
+
use_input_default(
|
|
37913
|
+
(_ch, k) => {
|
|
37914
|
+
if (k.escape) return back();
|
|
37915
|
+
if (k.upArrow || k.downArrow || k.tab) return setKind((x) => x === "openai" ? "anthropic" : "openai");
|
|
37916
|
+
if (k.return) next("url", url);
|
|
37917
|
+
},
|
|
37918
|
+
{ isActive: !busy && step === "kind" }
|
|
37919
|
+
);
|
|
37920
|
+
const done = (label2, value) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
37921
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
37922
|
+
G.ok,
|
|
37923
|
+
" "
|
|
37924
|
+
] }),
|
|
37925
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: pad(label2, 10) }),
|
|
37926
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { children: value })
|
|
37927
|
+
] });
|
|
37928
|
+
const at = order.indexOf(step);
|
|
37929
|
+
const prompt = {
|
|
37930
|
+
name: { label: "Name", hint: "What to call it in the model picker.", placeholder: "e.g. My Gateway" },
|
|
37931
|
+
url: {
|
|
37932
|
+
label: "Base URL",
|
|
37933
|
+
hint: kind === "openai" ? "The URL before /chat/completions \u2014 usually ends in /v1." : "The URL before /messages \u2014 usually ends in /v1.",
|
|
37934
|
+
placeholder: "https://api.example.com/v1"
|
|
37935
|
+
},
|
|
37936
|
+
key: { label: "API key", hint: "Leave empty if the endpoint needs no key (e.g. a local server).", placeholder: "paste the key, or enter to skip" },
|
|
37937
|
+
models: {
|
|
37938
|
+
label: "Models",
|
|
37939
|
+
hint: "Model ids, separated by commas. Leave empty to import every model from the endpoint's /models list.",
|
|
37940
|
+
placeholder: "e.g. gpt-4.1, claude-sonnet-4"
|
|
37941
|
+
}
|
|
37942
|
+
};
|
|
37943
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
37944
|
+
Panel,
|
|
37945
|
+
{
|
|
37946
|
+
title: "Custom provider",
|
|
37947
|
+
right: `step ${at + 1} of ${order.length}`,
|
|
37948
|
+
width: p.width,
|
|
37949
|
+
color: p.color,
|
|
37950
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
37951
|
+
Hints,
|
|
37952
|
+
{
|
|
37953
|
+
items: step === "kind" ? [["\u2191\u2193", "choose"], ["enter", "continue"], ["esc", "back"]] : [["enter", step === "models" ? "save" : "continue"], ["esc", "back"]]
|
|
37954
|
+
}
|
|
37955
|
+
),
|
|
37956
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
37957
|
+
at > 0 ? done("Name", name) : null,
|
|
37958
|
+
at > 1 ? done("Type", KIND_LABEL[kind]) : null,
|
|
37959
|
+
at > 2 ? done("Base URL", url) : null,
|
|
37960
|
+
at > 3 ? done("API key", key ? "\u2022".repeat(Math.min(key.length, 12)) : "none") : null,
|
|
37961
|
+
/* @__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: [
|
|
37962
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: "Which API does the endpoint speak?" }),
|
|
37963
|
+
KINDS.map((k) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37964
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
37965
|
+
k === kind ? G.prompt : " ",
|
|
37966
|
+
" "
|
|
37967
|
+
] }),
|
|
37968
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: k === kind, children: pad(KIND_LABEL[k], 24) }),
|
|
37969
|
+
/* @__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" })
|
|
37970
|
+
] }, k))
|
|
37971
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
37972
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: prompt[step].hint }),
|
|
37973
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Box_default, { marginTop: 1, children: [
|
|
37974
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.accent, children: [
|
|
37975
|
+
step === "key" ? G.key : G.prompt,
|
|
37976
|
+
" "
|
|
37977
|
+
] }),
|
|
37978
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: true, children: pad(prompt[step].label, 10) }),
|
|
37979
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FieldText, { state: field.state, mask: step === "key", placeholder: prompt[step].placeholder })
|
|
37980
|
+
] })
|
|
37981
|
+
] }) }),
|
|
37982
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: busy ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
37983
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Spinner, {}),
|
|
37984
|
+
" ",
|
|
37985
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.muted, children: busy })
|
|
37986
|
+
] }) : /* @__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." }) }),
|
|
37987
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: C.err, wrap: "wrap", children: error }) : null
|
|
36756
37988
|
] })
|
|
36757
37989
|
}
|
|
36758
37990
|
);
|
|
@@ -36762,21 +37994,24 @@ function Done(p) {
|
|
|
36762
37994
|
if (key.return) return p.onModels();
|
|
36763
37995
|
if (key.escape) p.onClose();
|
|
36764
37996
|
});
|
|
36765
|
-
return /* @__PURE__ */ (0,
|
|
37997
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
36766
37998
|
Panel,
|
|
36767
37999
|
{
|
|
36768
38000
|
title: "Connected",
|
|
36769
38001
|
width: p.width,
|
|
36770
38002
|
color: C.ok,
|
|
36771
|
-
footer: /* @__PURE__ */ (0,
|
|
36772
|
-
children:
|
|
36773
|
-
/* @__PURE__ */ (0,
|
|
36774
|
-
|
|
36775
|
-
|
|
36776
|
-
|
|
36777
|
-
|
|
36778
|
-
|
|
36779
|
-
|
|
38003
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hints, { items: [["enter", "pick a model"], ["esc", "close"]] }),
|
|
38004
|
+
children: [
|
|
38005
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { children: [
|
|
38006
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text, { color: C.ok, children: [
|
|
38007
|
+
G.ok,
|
|
38008
|
+
" "
|
|
38009
|
+
] }),
|
|
38010
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { bold: true, children: p.name }),
|
|
38011
|
+
/* @__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." })
|
|
38012
|
+
] }) }),
|
|
38013
|
+
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
|
|
38014
|
+
]
|
|
36780
38015
|
}
|
|
36781
38016
|
);
|
|
36782
38017
|
}
|
|
@@ -36886,6 +38121,25 @@ async function pollDeviceToken(appId, deviceCode, opts) {
|
|
|
36886
38121
|
}
|
|
36887
38122
|
throw new Error("Auth link timed out \u2014 run `latentcode login` again.");
|
|
36888
38123
|
}
|
|
38124
|
+
async function issueLoginKey(server, accessToken, deviceId2, fetchImpl = fetch) {
|
|
38125
|
+
let res;
|
|
38126
|
+
try {
|
|
38127
|
+
res = await fetchImpl(`${trimServer(server)}/auth/latent-key`, {
|
|
38128
|
+
method: "POST",
|
|
38129
|
+
headers: { "Content-Type": "application/json" },
|
|
38130
|
+
body: JSON.stringify({ access_token: accessToken, device_id: deviceId2 })
|
|
38131
|
+
});
|
|
38132
|
+
} catch {
|
|
38133
|
+
return null;
|
|
38134
|
+
}
|
|
38135
|
+
if ([404, 405, 503].includes(res.status)) return null;
|
|
38136
|
+
const body = await readJson(res);
|
|
38137
|
+
if (!res.ok) {
|
|
38138
|
+
throw new Error(typeof body.detail === "string" ? body.detail : `latent-key HTTP ${res.status}`);
|
|
38139
|
+
}
|
|
38140
|
+
if (!body.wallet || !body.privy_user_id || !body.key) return null;
|
|
38141
|
+
return { wallet: body.wallet, privy_user_id: body.privy_user_id, key: body.key, default_model: body.default_model ?? null };
|
|
38142
|
+
}
|
|
36889
38143
|
async function resolveSession(server, accessToken, fetchImpl = fetch) {
|
|
36890
38144
|
const res = await fetchImpl(`${trimServer(server)}/auth/session`, {
|
|
36891
38145
|
method: "POST",
|
|
@@ -36938,16 +38192,28 @@ You can still connect an address you control: latentcode login --wallet 0x\u2026
|
|
|
36938
38192
|
sleep: deps2.sleep,
|
|
36939
38193
|
now: deps2.now
|
|
36940
38194
|
});
|
|
36941
|
-
const
|
|
38195
|
+
const withKey = deps2.deviceId ? await issueLoginKey(deps2.server, tokens.access_token, deps2.deviceId(), deps2.fetchImpl) : null;
|
|
38196
|
+
const earner = withKey ?? await resolveSession(deps2.server, tokens.access_token, deps2.fetchImpl);
|
|
36942
38197
|
if (!WALLET_RE.test(earner.wallet)) throw new Error("The server returned an invalid wallet address.");
|
|
36943
38198
|
const prev = deps2.load().wallet;
|
|
36944
|
-
deps2.save({
|
|
38199
|
+
deps2.save({
|
|
38200
|
+
wallet: earner.wallet,
|
|
38201
|
+
privy_user_id: earner.privy_user_id,
|
|
38202
|
+
auth: "privy",
|
|
38203
|
+
...withKey ? { latent_key: withKey.key, latent_default_model: withKey.default_model ?? void 0 } : {}
|
|
38204
|
+
});
|
|
36945
38205
|
deps2.log(`Signed in. Earn mode pays into ${short(earner.wallet)}.`);
|
|
36946
|
-
|
|
38206
|
+
if (withKey) deps2.log("Latent provider ready: your earnings pay for model usage.");
|
|
38207
|
+
return {
|
|
38208
|
+
wallet: earner.wallet,
|
|
38209
|
+
method: "privy",
|
|
38210
|
+
replaced: prev && prev !== earner.wallet ? prev : void 0,
|
|
38211
|
+
latentKey: Boolean(withKey)
|
|
38212
|
+
};
|
|
36947
38213
|
}
|
|
36948
38214
|
|
|
36949
38215
|
// src/ui/panels/WalletPanel.tsx
|
|
36950
|
-
var
|
|
38216
|
+
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
|
36951
38217
|
var deps = (server, extra) => ({
|
|
36952
38218
|
server,
|
|
36953
38219
|
log: () => {
|
|
@@ -36955,6 +38221,7 @@ var deps = (server, extra) => ({
|
|
|
36955
38221
|
open: openUrl,
|
|
36956
38222
|
load: loadConfig,
|
|
36957
38223
|
save: (patch) => void saveConfig(patch),
|
|
38224
|
+
deviceId: deviceKeyId,
|
|
36958
38225
|
...extra
|
|
36959
38226
|
});
|
|
36960
38227
|
function WalletPanel(p) {
|
|
@@ -36965,13 +38232,13 @@ function WalletPanel(p) {
|
|
|
36965
38232
|
};
|
|
36966
38233
|
switch (view.v) {
|
|
36967
38234
|
case "menu":
|
|
36968
|
-
return /* @__PURE__ */ (0,
|
|
38235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Menu, { ...p, onPick: (v) => setView({ v }) });
|
|
36969
38236
|
case "link":
|
|
36970
|
-
return /* @__PURE__ */ (0,
|
|
38237
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AuthLink, { ...p, onDone: done, onBack: () => setView({ v: "menu" }) });
|
|
36971
38238
|
case "address":
|
|
36972
|
-
return /* @__PURE__ */ (0,
|
|
38239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Address, { ...p, onDone: done, onBack: () => setView({ v: "menu" }) });
|
|
36973
38240
|
case "done":
|
|
36974
|
-
return /* @__PURE__ */ (0,
|
|
38241
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Done2, { width: p.width, wallet: view.wallet, onClose: p.onClose });
|
|
36975
38242
|
}
|
|
36976
38243
|
}
|
|
36977
38244
|
function Menu(p) {
|
|
@@ -36985,23 +38252,23 @@ function Menu(p) {
|
|
|
36985
38252
|
if (key.upArrow || key.downArrow || key.tab) return setSel((s2) => (s2 + 1) % options.length);
|
|
36986
38253
|
if (key.return) p.onPick(options[sel].id);
|
|
36987
38254
|
});
|
|
36988
|
-
return /* @__PURE__ */ (0,
|
|
38255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
36989
38256
|
Panel,
|
|
36990
38257
|
{
|
|
36991
38258
|
title: "Wallet",
|
|
36992
38259
|
right: p.wallet ? `connected \xB7 ${shortWallet(p.wallet)}` : "not connected",
|
|
36993
38260
|
width: p.width,
|
|
36994
38261
|
color: C.earn,
|
|
36995
|
-
footer: /* @__PURE__ */ (0,
|
|
36996
|
-
children: /* @__PURE__ */ (0,
|
|
36997
|
-
/* @__PURE__ */ (0,
|
|
36998
|
-
/* @__PURE__ */ (0,
|
|
36999
|
-
/* @__PURE__ */ (0,
|
|
38262
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["enter", "continue"], ["esc", "close"]] }),
|
|
38263
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38264
|
+
/* @__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:" }),
|
|
38265
|
+
/* @__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: [
|
|
38266
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37000
38267
|
i === sel ? G.prompt : " ",
|
|
37001
38268
|
" "
|
|
37002
38269
|
] }),
|
|
37003
|
-
/* @__PURE__ */ (0,
|
|
37004
|
-
/* @__PURE__ */ (0,
|
|
38270
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: i === sel, children: o.label.padEnd(27) }),
|
|
38271
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.faint, children: o.hint })
|
|
37005
38272
|
] }, o.id)) })
|
|
37006
38273
|
] })
|
|
37007
38274
|
}
|
|
@@ -37030,34 +38297,34 @@ function AuthLink(p) {
|
|
|
37030
38297
|
if (key.escape) p.onBack();
|
|
37031
38298
|
if (key.return && link2) openUrl(link2.url);
|
|
37032
38299
|
});
|
|
37033
|
-
return /* @__PURE__ */ (0,
|
|
38300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
37034
38301
|
Panel,
|
|
37035
38302
|
{
|
|
37036
38303
|
title: "Sign in",
|
|
37037
38304
|
right: "Latent wallet",
|
|
37038
38305
|
width: p.width,
|
|
37039
38306
|
color: C.earn,
|
|
37040
|
-
footer: /* @__PURE__ */ (0,
|
|
37041
|
-
children: /* @__PURE__ */ (0,
|
|
37042
|
-
!link2 && !error ? /* @__PURE__ */ (0,
|
|
37043
|
-
/* @__PURE__ */ (0,
|
|
38307
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "open the link again"], ["esc", "cancel"]] }),
|
|
38308
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38309
|
+
!link2 && !error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
38310
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Spinner, { color: C.earn }),
|
|
37044
38311
|
" ",
|
|
37045
|
-
/* @__PURE__ */ (0,
|
|
38312
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Preparing your sign-in link\u2026" })
|
|
37046
38313
|
] }) : null,
|
|
37047
|
-
link2 ? /* @__PURE__ */ (0,
|
|
37048
|
-
/* @__PURE__ */ (0,
|
|
37049
|
-
/* @__PURE__ */ (0,
|
|
37050
|
-
/* @__PURE__ */ (0,
|
|
37051
|
-
/* @__PURE__ */ (0,
|
|
37052
|
-
/* @__PURE__ */ (0,
|
|
38314
|
+
link2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
38315
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Your browser should open. If it does not, open:" }),
|
|
38316
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.accent2, wrap: "wrap", children: link2.url }),
|
|
38317
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
38318
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Code " }),
|
|
38319
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: true, color: C.earn, children: link2.code })
|
|
37053
38320
|
] }) }),
|
|
37054
|
-
error ? null : /* @__PURE__ */ (0,
|
|
37055
|
-
/* @__PURE__ */ (0,
|
|
38321
|
+
error ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { children: [
|
|
38322
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Spinner, { color: C.earn }),
|
|
37056
38323
|
" ",
|
|
37057
|
-
/* @__PURE__ */ (0,
|
|
38324
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: "Waiting for you to finish in the browser\u2026" })
|
|
37058
38325
|
] }) })
|
|
37059
38326
|
] }) : null,
|
|
37060
|
-
error ? /* @__PURE__ */ (0,
|
|
38327
|
+
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
|
|
37061
38328
|
] })
|
|
37062
38329
|
}
|
|
37063
38330
|
);
|
|
@@ -37080,23 +38347,23 @@ function Address(p) {
|
|
|
37080
38347
|
return false;
|
|
37081
38348
|
}
|
|
37082
38349
|
});
|
|
37083
|
-
return /* @__PURE__ */ (0,
|
|
38350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
37084
38351
|
Panel,
|
|
37085
38352
|
{
|
|
37086
38353
|
title: "Wallet address",
|
|
37087
38354
|
width: p.width,
|
|
37088
38355
|
color: C.earn,
|
|
37089
|
-
footer: /* @__PURE__ */ (0,
|
|
37090
|
-
children: /* @__PURE__ */ (0,
|
|
37091
|
-
/* @__PURE__ */ (0,
|
|
37092
|
-
/* @__PURE__ */ (0,
|
|
37093
|
-
/* @__PURE__ */ (0,
|
|
38356
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hints, { items: [["enter", "save"], ["esc", "back"]] }),
|
|
38357
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38358
|
+
/* @__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." }),
|
|
38359
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Box_default, { marginTop: 1, children: [
|
|
38360
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37094
38361
|
G.earn,
|
|
37095
38362
|
" "
|
|
37096
38363
|
] }),
|
|
37097
|
-
/* @__PURE__ */ (0,
|
|
38364
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FieldText, { state: field.state, placeholder: "0x\u2026" })
|
|
37098
38365
|
] }),
|
|
37099
|
-
error ? /* @__PURE__ */ (0,
|
|
38366
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.err, children: error }) : null
|
|
37100
38367
|
] })
|
|
37101
38368
|
}
|
|
37102
38369
|
);
|
|
@@ -37105,19 +38372,316 @@ function Done2(p) {
|
|
|
37105
38372
|
use_input_default((_ch, key) => {
|
|
37106
38373
|
if (key.return || key.escape) p.onClose();
|
|
37107
38374
|
});
|
|
37108
|
-
return /* @__PURE__ */ (0,
|
|
37109
|
-
/* @__PURE__ */ (0,
|
|
38375
|
+
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: [
|
|
38376
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.ok, children: [
|
|
37110
38377
|
G.ok,
|
|
37111
38378
|
" "
|
|
37112
38379
|
] }),
|
|
37113
|
-
/* @__PURE__ */ (0,
|
|
37114
|
-
/* @__PURE__ */ (0,
|
|
37115
|
-
/* @__PURE__ */ (0,
|
|
38380
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { children: "Earn mode pays into " }),
|
|
38381
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { bold: true, children: shortWallet(p.wallet) }),
|
|
38382
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Text, { color: C.muted, children: ". You earn while the agent works." })
|
|
37116
38383
|
] }) }) });
|
|
37117
38384
|
}
|
|
37118
38385
|
|
|
38386
|
+
// src/ui/panels/OverflowPanel.tsx
|
|
38387
|
+
var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
|
|
38388
|
+
function OverflowPanel(p) {
|
|
38389
|
+
use_input_default((ch, key) => {
|
|
38390
|
+
if (key.return) p.onContinue();
|
|
38391
|
+
else if (ch === "s") p.onSwitch();
|
|
38392
|
+
else if (key.escape || ch === "n") p.onClose();
|
|
38393
|
+
});
|
|
38394
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
38395
|
+
Panel,
|
|
38396
|
+
{
|
|
38397
|
+
title: "Limit reached",
|
|
38398
|
+
right: `${p.credits.toFixed(2)} credits`,
|
|
38399
|
+
width: p.width,
|
|
38400
|
+
color: C.earn,
|
|
38401
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Hints, { items: [["enter", "switch & continue"], ["s", "switch only"], ["esc", "stay"]] }),
|
|
38402
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38403
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "wrap", children: [
|
|
38404
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { bold: true, children: p.fromName }),
|
|
38405
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: " hit its usage limit." })
|
|
38406
|
+
] }),
|
|
38407
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { wrap: "wrap", children: [
|
|
38408
|
+
"Continue on ",
|
|
38409
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { bold: true, color: C.earn, children: p.toName }),
|
|
38410
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.muted, children: [
|
|
38411
|
+
" via Venice, paid from the ",
|
|
38412
|
+
p.credits.toFixed(2),
|
|
38413
|
+
" credits you earned"
|
|
38414
|
+
] }),
|
|
38415
|
+
p.price ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text, { color: C.faint, children: [
|
|
38416
|
+
" (",
|
|
38417
|
+
p.price,
|
|
38418
|
+
" per 1M tokens)"
|
|
38419
|
+
] }) : null,
|
|
38420
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.muted, children: "?" })
|
|
38421
|
+
] }),
|
|
38422
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text, { color: C.faint, wrap: "wrap", children: "Your own plan stays connected; /model switches back any time." })
|
|
38423
|
+
] })
|
|
38424
|
+
}
|
|
38425
|
+
);
|
|
38426
|
+
}
|
|
38427
|
+
|
|
38428
|
+
// src/ui/panels/McpPanel.tsx
|
|
38429
|
+
var import_react26 = __toESM(require_react(), 1);
|
|
38430
|
+
var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
|
|
38431
|
+
var DOT = { connected: C.ok, pending: C.warn, needs_auth: C.warn, failed: C.err, disabled: C.faint };
|
|
38432
|
+
function errText2(e) {
|
|
38433
|
+
return (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "";
|
|
38434
|
+
}
|
|
38435
|
+
function McpPanel(p) {
|
|
38436
|
+
const [view, setView] = (0, import_react26.useState)(p.add !== void 0 ? { v: "add", initial: p.add } : { v: "list" });
|
|
38437
|
+
switch (view.v) {
|
|
38438
|
+
case "list":
|
|
38439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(List, { ...p, onAdd: () => setView({ v: "add" }), onAuth: (integration, method, name) => setView({ v: "auth", integration, method, name }) });
|
|
38440
|
+
case "add":
|
|
38441
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38442
|
+
AddForm,
|
|
38443
|
+
{
|
|
38444
|
+
...p,
|
|
38445
|
+
initial: view.initial,
|
|
38446
|
+
onDone: (note) => {
|
|
38447
|
+
p.onChanged(note);
|
|
38448
|
+
setView({ v: "list" });
|
|
38449
|
+
},
|
|
38450
|
+
onBack: () => setView({ v: "list" })
|
|
38451
|
+
}
|
|
38452
|
+
);
|
|
38453
|
+
case "auth":
|
|
38454
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38455
|
+
OAuthFlow,
|
|
38456
|
+
{
|
|
38457
|
+
width: p.width,
|
|
38458
|
+
color: C.accent2,
|
|
38459
|
+
engine: p.engine,
|
|
38460
|
+
integration: view.integration,
|
|
38461
|
+
method: view.method,
|
|
38462
|
+
onDone: async () => {
|
|
38463
|
+
await p.engine.mcpConnect(view.name).catch(() => {
|
|
38464
|
+
});
|
|
38465
|
+
p.onChanged(`${view.name}: signed in.`);
|
|
38466
|
+
setView({ v: "list" });
|
|
38467
|
+
},
|
|
38468
|
+
onBack: () => setView({ v: "list" })
|
|
38469
|
+
}
|
|
38470
|
+
);
|
|
38471
|
+
}
|
|
38472
|
+
}
|
|
38473
|
+
function List(p) {
|
|
38474
|
+
const [list2, setList] = (0, import_react26.useState)(null);
|
|
38475
|
+
const [sel, setSel] = (0, import_react26.useState)(0);
|
|
38476
|
+
const [busy, setBusy] = (0, import_react26.useState)("");
|
|
38477
|
+
const [note, setNote] = (0, import_react26.useState)("");
|
|
38478
|
+
const [confirm, setConfirm] = (0, import_react26.useState)("");
|
|
38479
|
+
const live = (0, import_react26.useRef)(true);
|
|
38480
|
+
const refresh = () => p.engine.mcpList().then((l) => live.current && setList(l)).catch((e) => live.current && (setList([]), setNote(errText2(e))));
|
|
38481
|
+
(0, import_react26.useEffect)(() => {
|
|
38482
|
+
live.current = true;
|
|
38483
|
+
void refresh();
|
|
38484
|
+
const t = setInterval(() => void refresh(), 2e3);
|
|
38485
|
+
return () => {
|
|
38486
|
+
live.current = false;
|
|
38487
|
+
clearInterval(t);
|
|
38488
|
+
};
|
|
38489
|
+
}, []);
|
|
38490
|
+
const items = list2 ?? [];
|
|
38491
|
+
const cur = items[Math.min(sel, Math.max(0, items.length - 1))];
|
|
38492
|
+
async function act(label2, run) {
|
|
38493
|
+
setBusy(label2);
|
|
38494
|
+
setNote("");
|
|
38495
|
+
try {
|
|
38496
|
+
const msg = await run();
|
|
38497
|
+
if (msg) setNote(msg);
|
|
38498
|
+
await refresh();
|
|
38499
|
+
} catch (e) {
|
|
38500
|
+
setNote(errText2(e));
|
|
38501
|
+
} finally {
|
|
38502
|
+
setBusy("");
|
|
38503
|
+
}
|
|
38504
|
+
}
|
|
38505
|
+
async function signIn(s2) {
|
|
38506
|
+
if (!s2.integrationID) return "This server needs a sign-in the engine cannot start. Run: latentcode mcp auth " + s2.name;
|
|
38507
|
+
const integ = await p.engine.integration(s2.integrationID);
|
|
38508
|
+
const method = integ.methods.find((m) => m.type === "oauth");
|
|
38509
|
+
if (!method) return "No sign-in method offered. Run: latentcode mcp auth " + s2.name;
|
|
38510
|
+
p.onAuth(integ, method, s2.name);
|
|
38511
|
+
}
|
|
38512
|
+
async function remove(s2) {
|
|
38513
|
+
const dir = await p.engine.configDir() ?? defaultConfigDir();
|
|
38514
|
+
const hit = removeMcpFromFiles(candidateConfigFiles(dir, p.engine.cwd ?? process.cwd()), s2.name);
|
|
38515
|
+
if (!hit) return `${s2.name} is not in a config file LatentCode can see; it was only stopped for this session.`;
|
|
38516
|
+
await p.engine.mcpDrop(s2.name);
|
|
38517
|
+
await p.engine.reloadConfig().catch(() => {
|
|
38518
|
+
});
|
|
38519
|
+
p.onChanged(`${s2.name} removed from ${hit.file}${hit.backup ? ` (comments kept in ${hit.backup})` : ""}.`);
|
|
38520
|
+
return `Removed ${s2.name}.`;
|
|
38521
|
+
}
|
|
38522
|
+
use_input_default(
|
|
38523
|
+
(ch, key) => {
|
|
38524
|
+
if (key.escape) return confirm ? setConfirm("") : p.onClose();
|
|
38525
|
+
if (key.upArrow) return setSel((s2) => Math.max(0, s2 - 1)), setConfirm("");
|
|
38526
|
+
if (key.downArrow) return setSel((s2) => Math.min(items.length - 1, s2 + 1)), setConfirm("");
|
|
38527
|
+
if (ch === "a") return p.onAdd();
|
|
38528
|
+
if (ch === "r") return void refresh();
|
|
38529
|
+
if (!cur) return;
|
|
38530
|
+
if (key.return) {
|
|
38531
|
+
if (cur.status === "needs_auth") return void act("Starting sign-in\u2026", () => signIn(cur));
|
|
38532
|
+
if (cur.status === "connected") return;
|
|
38533
|
+
return void act(`Connecting ${cur.name}\u2026`, async () => void await p.engine.mcpConnect(cur.name));
|
|
38534
|
+
}
|
|
38535
|
+
if (ch === "s" && cur.status === "connected") {
|
|
38536
|
+
return void act(`Stopping ${cur.name}\u2026`, async () => {
|
|
38537
|
+
await p.engine.mcpDisconnect(cur.name);
|
|
38538
|
+
return `${cur.name} stopped for this session. It starts again next time.`;
|
|
38539
|
+
});
|
|
38540
|
+
}
|
|
38541
|
+
if (ch === "x" || key.delete) {
|
|
38542
|
+
if (confirm !== cur.name) return setConfirm(cur.name);
|
|
38543
|
+
setConfirm("");
|
|
38544
|
+
return void act(`Removing ${cur.name}\u2026`, () => remove(cur));
|
|
38545
|
+
}
|
|
38546
|
+
},
|
|
38547
|
+
{ isActive: !busy }
|
|
38548
|
+
);
|
|
38549
|
+
const sum = mcpSummary(items);
|
|
38550
|
+
const height = Math.max(3, Math.min(items.length, p.rows - 14));
|
|
38551
|
+
const win = windowAround(items.length, sel, height);
|
|
38552
|
+
const nameW = Math.min(24, Math.max(8, ...items.map((s2) => s2.name.length)) + 2);
|
|
38553
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38554
|
+
Panel,
|
|
38555
|
+
{
|
|
38556
|
+
title: "MCP servers",
|
|
38557
|
+
right: list2 ? `${sum.connected}/${sum.total} connected` : "",
|
|
38558
|
+
width: p.width,
|
|
38559
|
+
color: C.accent2,
|
|
38560
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38561
|
+
Hints,
|
|
38562
|
+
{
|
|
38563
|
+
items: [
|
|
38564
|
+
["\u2191\u2193", "move"],
|
|
38565
|
+
["enter", cur?.status === "needs_auth" ? "sign in" : "connect"],
|
|
38566
|
+
["s", "stop"],
|
|
38567
|
+
["a", "add"],
|
|
38568
|
+
["x", confirm ? "again to remove" : "remove"],
|
|
38569
|
+
["esc", "close"]
|
|
38570
|
+
]
|
|
38571
|
+
}
|
|
38572
|
+
),
|
|
38573
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38574
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, wrap: "wrap", children: "Shared with OpenCode: servers in your OpenCode config (global or this project) run here too, and the ones you add here show up in OpenCode." }),
|
|
38575
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { flexDirection: "column", marginTop: 1, children: list2 === null ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { children: [
|
|
38576
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Spinner, {}),
|
|
38577
|
+
" ",
|
|
38578
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, children: "Reading MCP servers\u2026" })
|
|
38579
|
+
] }) : items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { color: C.muted, children: [
|
|
38580
|
+
"No MCP servers yet. Press ",
|
|
38581
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { bold: true, children: "a" }),
|
|
38582
|
+
" to add one, e.g.",
|
|
38583
|
+
" ",
|
|
38584
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.code, children: "context7 https://mcp.context7.com/mcp" })
|
|
38585
|
+
] }) : items.slice(win.start, win.end).map((s2, i) => {
|
|
38586
|
+
const idx = win.start + i;
|
|
38587
|
+
const on2 = idx === sel;
|
|
38588
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38589
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { color: C.accent2, children: [
|
|
38590
|
+
on2 ? G.prompt : " ",
|
|
38591
|
+
" "
|
|
38592
|
+
] }),
|
|
38593
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { color: DOT[s2.status] ?? C.muted, children: [
|
|
38594
|
+
G.dot,
|
|
38595
|
+
" "
|
|
38596
|
+
] }),
|
|
38597
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { bold: on2, children: pad(s2.name, nameW) }),
|
|
38598
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: DOT[s2.status] ?? C.muted, children: pad(statusLabel(s2.status), 15) }),
|
|
38599
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.faint, children: s2.title ?? "" })
|
|
38600
|
+
] }, s2.name);
|
|
38601
|
+
}) }),
|
|
38602
|
+
cur?.error ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: cur.status === "needs_auth" ? C.warn : C.err, wrap: "wrap", children: cur.error }) }) : null,
|
|
38603
|
+
busy ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { children: [
|
|
38604
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Spinner, {}),
|
|
38605
|
+
" ",
|
|
38606
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, children: busy })
|
|
38607
|
+
] }) }) : null,
|
|
38608
|
+
confirm ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { color: C.warn, children: [
|
|
38609
|
+
"Press x again to remove ",
|
|
38610
|
+
confirm,
|
|
38611
|
+
" from your config (OpenCode loses it too)."
|
|
38612
|
+
] }) }) : null,
|
|
38613
|
+
note && !busy ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, wrap: "wrap", children: note }) }) : null
|
|
38614
|
+
] })
|
|
38615
|
+
}
|
|
38616
|
+
);
|
|
38617
|
+
}
|
|
38618
|
+
function AddForm(p) {
|
|
38619
|
+
const [error, setError] = (0, import_react26.useState)("");
|
|
38620
|
+
const [busy, setBusy] = (0, import_react26.useState)("");
|
|
38621
|
+
async function add(line) {
|
|
38622
|
+
const spec = parseMcpAdd(line);
|
|
38623
|
+
setBusy(`Adding ${spec.name}\u2026`);
|
|
38624
|
+
const r = await p.engine.runCli(mcpAddArgv(spec, "global"));
|
|
38625
|
+
if (r.code !== 0) throw new Error(r.out.trim().split("\n").filter(Boolean).at(-1) ?? `mcp add failed (${r.code})`);
|
|
38626
|
+
setBusy(`Starting ${spec.name}\u2026`);
|
|
38627
|
+
await p.engine.reloadConfig();
|
|
38628
|
+
const s2 = await p.engine.waitForMcp(spec.name);
|
|
38629
|
+
const label2 = statusLabel(s2.status);
|
|
38630
|
+
p.onDone(`MCP ${spec.name} added (${spec.type}) \u2014 ${label2}${label2.endsWith("\u2026") ? "" : "."}`);
|
|
38631
|
+
}
|
|
38632
|
+
const field = useLineField({
|
|
38633
|
+
active: !busy,
|
|
38634
|
+
initial: p.initial,
|
|
38635
|
+
onChange: () => setError(""),
|
|
38636
|
+
onKey: (_ch, key) => {
|
|
38637
|
+
if (key.escape) return p.onBack(), true;
|
|
38638
|
+
if (key.return) {
|
|
38639
|
+
const line = field.text.trim();
|
|
38640
|
+
if (!line) return true;
|
|
38641
|
+
add(line).catch((e) => {
|
|
38642
|
+
setError(errText2(e));
|
|
38643
|
+
setBusy("");
|
|
38644
|
+
});
|
|
38645
|
+
return true;
|
|
38646
|
+
}
|
|
38647
|
+
return false;
|
|
38648
|
+
}
|
|
38649
|
+
});
|
|
38650
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
38651
|
+
Panel,
|
|
38652
|
+
{
|
|
38653
|
+
title: "Add an MCP server",
|
|
38654
|
+
right: "saved to your OpenCode config",
|
|
38655
|
+
width: p.width,
|
|
38656
|
+
color: C.accent2,
|
|
38657
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Hints, { items: [["enter", "add"], ["esc", "back"]] }),
|
|
38658
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38659
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, children: "A name, then a URL (remote) or the command that starts it (local):" }),
|
|
38660
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.faint, children: " context7 https://mcp.context7.com/mcp" }),
|
|
38661
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.faint, children: ' github https://api.githubcopilot.com/mcp/ --header Authorization="Bearer \u2026"' }),
|
|
38662
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.faint, children: " playwright npx -y @playwright/mcp@latest" }),
|
|
38663
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box_default, { marginTop: 1, children: [
|
|
38664
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { color: C.accent2, children: [
|
|
38665
|
+
G.prompt,
|
|
38666
|
+
" "
|
|
38667
|
+
] }),
|
|
38668
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FieldText, { state: field.state, placeholder: "name url | command\u2026" })
|
|
38669
|
+
] }),
|
|
38670
|
+
busy ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Text, { children: [
|
|
38671
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Spinner, {}),
|
|
38672
|
+
" ",
|
|
38673
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.muted, children: busy })
|
|
38674
|
+
] }) : null,
|
|
38675
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Text, { color: C.err, wrap: "wrap", children: error }) : null
|
|
38676
|
+
] })
|
|
38677
|
+
}
|
|
38678
|
+
);
|
|
38679
|
+
}
|
|
38680
|
+
|
|
37119
38681
|
// src/ui/App.tsx
|
|
37120
|
-
var
|
|
38682
|
+
var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
|
|
38683
|
+
var DASHBOARD = "latentprotocol.xyz/app";
|
|
38684
|
+
var MODE = { keep: "keep and spend (bonus)", auto_sell: "sell automatically for USDC", auto_list: "list at my price" };
|
|
37121
38685
|
var notice = (text, tone = "info") => ({
|
|
37122
38686
|
type: "latentcode.notice",
|
|
37123
38687
|
created: Date.now(),
|
|
@@ -37149,42 +38713,42 @@ function activityLabel(s2) {
|
|
|
37149
38713
|
function StepMark({ status: status2 }) {
|
|
37150
38714
|
switch (status2) {
|
|
37151
38715
|
case "run":
|
|
37152
|
-
return /* @__PURE__ */ (0,
|
|
38716
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Spinner, {});
|
|
37153
38717
|
case "ok":
|
|
37154
|
-
return /* @__PURE__ */ (0,
|
|
38718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.ok, children: G.ok });
|
|
37155
38719
|
case "warn":
|
|
37156
|
-
return /* @__PURE__ */ (0,
|
|
38720
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.warn, children: G.ring });
|
|
37157
38721
|
case "fail":
|
|
37158
|
-
return /* @__PURE__ */ (0,
|
|
38722
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.err, children: G.no });
|
|
37159
38723
|
default:
|
|
37160
|
-
return /* @__PURE__ */ (0,
|
|
38724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.faint, children: "\xB7" });
|
|
37161
38725
|
}
|
|
37162
38726
|
}
|
|
37163
38727
|
function BootCard(p) {
|
|
37164
38728
|
const wLabel = 10;
|
|
37165
38729
|
const inner = p.width - 4;
|
|
37166
|
-
return /* @__PURE__ */ (0,
|
|
37167
|
-
/* @__PURE__ */ (0,
|
|
37168
|
-
/* @__PURE__ */ (0,
|
|
37169
|
-
/* @__PURE__ */ (0,
|
|
38730
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { flexDirection: "column", children: [
|
|
38731
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { marginTop: 1, marginLeft: 1, flexDirection: "column", children: [
|
|
38732
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Logo, { version: p.version }),
|
|
38733
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.muted, children: TAGLINE })
|
|
37170
38734
|
] }),
|
|
37171
|
-
/* @__PURE__ */ (0,
|
|
37172
|
-
p.steps.map((st) => /* @__PURE__ */ (0,
|
|
37173
|
-
/* @__PURE__ */ (0,
|
|
37174
|
-
/* @__PURE__ */ (0,
|
|
38735
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { marginTop: 1, flexDirection: "column", borderStyle: "round", borderColor: p.error ? C.err : C.border, paddingX: 1, width: p.width, children: [
|
|
38736
|
+
p.steps.map((st) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38737
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(StepMark, { status: st.status }),
|
|
38738
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { bold: st.status === "run", color: st.status === "pending" ? C.faint : void 0, children: [
|
|
37175
38739
|
" ",
|
|
37176
38740
|
pad(st.label, wLabel)
|
|
37177
38741
|
] }),
|
|
37178
|
-
/* @__PURE__ */ (0,
|
|
38742
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.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) })
|
|
37179
38743
|
] }, st.id)),
|
|
37180
|
-
/* @__PURE__ */ (0,
|
|
37181
|
-
/* @__PURE__ */ (0,
|
|
37182
|
-
/* @__PURE__ */ (0,
|
|
37183
|
-
/* @__PURE__ */ (0,
|
|
38744
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38745
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.faint, children: "\xB7 " }),
|
|
38746
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.faint, children: pad("Project", wLabel) }),
|
|
38747
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.muted, children: shortPath(p.cwd, homedir4(), inner - wLabel - 4) })
|
|
37184
38748
|
] })
|
|
37185
38749
|
] }),
|
|
37186
|
-
p.error ? /* @__PURE__ */ (0,
|
|
37187
|
-
p.ready ? /* @__PURE__ */ (0,
|
|
38750
|
+
p.error ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginLeft: 1, marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.err, wrap: "wrap", children: p.error }) }) : null,
|
|
38751
|
+
p.ready ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginLeft: 1, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
37188
38752
|
Hints,
|
|
37189
38753
|
{
|
|
37190
38754
|
items: [
|
|
@@ -37213,44 +38777,45 @@ function HelpPanel({ width, commands, onClose }) {
|
|
|
37213
38777
|
["ctrl+o", "open the sponsored link"],
|
|
37214
38778
|
["ctrl+c", "clear the line, twice to quit"]
|
|
37215
38779
|
];
|
|
37216
|
-
return /* @__PURE__ */ (0,
|
|
38780
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Panel, { title: "Help", width, color: C.accent, footer: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Hints, { items: [["esc", "close"]] }), children: [
|
|
37217
38781
|
groups.map((g) => {
|
|
37218
|
-
const
|
|
37219
|
-
if (!
|
|
37220
|
-
return /* @__PURE__ */ (0,
|
|
37221
|
-
/* @__PURE__ */ (0,
|
|
37222
|
-
|
|
37223
|
-
/* @__PURE__ */ (0,
|
|
37224
|
-
/* @__PURE__ */ (0,
|
|
38782
|
+
const list2 = commands.filter((c) => c.group === g);
|
|
38783
|
+
if (!list2.length) return null;
|
|
38784
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38785
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { bold: true, color: C.muted, children: g }),
|
|
38786
|
+
list2.map((c) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
38787
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.accent2, children: pad(`/${c.name}${c.args ? " " + c.args : ""}`, 22) }),
|
|
38788
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.muted, children: c.desc })
|
|
37225
38789
|
] }, c.name))
|
|
37226
38790
|
] }, g);
|
|
37227
38791
|
}),
|
|
37228
|
-
/* @__PURE__ */ (0,
|
|
37229
|
-
/* @__PURE__ */ (0,
|
|
37230
|
-
keys.map(([k, d]) => /* @__PURE__ */ (0,
|
|
37231
|
-
/* @__PURE__ */ (0,
|
|
37232
|
-
/* @__PURE__ */ (0,
|
|
38792
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { flexDirection: "column", marginTop: 1, children: [
|
|
38793
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { bold: true, color: C.muted, children: "Keys" }),
|
|
38794
|
+
keys.map(([k, d]) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { children: [
|
|
38795
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.accent2, children: pad(k, 22) }),
|
|
38796
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.muted, children: d })
|
|
37233
38797
|
] }, k))
|
|
37234
38798
|
] }),
|
|
37235
|
-
/* @__PURE__ */ (0,
|
|
38799
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginTop: 1, children: /* @__PURE__ */ (0, import_jsx_runtime9.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.` }) })
|
|
37236
38800
|
] });
|
|
37237
38801
|
}
|
|
38802
|
+
var LINKS_OSC8 = linkShape() === "osc8";
|
|
37238
38803
|
function App2(props) {
|
|
37239
38804
|
const { engine, controller, api, cwd: cwd2, version } = props;
|
|
37240
38805
|
const { exit } = use_app_default();
|
|
37241
38806
|
const { cols, rows } = useTermSize();
|
|
37242
38807
|
const width = Math.max(40, Math.min(cols, 110));
|
|
37243
|
-
const [sessionID, setSessionID] = (0,
|
|
37244
|
-
const [state, dispatch] = (0,
|
|
38808
|
+
const [sessionID, setSessionID] = (0, import_react27.useState)(props.sessionID);
|
|
38809
|
+
const [state, dispatch] = (0, import_react27.useReducer)(
|
|
37245
38810
|
(s2, ev) => ev.type === "reset" ? { ...initialState(ev.sessionID, s2.model), variant: s2.variant } : reduce(s2, ev),
|
|
37246
38811
|
{ ...initialState(props.sessionID, props.model), variant: props.variant }
|
|
37247
38812
|
);
|
|
37248
|
-
const [catalog, setCatalog] = (0,
|
|
37249
|
-
const [wallet, setWallet] = (0,
|
|
37250
|
-
const [overlay, setOverlay] = (0,
|
|
37251
|
-
const [, tick] = (0,
|
|
37252
|
-
const [editor, setEditorState] = (0,
|
|
37253
|
-
const editorRef = (0,
|
|
38813
|
+
const [catalog, setCatalog] = (0, import_react27.useState)(props.catalog);
|
|
38814
|
+
const [wallet, setWallet] = (0, import_react27.useState)(props.wallet);
|
|
38815
|
+
const [overlay, setOverlay] = (0, import_react27.useState)(null);
|
|
38816
|
+
const [, tick] = (0, import_react27.useState)(0);
|
|
38817
|
+
const [editor, setEditorState] = (0, import_react27.useState)(() => emptyEditor());
|
|
38818
|
+
const editorRef = (0, import_react27.useRef)(editor);
|
|
37254
38819
|
const setEditor = (next) => {
|
|
37255
38820
|
if (next.text !== editorRef.current.text) {
|
|
37256
38821
|
setPaletteAt(0);
|
|
@@ -37259,24 +38824,24 @@ function App2(props) {
|
|
|
37259
38824
|
editorRef.current = next;
|
|
37260
38825
|
setEditorState(next);
|
|
37261
38826
|
};
|
|
37262
|
-
const [paletteAt, setPaletteAt] = (0,
|
|
37263
|
-
const [paletteHidden, setPaletteHidden] = (0,
|
|
37264
|
-
const [permAt, setPermAt] = (0,
|
|
37265
|
-
const [quitArmed, setQuitArmed] = (0,
|
|
37266
|
-
const [leaving, setLeaving] = (0,
|
|
38827
|
+
const [paletteAt, setPaletteAt] = (0, import_react27.useState)(0);
|
|
38828
|
+
const [paletteHidden, setPaletteHidden] = (0, import_react27.useState)(false);
|
|
38829
|
+
const [permAt, setPermAt] = (0, import_react27.useState)(0);
|
|
38830
|
+
const [quitArmed, setQuitArmed] = (0, import_react27.useState)(false);
|
|
38831
|
+
const [leaving, setLeaving] = (0, import_react27.useState)(false);
|
|
37267
38832
|
const quit = () => {
|
|
37268
38833
|
setLeaving(true);
|
|
37269
38834
|
setTimeout(() => exit(), 20);
|
|
37270
38835
|
};
|
|
37271
|
-
const lastPrompt = (0,
|
|
37272
|
-
const currentModel = (0,
|
|
38836
|
+
const lastPrompt = (0, import_react27.useRef)("");
|
|
38837
|
+
const currentModel = (0, import_react27.useRef)(props.model);
|
|
37273
38838
|
currentModel.current = state.model;
|
|
37274
38839
|
const store = props.models;
|
|
37275
|
-
const ad = (0,
|
|
38840
|
+
const ad = (0, import_react27.useSyncExternalStore)(
|
|
37276
38841
|
(fn) => controller.subscribe(fn),
|
|
37277
38842
|
() => controller.snapshot()
|
|
37278
38843
|
);
|
|
37279
|
-
const allCommands = (0,
|
|
38844
|
+
const allCommands = (0, import_react27.useMemo)(
|
|
37280
38845
|
() => [
|
|
37281
38846
|
...COMMANDS,
|
|
37282
38847
|
...props.commands.filter((c) => !findCommand(c.name)).map((c) => ({ name: c.name, args: "[text]", desc: c.description ?? "agent command", group: "Agent" }))
|
|
@@ -37286,14 +38851,18 @@ function App2(props) {
|
|
|
37286
38851
|
const say = (text, tone = "info") => dispatch(notice(text, tone));
|
|
37287
38852
|
const statusOf = (key) => store.get(key)?.status ?? "unknown";
|
|
37288
38853
|
const modelName = (key) => catalog.models.find((m) => m.key === key)?.name ?? key;
|
|
38854
|
+
const [bonus, setBonus] = (0, import_react27.useState)(1);
|
|
38855
|
+
(0, import_react27.useEffect)(() => {
|
|
38856
|
+
void api.creditQuote().then((q) => q && setBonus(q.bonus));
|
|
38857
|
+
}, [api]);
|
|
37289
38858
|
props.summary.current = {
|
|
37290
38859
|
turns: state.turns,
|
|
37291
38860
|
tokens: state.tokens.input + state.tokens.output,
|
|
37292
38861
|
cost: state.cost,
|
|
37293
|
-
earned: ad.sessionEarned,
|
|
38862
|
+
earned: credits(ad.sessionEarned, bonus),
|
|
37294
38863
|
impressions: ad.impressions
|
|
37295
38864
|
};
|
|
37296
|
-
(0,
|
|
38865
|
+
(0, import_react27.useEffect)(() => {
|
|
37297
38866
|
const ac = new AbortController();
|
|
37298
38867
|
void engine.subscribe((ev) => {
|
|
37299
38868
|
dispatch(ev);
|
|
@@ -37305,19 +38874,37 @@ function App2(props) {
|
|
|
37305
38874
|
if (props.startNotice) say(props.startNotice, "warn");
|
|
37306
38875
|
return () => ac.abort();
|
|
37307
38876
|
}, [engine]);
|
|
37308
|
-
(0,
|
|
38877
|
+
(0, import_react27.useEffect)(() => {
|
|
37309
38878
|
controller.setWorking(state.working, lastPrompt.current);
|
|
37310
38879
|
}, [state.working, controller]);
|
|
37311
|
-
|
|
37312
|
-
|
|
37313
|
-
|
|
37314
|
-
|
|
37315
|
-
|
|
37316
|
-
|
|
38880
|
+
const lingering = !state.working && !!ad.current;
|
|
38881
|
+
(0, import_react27.useEffect)(() => {
|
|
38882
|
+
if (!state.working && !lingering) return;
|
|
38883
|
+
const t = setInterval(
|
|
38884
|
+
() => {
|
|
38885
|
+
controller.tick();
|
|
38886
|
+
if (state.working) tick((f) => f + 1);
|
|
38887
|
+
},
|
|
38888
|
+
state.working ? 250 : 1e3
|
|
38889
|
+
);
|
|
37317
38890
|
return () => clearInterval(t);
|
|
37318
|
-
}, [state.working, controller]);
|
|
37319
|
-
|
|
37320
|
-
(0,
|
|
38891
|
+
}, [state.working, lingering, controller]);
|
|
38892
|
+
const [balance, setBalance] = (0, import_react27.useState)(null);
|
|
38893
|
+
const catalogRef = (0, import_react27.useRef)(catalog);
|
|
38894
|
+
catalogRef.current = catalog;
|
|
38895
|
+
const balanceRef = (0, import_react27.useRef)(balance);
|
|
38896
|
+
balanceRef.current = balance;
|
|
38897
|
+
const offered = (0, import_react27.useRef)(/* @__PURE__ */ new Set());
|
|
38898
|
+
(0, import_react27.useEffect)(() => {
|
|
38899
|
+
if (!wallet || state.working) return;
|
|
38900
|
+
let live2 = true;
|
|
38901
|
+
void api.creditSummary(wallet).then((c) => live2 && setBalance(c ? c.credits : null));
|
|
38902
|
+
return () => {
|
|
38903
|
+
live2 = false;
|
|
38904
|
+
};
|
|
38905
|
+
}, [api, wallet, state.working, ad.impressions]);
|
|
38906
|
+
(0, import_react27.useEffect)(() => setPermAt(0), [state.permissions[0]?.id]);
|
|
38907
|
+
(0, import_react27.useEffect)(() => {
|
|
37321
38908
|
if (!quitArmed) return;
|
|
37322
38909
|
const t = setTimeout(() => setQuitArmed(false), 2e3);
|
|
37323
38910
|
return () => clearTimeout(t);
|
|
@@ -37326,12 +38913,18 @@ function App2(props) {
|
|
|
37326
38913
|
const model = currentModel.current;
|
|
37327
38914
|
if (!model) return;
|
|
37328
38915
|
const v = classifyError(ev.data?.error);
|
|
37329
|
-
const name =
|
|
38916
|
+
const name = catalogRef.current.models.find((m) => m.key === model)?.name ?? model;
|
|
37330
38917
|
if (v.status === "unsupported") {
|
|
37331
38918
|
store.set(model, v);
|
|
37332
38919
|
say(`${name} isn't available with your connected account. /model shows which ones are (${G.ok}).`, "warn");
|
|
37333
38920
|
} else if (v.status === "rate-limited") {
|
|
37334
38921
|
store.set(model, v);
|
|
38922
|
+
const offer = overflowOffer(model, v, catalogRef.current, balanceRef.current, offered.current);
|
|
38923
|
+
if (offer) {
|
|
38924
|
+
offered.current.add(model);
|
|
38925
|
+
setOverlay({ t: "overflow", offer });
|
|
38926
|
+
return;
|
|
38927
|
+
}
|
|
37335
38928
|
const mins = v.until ? Math.max(1, Math.round((v.until - Date.now()) / 6e4)) : 0;
|
|
37336
38929
|
say(`${name} is rate-limited${mins ? ` for about ${mins} min` : ""}. /model to switch.`, "warn");
|
|
37337
38930
|
} else if (v.status === "auth") {
|
|
@@ -37361,6 +38954,20 @@ function App2(props) {
|
|
|
37361
38954
|
function changeWallet(next) {
|
|
37362
38955
|
setWallet(next);
|
|
37363
38956
|
controller.setWallet(next);
|
|
38957
|
+
void connectLoginKey();
|
|
38958
|
+
}
|
|
38959
|
+
async function connectLoginKey() {
|
|
38960
|
+
try {
|
|
38961
|
+
const res = await connectPendingLatentKey(engine, props.server, { load: loadConfig, save: (p) => void saveConfig(p) });
|
|
38962
|
+
if (!res) return;
|
|
38963
|
+
const next = await reloadCatalog();
|
|
38964
|
+
const m = res.defaultModel ? next.models.find((x) => x.key === res.defaultModel) : void 0;
|
|
38965
|
+
if (m) await pickModel(m, "");
|
|
38966
|
+
say(`Latent connected: ${res.models.length} models, paid from your earnings.${m ? "" : " Pick one with /model latent."}`, "ok");
|
|
38967
|
+
props.sync.kick();
|
|
38968
|
+
} catch (e) {
|
|
38969
|
+
say(`Latent not connected: ${e instanceof Error ? e.message : String(e)}. Try /key lk_\u2026 with a key from the dashboard.`, "warn");
|
|
38970
|
+
}
|
|
37364
38971
|
}
|
|
37365
38972
|
async function runCommand(line) {
|
|
37366
38973
|
const { name, arg } = parseCommandLine(line);
|
|
@@ -37412,13 +39019,54 @@ function App2(props) {
|
|
|
37412
39019
|
say("No wallet connected yet. /login takes a minute and you start earning right away.", "warn");
|
|
37413
39020
|
return;
|
|
37414
39021
|
}
|
|
37415
|
-
const
|
|
39022
|
+
const c = await api.creditSummary(wallet);
|
|
39023
|
+
const hasLatent = catalog.providers.some((p) => p.id === LATENT_PROVIDER_ID);
|
|
37416
39024
|
say(
|
|
37417
|
-
`This session: ${ad.impressions} sponsored view${ad.impressions === 1 ? "" : "s"} \u2248
|
|
37418
|
-
Wallet ${shortWallet(wallet)} \xB7
|
|
39025
|
+
`This session: ${ad.impressions} sponsored view${ad.impressions === 1 ? "" : "s"} \u2248 ${credits(ad.sessionEarned, bonus).toFixed(3)} credits (indicative)
|
|
39026
|
+
Wallet ${shortWallet(wallet)} \xB7 ${c === null ? "balance unavailable right now" : `${c.credits.toFixed(2)} Latent Credit ($1 of model usage each)`}` + (c ? `
|
|
39027
|
+
Mode: ${MODE[c.mode]} \u2014 change it at ${DASHBOARD}/settings` : "") + (hasLatent ? "" : `
|
|
39028
|
+
Spend it here: /login connects the Latent provider (or /key lk_\u2026 with a key from ${DASHBOARD}/earn).`)
|
|
37419
39029
|
);
|
|
37420
39030
|
return;
|
|
37421
39031
|
}
|
|
39032
|
+
case "credits": {
|
|
39033
|
+
if (!wallet) {
|
|
39034
|
+
say("No wallet connected yet. /login first.", "warn");
|
|
39035
|
+
return;
|
|
39036
|
+
}
|
|
39037
|
+
const [c, q] = await Promise.all([api.creditSummary(wallet), api.creditQuote()]);
|
|
39038
|
+
if (!c) {
|
|
39039
|
+
say("Credit balance unavailable right now.", "warn");
|
|
39040
|
+
return;
|
|
39041
|
+
}
|
|
39042
|
+
say(
|
|
39043
|
+
[
|
|
39044
|
+
`Latent Credit ${c.credits.toFixed(2)} credits \xB7 $1 of model usage at list price each`,
|
|
39045
|
+
`Bonus ${c.bonus}\xD7 \u2014 every $1 earned from ads becomes ${c.bonus} credits`,
|
|
39046
|
+
`Mode ${MODE[c.mode]}`,
|
|
39047
|
+
q?.buybackEnabled ? `Sell now ${q.buybackPrice.toFixed(2)} USDC per credit, paid on Base` : `Sell now opens soon`,
|
|
39048
|
+
`Change it ${DASHBOARD}/settings \xB7 sell or list at ${DASHBOARD}/earn \xB7 buy at ${DASHBOARD}/credits`
|
|
39049
|
+
].join("\n")
|
|
39050
|
+
);
|
|
39051
|
+
return;
|
|
39052
|
+
}
|
|
39053
|
+
case "key": {
|
|
39054
|
+
const k = arg.trim();
|
|
39055
|
+
if (!k) {
|
|
39056
|
+
say("/login connects the Latent provider for you. Or paste a key from latentprotocol.xyz/app/earn: /key lk_\u2026");
|
|
39057
|
+
return;
|
|
39058
|
+
}
|
|
39059
|
+
say("Connecting your Latent Key\u2026");
|
|
39060
|
+
try {
|
|
39061
|
+
const res = await connectLatentKey(engine, props.server, k);
|
|
39062
|
+
await reloadCatalog();
|
|
39063
|
+
const note = res.backup ? ` (Comments in ${res.file} could not be kept; the original is at ${res.backup}.)` : "";
|
|
39064
|
+
say(`Latent connected: ${res.models.length} models, paid from your earnings. Pick one with /model latent.${note}`, "ok");
|
|
39065
|
+
} catch (e) {
|
|
39066
|
+
say(e instanceof Error ? e.message : String(e), "warn");
|
|
39067
|
+
}
|
|
39068
|
+
return;
|
|
39069
|
+
}
|
|
37422
39070
|
case "status": {
|
|
37423
39071
|
const prov = catalog.providers.map((p) => p.name).join(", ");
|
|
37424
39072
|
say(
|
|
@@ -37426,7 +39074,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37426
39074
|
`Model ${describeModel(state.model, catalog)}${state.variant ? ` \xB7 effort ${state.variant}` : ""}`,
|
|
37427
39075
|
`Providers ${prov || "none"}`,
|
|
37428
39076
|
`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)}` : ""}`,
|
|
37429
|
-
`Earn ${ad.status === "disabled" ? "off" : wallet ? `on \xB7 ${shortWallet(wallet)} \xB7 \u2248
|
|
39077
|
+
`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"}`,
|
|
37430
39078
|
`Safety ${props.permissions.length ? "asks before shell commands and file changes" : "--auto (no confirmation)"}`
|
|
37431
39079
|
].join("\n")
|
|
37432
39080
|
);
|
|
@@ -37441,6 +39089,9 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37441
39089
|
case "connect":
|
|
37442
39090
|
setOverlay({ t: "providers", connect: true, query: arg || void 0 });
|
|
37443
39091
|
return;
|
|
39092
|
+
case "mcp":
|
|
39093
|
+
setOverlay(/^add\b/.test(arg) ? { t: "mcp", add: arg.replace(/^add\s*/, "") } : { t: "mcp" });
|
|
39094
|
+
return;
|
|
37444
39095
|
case "model": {
|
|
37445
39096
|
const exact = arg ? catalog.models.find((m) => m.key === arg) : void 0;
|
|
37446
39097
|
if (exact) await pickModel(exact, "");
|
|
@@ -37472,9 +39123,13 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37472
39123
|
const matches = overlay || perm || paletteHidden ? [] : matchCommands(editor.text, allCommands);
|
|
37473
39124
|
const paletteOpen = matches.length > 0 && !(matches.length === 1 && "/" + matches[0].name === editor.text && !matches[0].args);
|
|
37474
39125
|
const paletteSel = Math.min(paletteAt, Math.max(0, matches.length - 1));
|
|
37475
|
-
usePaste((text) =>
|
|
39126
|
+
usePaste((text) => {
|
|
39127
|
+
controller.noteActivity();
|
|
39128
|
+
setEditor(insert(editorRef.current, text.replace(/\n+$/, "")));
|
|
39129
|
+
}, overlay === null && !perm);
|
|
37476
39130
|
use_input_default(
|
|
37477
39131
|
(ch, key) => {
|
|
39132
|
+
controller.noteActivity();
|
|
37478
39133
|
if (perm) {
|
|
37479
39134
|
const decisions = ["once", "always", "reject"];
|
|
37480
39135
|
const reply = (d) => void engine.replyPermission(sessionID, perm.id, d).catch(fail);
|
|
@@ -37526,62 +39181,34 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37526
39181
|
const live = state.items.slice(cut);
|
|
37527
39182
|
const elapsed = state.workingSince ? Math.max(0, Math.floor((Date.now() - state.workingSince) / 1e3)) : 0;
|
|
37528
39183
|
const maxLines = Math.max(6, rows - 14);
|
|
37529
|
-
const header = (0,
|
|
39184
|
+
const header = (0, import_react27.useMemo)(() => ({ id: "header" }), []);
|
|
37530
39185
|
const current = catalog.models.find((m) => m.key === state.model);
|
|
37531
39186
|
const provider = catalog.providers.find((p) => p.id === (current?.providerID ?? parseKey(state.model)?.providerID));
|
|
37532
39187
|
const close = () => setOverlay(null);
|
|
37533
|
-
return /* @__PURE__ */ (0,
|
|
37534
|
-
/* @__PURE__ */ (0,
|
|
37535
|
-
live.map((it) => /* @__PURE__ */ (0,
|
|
37536
|
-
perm ? /* @__PURE__ */ (0,
|
|
37537
|
-
state.working ? /* @__PURE__ */ (0,
|
|
37538
|
-
/* @__PURE__ */ (0,
|
|
37539
|
-
|
|
37540
|
-
|
|
37541
|
-
|
|
37542
|
-
|
|
37543
|
-
"\u2026"
|
|
37544
|
-
] }),
|
|
37545
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37546
|
-
" ",
|
|
37547
|
-
elapsed,
|
|
37548
|
-
"s \xB7 ",
|
|
37549
|
-
G.up,
|
|
37550
|
-
fmtTokens(state.tokens.input),
|
|
37551
|
-
" ",
|
|
37552
|
-
G.down,
|
|
37553
|
-
fmtTokens(state.tokens.output),
|
|
37554
|
-
" \xB7 esc to interrupt"
|
|
37555
|
-
] })
|
|
39188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
39189
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Static, { items: [header, ...done.map((it) => ({ id: it.id, it }))], children: (entry) => "it" in entry ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ItemView, { item: entry.it, live: false, cwd: cwd2, width, maxLines }, entry.id) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BootCard, { steps: props.bootSteps, version, cwd: cwd2, width, ready: true }, entry.id) }),
|
|
39190
|
+
live.map((it) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ItemView, { item: it, live: true, cwd: cwd2, width, maxLines }, it.id)),
|
|
39191
|
+
perm ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PermissionPrompt, { perm, selected: permAt, cwd: cwd2, width }) : null,
|
|
39192
|
+
state.working ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { marginTop: 1, flexDirection: "column", width, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
39193
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Spinner, {}),
|
|
39194
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { children: [
|
|
39195
|
+
" ",
|
|
39196
|
+
activityLabel(state),
|
|
39197
|
+
"\u2026"
|
|
37556
39198
|
] }),
|
|
37557
|
-
|
|
37558
|
-
|
|
37559
|
-
|
|
37560
|
-
|
|
37561
|
-
|
|
37562
|
-
|
|
37563
|
-
|
|
37564
|
-
|
|
37565
|
-
|
|
37566
|
-
|
|
37567
|
-
|
|
37568
|
-
|
|
37569
|
-
|
|
37570
|
-
" \u2014 ",
|
|
37571
|
-
ad.current.body
|
|
37572
|
-
] }) : null,
|
|
37573
|
-
ad.current.url ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37574
|
-
" \xB7 ctrl+o ",
|
|
37575
|
-
ad.current.ctaText
|
|
37576
|
-
] }) : null
|
|
37577
|
-
] }),
|
|
37578
|
-
ad.billed && ad.current.earn > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.earn, children: [
|
|
37579
|
-
" +$",
|
|
37580
|
-
ad.current.earn.toFixed(4)
|
|
37581
|
-
] }) : null
|
|
37582
|
-
] }) : null
|
|
37583
|
-
] }) : null,
|
|
37584
|
-
overlay?.t === "model" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
39199
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { color: C.faint, children: [
|
|
39200
|
+
" ",
|
|
39201
|
+
elapsed,
|
|
39202
|
+
"s \xB7 ",
|
|
39203
|
+
G.up,
|
|
39204
|
+
fmtTokens(state.tokens.input),
|
|
39205
|
+
" ",
|
|
39206
|
+
G.down,
|
|
39207
|
+
fmtTokens(state.tokens.output),
|
|
39208
|
+
" \xB7 esc to interrupt"
|
|
39209
|
+
] })
|
|
39210
|
+
] }) }) : null,
|
|
39211
|
+
overlay?.t === "model" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
37585
39212
|
ModelPicker,
|
|
37586
39213
|
{
|
|
37587
39214
|
catalog,
|
|
@@ -37600,7 +39227,7 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37600
39227
|
onClose: close
|
|
37601
39228
|
}
|
|
37602
39229
|
) : null,
|
|
37603
|
-
overlay?.t === "providers" ? /* @__PURE__ */ (0,
|
|
39230
|
+
overlay?.t === "providers" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
37604
39231
|
ProviderPanel,
|
|
37605
39232
|
{
|
|
37606
39233
|
engine,
|
|
@@ -37614,15 +39241,54 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37614
39241
|
onConnected: async (name) => {
|
|
37615
39242
|
const next = await reloadCatalog();
|
|
37616
39243
|
say(`${name} connected.`, "ok");
|
|
39244
|
+
props.sync.kick();
|
|
37617
39245
|
return next;
|
|
37618
39246
|
},
|
|
37619
39247
|
onClose: close
|
|
37620
39248
|
}
|
|
37621
39249
|
) : null,
|
|
37622
|
-
overlay?.t === "
|
|
37623
|
-
|
|
37624
|
-
|
|
37625
|
-
|
|
39250
|
+
overlay?.t === "mcp" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
39251
|
+
McpPanel,
|
|
39252
|
+
{
|
|
39253
|
+
engine,
|
|
39254
|
+
width,
|
|
39255
|
+
rows,
|
|
39256
|
+
add: overlay.add,
|
|
39257
|
+
onChanged: (note) => {
|
|
39258
|
+
say(note, "ok");
|
|
39259
|
+
props.sync.kick();
|
|
39260
|
+
},
|
|
39261
|
+
onClose: close
|
|
39262
|
+
}
|
|
39263
|
+
) : null,
|
|
39264
|
+
overlay?.t === "wallet" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(WalletPanel, { server: props.server, wallet, width, onWallet: changeWallet, onClose: close }) : null,
|
|
39265
|
+
overlay?.t === "help" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HelpPanel, { width, commands: allCommands, onClose: close }) : null,
|
|
39266
|
+
overlay?.t === "overflow" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
39267
|
+
OverflowPanel,
|
|
39268
|
+
{
|
|
39269
|
+
width,
|
|
39270
|
+
fromName: modelName(overlay.offer.from),
|
|
39271
|
+
toName: overlay.offer.to.name,
|
|
39272
|
+
price: overlay.offer.to.costIn !== null ? fmtPrice(overlay.offer.to, "latent") : void 0,
|
|
39273
|
+
credits: overlay.offer.credits,
|
|
39274
|
+
onContinue: () => {
|
|
39275
|
+
const to = overlay.offer.to;
|
|
39276
|
+
close();
|
|
39277
|
+
void pickModel(to, "").then(() => {
|
|
39278
|
+
lastPrompt.current = "Continue where you left off.";
|
|
39279
|
+
return engine.prompt(sessionID, lastPrompt.current);
|
|
39280
|
+
}).catch(fail);
|
|
39281
|
+
},
|
|
39282
|
+
onSwitch: () => {
|
|
39283
|
+
const to = overlay.offer.to;
|
|
39284
|
+
close();
|
|
39285
|
+
void pickModel(to, "").catch(fail);
|
|
39286
|
+
},
|
|
39287
|
+
onClose: close
|
|
39288
|
+
}
|
|
39289
|
+
) : null,
|
|
39290
|
+
overlay === null && !perm && !leaving ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
39291
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
37626
39292
|
Box_default,
|
|
37627
39293
|
{
|
|
37628
39294
|
marginTop: 1,
|
|
@@ -37631,84 +39297,70 @@ Wallet ${shortWallet(wallet)} \xB7 unpaid balance ${bal === null ? "unavailable
|
|
|
37631
39297
|
paddingX: 1,
|
|
37632
39298
|
width,
|
|
37633
39299
|
children: [
|
|
37634
|
-
/* @__PURE__ */ (0,
|
|
39300
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { flexShrink: 0, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { color: C.accent, bold: true, children: [
|
|
37635
39301
|
G.prompt,
|
|
37636
39302
|
" "
|
|
37637
39303
|
] }) }),
|
|
37638
|
-
/* @__PURE__ */ (0,
|
|
39304
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FieldText, { state: editor, placeholder: state.turns ? "reply, or / for commands" : "ask anything, or / for commands" })
|
|
37639
39305
|
]
|
|
37640
39306
|
}
|
|
37641
39307
|
),
|
|
37642
|
-
paletteOpen ? /* @__PURE__ */ (0,
|
|
37643
|
-
matches.slice(0, 8).map((c, i) => /* @__PURE__ */ (0,
|
|
37644
|
-
/* @__PURE__ */ (0,
|
|
39308
|
+
paletteOpen ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Box_default, { flexDirection: "column", paddingX: 2, width, children: [
|
|
39309
|
+
matches.slice(0, 8).map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { wrap: "truncate-end", children: [
|
|
39310
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { color: C.accent, children: [
|
|
37645
39311
|
i === paletteSel ? G.prompt : " ",
|
|
37646
39312
|
" "
|
|
37647
39313
|
] }),
|
|
37648
|
-
/* @__PURE__ */ (0,
|
|
37649
|
-
/* @__PURE__ */ (0,
|
|
39314
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { bold: i === paletteSel, color: i === paletteSel ? C.accent2 : C.text, children: pad(`/${c.name}${c.args ? " " + c.args : ""}`, 20) }),
|
|
39315
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.muted, children: c.desc })
|
|
37650
39316
|
] }, c.name)),
|
|
37651
|
-
matches.length > 8 ? /* @__PURE__ */ (0,
|
|
39317
|
+
matches.length > 8 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(Text, { color: C.faint, children: [
|
|
37652
39318
|
" ",
|
|
37653
39319
|
G.down,
|
|
37654
39320
|
" ",
|
|
37655
39321
|
matches.length - 8,
|
|
37656
39322
|
" more \u2014 keep typing"
|
|
37657
39323
|
] }) : null,
|
|
37658
|
-
/* @__PURE__ */ (0,
|
|
39324
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Hints, { items: [["\u2191\u2193", "move"], ["tab", "complete"], ["enter", "run"], ["esc", "dismiss"]] })
|
|
37659
39325
|
] }) : null
|
|
37660
39326
|
] }) : null,
|
|
37661
|
-
paletteOpen || leaving ? null : /* @__PURE__ */ (0,
|
|
37662
|
-
|
|
37663
|
-
|
|
37664
|
-
|
|
37665
|
-
|
|
37666
|
-
|
|
37667
|
-
|
|
37668
|
-
|
|
37669
|
-
|
|
37670
|
-
|
|
37671
|
-
|
|
37672
|
-
|
|
37673
|
-
|
|
37674
|
-
|
|
37675
|
-
|
|
37676
|
-
|
|
37677
|
-
|
|
37678
|
-
|
|
37679
|
-
|
|
37680
|
-
|
|
37681
|
-
|
|
37682
|
-
|
|
37683
|
-
|
|
37684
|
-
|
|
37685
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37686
|
-
" \xB7 ",
|
|
37687
|
-
ad.impressions,
|
|
37688
|
-
" view",
|
|
37689
|
-
ad.impressions === 1 ? "" : "s"
|
|
37690
|
-
] })
|
|
37691
|
-
] }) : ad.status === "disabled" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.faint, children: [
|
|
37692
|
-
G.earn,
|
|
37693
|
-
" Earn off \xB7 /ads on"
|
|
37694
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Text, { color: C.warn, children: [
|
|
37695
|
-
G.earn,
|
|
37696
|
-
" /login to start earning"
|
|
37697
|
-
] }) })
|
|
37698
|
-
] })
|
|
39327
|
+
paletteOpen || leaving ? null : quitArmed ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box_default, { paddingX: 1, width, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: C.warn, children: "Press ctrl+c again to quit" }) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
39328
|
+
StatusPanel,
|
|
39329
|
+
{
|
|
39330
|
+
width,
|
|
39331
|
+
model: current?.name ?? state.model,
|
|
39332
|
+
variant: state.variant,
|
|
39333
|
+
provider: provider?.name,
|
|
39334
|
+
latent: (current?.providerID ?? parseKey(state.model)?.providerID) === LATENT_PROVIDER_ID,
|
|
39335
|
+
working: state.working,
|
|
39336
|
+
tokens: state.tokens.input + state.tokens.output,
|
|
39337
|
+
cost: state.cost,
|
|
39338
|
+
earn: ad.status,
|
|
39339
|
+
ad: ad.current,
|
|
39340
|
+
adIndex: ad.adIndex,
|
|
39341
|
+
visibleMs: ad.visibleMs,
|
|
39342
|
+
billed: ad.billed,
|
|
39343
|
+
verdict: ad.verdict,
|
|
39344
|
+
balance,
|
|
39345
|
+
sessionCredits: credits(ad.sessionEarned, bonus),
|
|
39346
|
+
views: ad.impressions,
|
|
39347
|
+
wallet: shortWallet(wallet),
|
|
39348
|
+
osc8Links: LINKS_OSC8
|
|
39349
|
+
}
|
|
39350
|
+
)
|
|
37699
39351
|
] });
|
|
37700
39352
|
}
|
|
37701
39353
|
|
|
37702
39354
|
// src/ui/Root.tsx
|
|
37703
|
-
var
|
|
39355
|
+
var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
|
|
37704
39356
|
function Root(p) {
|
|
37705
39357
|
const { exit } = use_app_default();
|
|
37706
39358
|
const { cols } = useTermSize();
|
|
37707
|
-
const [steps, setSteps] = (0,
|
|
37708
|
-
const [booted, setBooted] = (0,
|
|
37709
|
-
const [error, setError] = (0,
|
|
37710
|
-
(0,
|
|
37711
|
-
boot(p.args, p.focus, (id, patch) => setSteps((
|
|
39359
|
+
const [steps, setSteps] = (0, import_react28.useState)(BOOT_STEPS);
|
|
39360
|
+
const [booted, setBooted] = (0, import_react28.useState)(null);
|
|
39361
|
+
const [error, setError] = (0, import_react28.useState)("");
|
|
39362
|
+
(0, import_react28.useEffect)(() => {
|
|
39363
|
+
boot(p.args, p.focus, (id, patch) => setSteps((list2) => list2.map((s2) => s2.id === id ? { ...s2, ...patch } : s2))).then(setBooted).catch((e) => {
|
|
37712
39364
|
const message = e instanceof Error ? e.message : String(e);
|
|
37713
39365
|
setError(message);
|
|
37714
39366
|
p.onFatal(message);
|
|
@@ -37722,7 +39374,7 @@ function Root(p) {
|
|
|
37722
39374
|
{ isActive: !booted }
|
|
37723
39375
|
);
|
|
37724
39376
|
if (!booted) {
|
|
37725
|
-
return /* @__PURE__ */ (0,
|
|
39377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
37726
39378
|
BootCard,
|
|
37727
39379
|
{
|
|
37728
39380
|
steps,
|
|
@@ -37734,7 +39386,7 @@ function Root(p) {
|
|
|
37734
39386
|
}
|
|
37735
39387
|
);
|
|
37736
39388
|
}
|
|
37737
|
-
return /* @__PURE__ */ (0,
|
|
39389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PasteContext.Provider, { value: p.paste, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(App2, { ...booted, version: p.version, bootSteps: steps, summary: p.summary }) });
|
|
37738
39390
|
}
|
|
37739
39391
|
|
|
37740
39392
|
// src/ads/attention.ts
|
|
@@ -37784,6 +39436,27 @@ var FocusTracker = class {
|
|
|
37784
39436
|
}
|
|
37785
39437
|
};
|
|
37786
39438
|
|
|
39439
|
+
// src/ui/syncOutput.ts
|
|
39440
|
+
var BSU = "\x1B[?2026h";
|
|
39441
|
+
var ESU = "\x1B[?2026l";
|
|
39442
|
+
function wrapFrame(chunk) {
|
|
39443
|
+
if (typeof chunk === "string") return chunk ? BSU + chunk + ESU : chunk;
|
|
39444
|
+
if (!chunk.length) return chunk;
|
|
39445
|
+
return Buffer.concat([Buffer.from(BSU), chunk, Buffer.from(ESU)]);
|
|
39446
|
+
}
|
|
39447
|
+
function syncedStdout(stream = process.stdout, env3 = process.env) {
|
|
39448
|
+
if (env3.LATENTCODE_SYNC_OUTPUT === "off") return stream;
|
|
39449
|
+
return new Proxy(stream, {
|
|
39450
|
+
get(target, prop) {
|
|
39451
|
+
if (prop === "write") {
|
|
39452
|
+
return (chunk, ...rest) => target.write(wrapFrame(chunk), ...rest);
|
|
39453
|
+
}
|
|
39454
|
+
const v = Reflect.get(target, prop, target);
|
|
39455
|
+
return typeof v === "function" ? v.bind(target) : v;
|
|
39456
|
+
}
|
|
39457
|
+
});
|
|
39458
|
+
}
|
|
39459
|
+
|
|
37787
39460
|
// src/ui/stdin.ts
|
|
37788
39461
|
import { PassThrough as PassThrough2 } from "node:stream";
|
|
37789
39462
|
var PASTE_ENABLE = "\x1B[?2004h";
|
|
@@ -37928,9 +39601,109 @@ function row(mark, label2, value, width = 10) {
|
|
|
37928
39601
|
return ` ${mark} ${a.bold(label2.padEnd(width))} ${value}`;
|
|
37929
39602
|
}
|
|
37930
39603
|
|
|
39604
|
+
// src/mcpCli.ts
|
|
39605
|
+
import { spawnSync } from "node:child_process";
|
|
39606
|
+
var HELP = `${a.bold("latentcode mcp")} \u2014 MCP servers (shared with OpenCode)
|
|
39607
|
+
|
|
39608
|
+
latentcode mcp list status of every server
|
|
39609
|
+
latentcode mcp add <name> <url> a remote server (--header k=v)
|
|
39610
|
+
latentcode mcp add <name> -- <command\u2026> a local server (--env k=v)
|
|
39611
|
+
latentcode mcp remove <name> remove it from your config
|
|
39612
|
+
latentcode mcp auth [name] sign in to a server that needs it
|
|
39613
|
+
latentcode mcp logout <name> forget that sign-in
|
|
39614
|
+
|
|
39615
|
+
add writes the global OpenCode config; --project writes ./opencode.json instead.
|
|
39616
|
+
`;
|
|
39617
|
+
function engineBin() {
|
|
39618
|
+
const bin = resolveEngineBin();
|
|
39619
|
+
if (!bin) throw new EngineError(ENGINE_NOT_FOUND);
|
|
39620
|
+
return bin.path;
|
|
39621
|
+
}
|
|
39622
|
+
var COLOR = {
|
|
39623
|
+
connected: a.ok,
|
|
39624
|
+
pending: a.warn,
|
|
39625
|
+
needs_auth: a.warn,
|
|
39626
|
+
failed: a.err,
|
|
39627
|
+
disabled: a.dim
|
|
39628
|
+
};
|
|
39629
|
+
async function list(cwd2) {
|
|
39630
|
+
const engine = await Engine.start({ cwd: cwd2, bin: engineBin() });
|
|
39631
|
+
try {
|
|
39632
|
+
let servers = [];
|
|
39633
|
+
const start = Date.now();
|
|
39634
|
+
do {
|
|
39635
|
+
servers = await engine.mcpList().catch(() => []);
|
|
39636
|
+
const settled = servers.length ? servers.every((s2) => s2.status !== "pending") : Date.now() - start > 5e3;
|
|
39637
|
+
if (settled) break;
|
|
39638
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
39639
|
+
} while (Date.now() - start < 2e4);
|
|
39640
|
+
if (!servers.length) {
|
|
39641
|
+
process.stdout.write(`No MCP servers. Add one: latentcode mcp add <name> <url>
|
|
39642
|
+
`);
|
|
39643
|
+
return;
|
|
39644
|
+
}
|
|
39645
|
+
const w = Math.max(...servers.map((s2) => s2.name.length)) + 2;
|
|
39646
|
+
for (const s2 of servers) {
|
|
39647
|
+
const paint = COLOR[s2.status] ?? ((x) => x);
|
|
39648
|
+
process.stdout.write(`${paint("\u25CF")} ${s2.name.padEnd(w)}${paint(statusLabel(s2.status).padEnd(15))}${a.dim(s2.title ?? "")}
|
|
39649
|
+
`);
|
|
39650
|
+
if (s2.error) process.stdout.write(` ${a.dim(s2.error)}
|
|
39651
|
+
`);
|
|
39652
|
+
if (s2.status === "needs_auth") process.stdout.write(` ${a.dim(`sign in: latentcode mcp auth ${s2.name}`)}
|
|
39653
|
+
`);
|
|
39654
|
+
}
|
|
39655
|
+
} finally {
|
|
39656
|
+
engine.stop();
|
|
39657
|
+
}
|
|
39658
|
+
}
|
|
39659
|
+
async function mcpCommand(argv, cwd2 = process.cwd()) {
|
|
39660
|
+
const [sub, ...rest] = argv;
|
|
39661
|
+
switch (sub) {
|
|
39662
|
+
case void 0:
|
|
39663
|
+
case "list":
|
|
39664
|
+
case "ls":
|
|
39665
|
+
await list(cwd2);
|
|
39666
|
+
return 0;
|
|
39667
|
+
case "add": {
|
|
39668
|
+
const project = rest.includes("--project");
|
|
39669
|
+
const spec = parseMcpAdd(rest.filter((x) => x !== "--project"));
|
|
39670
|
+
const r = spawnSync(engineBin(), mcpAddArgv(spec, project ? "project" : "global"), { stdio: "inherit", cwd: cwd2 });
|
|
39671
|
+
return r.status ?? 1;
|
|
39672
|
+
}
|
|
39673
|
+
case "remove":
|
|
39674
|
+
case "rm": {
|
|
39675
|
+
const name = rest[0];
|
|
39676
|
+
if (!name) throw new Error("Which server? latentcode mcp remove <name>");
|
|
39677
|
+
const hit = removeMcpFromFiles(candidateConfigFiles(defaultConfigDir(), cwd2), name);
|
|
39678
|
+
if (!hit) {
|
|
39679
|
+
process.stderr.write(`No server "${name}" in your OpenCode config (global or this project).
|
|
39680
|
+
`);
|
|
39681
|
+
return 1;
|
|
39682
|
+
}
|
|
39683
|
+
process.stdout.write(`Removed ${name} from ${hit.file}${hit.backup ? ` (the original, with comments, is at ${hit.backup})` : ""}.
|
|
39684
|
+
`);
|
|
39685
|
+
return 0;
|
|
39686
|
+
}
|
|
39687
|
+
case "auth":
|
|
39688
|
+
case "logout": {
|
|
39689
|
+
const r = spawnSync(engineBin(), ["mcp", sub, ...rest, "--standalone"], { stdio: "inherit", cwd: cwd2 });
|
|
39690
|
+
return r.status ?? 1;
|
|
39691
|
+
}
|
|
39692
|
+
case "help":
|
|
39693
|
+
case "-h":
|
|
39694
|
+
case "--help":
|
|
39695
|
+
process.stdout.write(HELP);
|
|
39696
|
+
return 0;
|
|
39697
|
+
default:
|
|
39698
|
+
throw new Error(`unknown mcp command "${sub}"
|
|
39699
|
+
|
|
39700
|
+
${HELP}`);
|
|
39701
|
+
}
|
|
39702
|
+
}
|
|
39703
|
+
|
|
37931
39704
|
// src/index.tsx
|
|
37932
|
-
var
|
|
37933
|
-
var VERSION = "0.1.0-alpha.
|
|
39705
|
+
var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
|
|
39706
|
+
var VERSION = "0.1.0-alpha.10";
|
|
37934
39707
|
var usage = () => `${logo()}
|
|
37935
39708
|
${a.dim(`v${VERSION} \xB7 terminal coding agent. Bring your own model access; earn while it works.`)}
|
|
37936
39709
|
|
|
@@ -37940,6 +39713,7 @@ ${a.bold("Usage")}
|
|
|
37940
39713
|
latentcode status wallet, Earn mode, balance, engine
|
|
37941
39714
|
latentcode auth login connect a model provider from the shell
|
|
37942
39715
|
latentcode auth list|logout manage connected providers
|
|
39716
|
+
latentcode mcp list|add|remove MCP servers (shared with OpenCode)
|
|
37943
39717
|
|
|
37944
39718
|
${a.bold("Options")}
|
|
37945
39719
|
--model <provider/id> start with this model
|
|
@@ -37951,6 +39725,7 @@ ${a.bold("Options")}
|
|
|
37951
39725
|
${a.bold("Inside the app")}
|
|
37952
39726
|
/model switch model, filter by provider, set effort
|
|
37953
39727
|
/connect connect a provider (API key or account sign-in)
|
|
39728
|
+
/mcp MCP servers: status, sign in, add, remove
|
|
37954
39729
|
/login connect your wallet
|
|
37955
39730
|
/help every command and key
|
|
37956
39731
|
`;
|
|
@@ -37990,7 +39765,8 @@ function loginDeps() {
|
|
|
37990
39765
|
log: (l) => process.stdout.write(styleLoginLine(l) + "\n"),
|
|
37991
39766
|
open: openUrl,
|
|
37992
39767
|
load: loadConfig,
|
|
37993
|
-
save: (patch) => void saveConfig(patch)
|
|
39768
|
+
save: (patch) => void saveConfig(patch),
|
|
39769
|
+
deviceId: deviceKeyId
|
|
37994
39770
|
};
|
|
37995
39771
|
}
|
|
37996
39772
|
function styleLoginLine(l) {
|
|
@@ -38011,7 +39787,7 @@ ${usage()}`);
|
|
|
38011
39787
|
function auth(argv) {
|
|
38012
39788
|
const engine = resolveEngineBin();
|
|
38013
39789
|
if (!engine) throw new EngineError(ENGINE_NOT_FOUND);
|
|
38014
|
-
const r =
|
|
39790
|
+
const r = spawnSync2(engine.path, ["auth", ...argv.length ? argv : ["login"], "--standalone"], { stdio: "inherit" });
|
|
38015
39791
|
process.exit(r.status ?? 1);
|
|
38016
39792
|
}
|
|
38017
39793
|
async function status() {
|
|
@@ -38038,7 +39814,7 @@ async function status() {
|
|
|
38038
39814
|
if (wallet) {
|
|
38039
39815
|
const bal = await httpAdApi(server).balance(wallet);
|
|
38040
39816
|
lines.push(
|
|
38041
|
-
row(a.earn("\u25C6"), "
|
|
39817
|
+
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)")}`)
|
|
38042
39818
|
);
|
|
38043
39819
|
}
|
|
38044
39820
|
process.stdout.write(lines.join("\n") + "\n");
|
|
@@ -38047,7 +39823,7 @@ function goodbye(s2) {
|
|
|
38047
39823
|
const parts = s2.turns ? [`${s2.turns} turn${s2.turns === 1 ? "" : "s"}`] : [];
|
|
38048
39824
|
if (s2.tokens) parts.push(`${fmtTokens(s2.tokens)} tokens`);
|
|
38049
39825
|
if (s2.cost) parts.push(`$${s2.cost.toFixed(3)} model cost`);
|
|
38050
|
-
const earned = s2.impressions ? a.earn(`\u25C6 earned \u2248
|
|
39826
|
+
const earned = s2.impressions ? a.earn(`\u25C6 earned \u2248 ${s2.earned.toFixed(3)} credits from ${s2.impressions} view${s2.impressions === 1 ? "" : "s"}`) : "";
|
|
38051
39827
|
return ` ${a.dim(parts.join(" \xB7 "))}${earned ? ` ${earned}` : ""}
|
|
38052
39828
|
`;
|
|
38053
39829
|
}
|
|
@@ -38056,6 +39832,7 @@ async function main() {
|
|
|
38056
39832
|
if (argv[0] === "login") return login(argv.slice(1));
|
|
38057
39833
|
if (argv[0] === "status") return status();
|
|
38058
39834
|
if (argv[0] === "auth") return auth(argv.slice(1));
|
|
39835
|
+
if (argv[0] === "mcp") return process.exit(await mcpCommand(argv.slice(1)));
|
|
38059
39836
|
const args = parseArgs(argv);
|
|
38060
39837
|
const cwd2 = resolve(args.dir ?? process.cwd());
|
|
38061
39838
|
if (!process.stdin.isTTY) {
|
|
@@ -38070,7 +39847,7 @@ async function main() {
|
|
|
38070
39847
|
const summary = { current: { turns: 0, tokens: 0, cost: 0, earned: 0, impressions: 0 } };
|
|
38071
39848
|
let fatal = false;
|
|
38072
39849
|
const app = render_default(
|
|
38073
|
-
/* @__PURE__ */ (0,
|
|
39850
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
38074
39851
|
Root,
|
|
38075
39852
|
{
|
|
38076
39853
|
args: { cwd: cwd2, model: args.model, noAds: args.noAds, auto: args.auto },
|
|
@@ -38083,14 +39860,14 @@ async function main() {
|
|
|
38083
39860
|
}
|
|
38084
39861
|
}
|
|
38085
39862
|
),
|
|
38086
|
-
{ stdin, exitOnCtrlC: false }
|
|
39863
|
+
{ stdin, stdout: syncedStdout(), exitOnCtrlC: false }
|
|
38087
39864
|
);
|
|
38088
39865
|
await app.waitUntilExit();
|
|
38089
39866
|
if (!fatal && (summary.current.turns || summary.current.impressions)) process.stdout.write(goodbye(summary.current));
|
|
38090
39867
|
process.exit(fatal ? 1 : 0);
|
|
38091
39868
|
}
|
|
38092
39869
|
main().catch((e) => {
|
|
38093
|
-
const known = e instanceof EngineError || e instanceof Error && process.argv[2] && ["login", "status", "auth"].includes(process.argv[2]);
|
|
39870
|
+
const known = e instanceof EngineError || e instanceof Error && process.argv[2] && ["login", "status", "auth", "mcp"].includes(process.argv[2]);
|
|
38094
39871
|
process.stderr.write(`
|
|
38095
39872
|
${known ? e.message : e instanceof Error ? e.stack : String(e)}
|
|
38096
39873
|
`);
|