@gapi/gcli 1.8.263 → 1.8.265
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/.agents/skills/local-ai-runners/SKILL.md +11 -1
- package/README-CLI.md +94 -29
- package/README.md +41 -1
- package/docs/changelog.d/2026-11-15-local-ai-runners-one-runner-serves-several-model-servers-through-adapters-oll.md +43 -0
- package/docs/changelog.d/2026-11-17-lambda-spread-lambda-create-update-spread-and-spreadstrict-lambforge.yaml.md +16 -0
- package/docs/features/README.md +1 -0
- package/docs/features/lambda-spread.md +9 -0
- package/docs/features/local-ai-runners.md +55 -5
- package/package.json +1 -1
- package/release/index.js +550 -154
package/release/index.js
CHANGED
|
@@ -35511,16 +35511,16 @@ var require_encoder = __commonJS({
|
|
|
35511
35511
|
});
|
|
35512
35512
|
return bl(acc);
|
|
35513
35513
|
}
|
|
35514
|
-
function write64BitUint(buf, offset,
|
|
35515
|
-
const lo =
|
|
35516
|
-
const hi = Math.floor(
|
|
35514
|
+
function write64BitUint(buf, offset, num3) {
|
|
35515
|
+
const lo = num3 % 4294967296;
|
|
35516
|
+
const hi = Math.floor(num3 / 4294967296);
|
|
35517
35517
|
buf.writeUInt32BE(hi, offset + 0);
|
|
35518
35518
|
buf.writeUInt32BE(lo, offset + 4);
|
|
35519
35519
|
}
|
|
35520
|
-
function write64BitInt(buf, offset,
|
|
35521
|
-
const negate =
|
|
35522
|
-
|
|
35523
|
-
write64BitUint(buf, offset,
|
|
35520
|
+
function write64BitInt(buf, offset, num3) {
|
|
35521
|
+
const negate = num3 < 0;
|
|
35522
|
+
num3 = Math.abs(num3);
|
|
35523
|
+
write64BitUint(buf, offset, num3);
|
|
35524
35524
|
if (negate) negate64BitInt(buf, offset);
|
|
35525
35525
|
}
|
|
35526
35526
|
function negate64BitInt(buf, offset) {
|
|
@@ -183652,7 +183652,7 @@ ${lanes.join("\n")}
|
|
|
183652
183652
|
function createTabularErrorsDisplay(filesInError, host) {
|
|
183653
183653
|
const distinctFiles = filesInError.filter((value, index, self2) => index === self2.findIndex((file2) => (file2 == null ? void 0 : file2.fileName) === (value == null ? void 0 : value.fileName)));
|
|
183654
183654
|
if (distinctFiles.length === 0) return "";
|
|
183655
|
-
const numberLength = (
|
|
183655
|
+
const numberLength = (num3) => Math.log(num3) * Math.LOG10E + 1;
|
|
183656
183656
|
const fileToErrorCount = distinctFiles.map((file2) => [file2, countWhere(filesInError, (fileInError) => fileInError.fileName === file2.fileName)]);
|
|
183657
183657
|
const maxErrors = maxBy(fileToErrorCount, 0, (value) => value[1]);
|
|
183658
183658
|
const headerRow = Diagnostics.Errors_Files.message;
|
|
@@ -192781,7 +192781,7 @@ ${lanes.join("\n")}
|
|
|
192781
192781
|
search: (importingFile, preferCapitalized, matches, action) => {
|
|
192782
192782
|
if (importingFile !== usableByFileName) return;
|
|
192783
192783
|
return forEachEntry(exportInfo, (info, key2) => {
|
|
192784
|
-
const { symbolName: symbolName2, ambientModuleName } =
|
|
192784
|
+
const { symbolName: symbolName2, ambientModuleName } = parseKey2(key2);
|
|
192785
192785
|
const name2 = preferCapitalized && info[0].capitalizedSymbolName || symbolName2;
|
|
192786
192786
|
if (matches(name2, info[0].targetFlags)) {
|
|
192787
192787
|
const rehydrated = info.map(rehydrateCachedInfo);
|
|
@@ -192853,7 +192853,7 @@ ${lanes.join("\n")}
|
|
|
192853
192853
|
const moduleKey = ambientModuleName || "";
|
|
192854
192854
|
return `${importedName.length} ${getSymbolId(skipAlias(symbol2, checker))} ${importedName} ${moduleKey}`;
|
|
192855
192855
|
}
|
|
192856
|
-
function
|
|
192856
|
+
function parseKey2(key2) {
|
|
192857
192857
|
const firstSpace = key2.indexOf(" ");
|
|
192858
192858
|
const secondSpace = key2.indexOf(" ", firstSpace + 1);
|
|
192859
192859
|
const symbolNameLength = parseInt(key2.substring(0, firstSpace), 10);
|
|
@@ -206064,7 +206064,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
206064
206064
|
}
|
|
206065
206065
|
}
|
|
206066
206066
|
}
|
|
206067
|
-
function
|
|
206067
|
+
function collect2(node) {
|
|
206068
206068
|
if (!node) return;
|
|
206069
206069
|
if (node.flags & 33554432) {
|
|
206070
206070
|
return;
|
|
@@ -206073,7 +206073,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
206073
206073
|
if (isClassLike(node)) {
|
|
206074
206074
|
for (const member of node.members) {
|
|
206075
206075
|
if (member.name && isComputedPropertyName(member.name)) {
|
|
206076
|
-
|
|
206076
|
+
collect2(member.name.expression);
|
|
206077
206077
|
}
|
|
206078
206078
|
}
|
|
206079
206079
|
}
|
|
@@ -206092,105 +206092,105 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
206092
206092
|
return;
|
|
206093
206093
|
case 217:
|
|
206094
206094
|
case 235:
|
|
206095
|
-
|
|
206095
|
+
collect2(node.expression);
|
|
206096
206096
|
return;
|
|
206097
206097
|
case 261:
|
|
206098
206098
|
case 170:
|
|
206099
|
-
|
|
206100
|
-
|
|
206099
|
+
collect2(node.name);
|
|
206100
|
+
collect2(node.initializer);
|
|
206101
206101
|
return;
|
|
206102
206102
|
case 214:
|
|
206103
206103
|
recordCallSite(node);
|
|
206104
|
-
|
|
206105
|
-
forEach(node.arguments,
|
|
206104
|
+
collect2(node.expression);
|
|
206105
|
+
forEach(node.arguments, collect2);
|
|
206106
206106
|
return;
|
|
206107
206107
|
case 215:
|
|
206108
206108
|
recordCallSite(node);
|
|
206109
|
-
|
|
206110
|
-
forEach(node.arguments,
|
|
206109
|
+
collect2(node.expression);
|
|
206110
|
+
forEach(node.arguments, collect2);
|
|
206111
206111
|
return;
|
|
206112
206112
|
case 216:
|
|
206113
206113
|
recordCallSite(node);
|
|
206114
|
-
|
|
206115
|
-
|
|
206114
|
+
collect2(node.tag);
|
|
206115
|
+
collect2(node.template);
|
|
206116
206116
|
return;
|
|
206117
206117
|
case 287:
|
|
206118
206118
|
case 286:
|
|
206119
206119
|
recordCallSite(node);
|
|
206120
|
-
|
|
206121
|
-
|
|
206120
|
+
collect2(node.tagName);
|
|
206121
|
+
collect2(node.attributes);
|
|
206122
206122
|
return;
|
|
206123
206123
|
case 171:
|
|
206124
206124
|
recordCallSite(node);
|
|
206125
|
-
|
|
206125
|
+
collect2(node.expression);
|
|
206126
206126
|
return;
|
|
206127
206127
|
case 212:
|
|
206128
206128
|
case 213:
|
|
206129
206129
|
recordCallSite(node);
|
|
206130
|
-
forEachChild(node,
|
|
206130
|
+
forEachChild(node, collect2);
|
|
206131
206131
|
break;
|
|
206132
206132
|
case 239:
|
|
206133
|
-
|
|
206133
|
+
collect2(node.expression);
|
|
206134
206134
|
return;
|
|
206135
206135
|
}
|
|
206136
206136
|
if (isPartOfTypeNode(node)) {
|
|
206137
206137
|
return;
|
|
206138
206138
|
}
|
|
206139
|
-
forEachChild(node,
|
|
206139
|
+
forEachChild(node, collect2);
|
|
206140
206140
|
}
|
|
206141
|
-
return
|
|
206141
|
+
return collect2;
|
|
206142
206142
|
}
|
|
206143
|
-
function collectCallSitesOfSourceFile(node,
|
|
206144
|
-
forEach(node.statements,
|
|
206143
|
+
function collectCallSitesOfSourceFile(node, collect2) {
|
|
206144
|
+
forEach(node.statements, collect2);
|
|
206145
206145
|
}
|
|
206146
|
-
function collectCallSitesOfModuleDeclaration(node,
|
|
206146
|
+
function collectCallSitesOfModuleDeclaration(node, collect2) {
|
|
206147
206147
|
if (!hasSyntacticModifier(
|
|
206148
206148
|
node,
|
|
206149
206149
|
128
|
|
206150
206150
|
/* Ambient */
|
|
206151
206151
|
) && node.body && isModuleBlock(node.body)) {
|
|
206152
|
-
forEach(node.body.statements,
|
|
206152
|
+
forEach(node.body.statements, collect2);
|
|
206153
206153
|
}
|
|
206154
206154
|
}
|
|
206155
|
-
function collectCallSitesOfFunctionLikeDeclaration(typeChecker, node,
|
|
206155
|
+
function collectCallSitesOfFunctionLikeDeclaration(typeChecker, node, collect2) {
|
|
206156
206156
|
const implementation = findImplementation(typeChecker, node);
|
|
206157
206157
|
if (implementation) {
|
|
206158
|
-
forEach(implementation.parameters,
|
|
206159
|
-
|
|
206158
|
+
forEach(implementation.parameters, collect2);
|
|
206159
|
+
collect2(implementation.body);
|
|
206160
206160
|
}
|
|
206161
206161
|
}
|
|
206162
|
-
function collectCallSitesOfClassStaticBlockDeclaration(node,
|
|
206163
|
-
|
|
206162
|
+
function collectCallSitesOfClassStaticBlockDeclaration(node, collect2) {
|
|
206163
|
+
collect2(node.body);
|
|
206164
206164
|
}
|
|
206165
|
-
function collectCallSitesOfClassLikeDeclaration(node,
|
|
206166
|
-
forEach(node.modifiers,
|
|
206165
|
+
function collectCallSitesOfClassLikeDeclaration(node, collect2) {
|
|
206166
|
+
forEach(node.modifiers, collect2);
|
|
206167
206167
|
const heritage = getClassExtendsHeritageElement(node);
|
|
206168
206168
|
if (heritage) {
|
|
206169
|
-
|
|
206169
|
+
collect2(heritage.expression);
|
|
206170
206170
|
}
|
|
206171
206171
|
for (const member of node.members) {
|
|
206172
206172
|
if (canHaveModifiers(member)) {
|
|
206173
|
-
forEach(member.modifiers,
|
|
206173
|
+
forEach(member.modifiers, collect2);
|
|
206174
206174
|
}
|
|
206175
206175
|
if (isPropertyDeclaration(member)) {
|
|
206176
|
-
|
|
206176
|
+
collect2(member.initializer);
|
|
206177
206177
|
} else if (isConstructorDeclaration(member) && member.body) {
|
|
206178
|
-
forEach(member.parameters,
|
|
206179
|
-
|
|
206178
|
+
forEach(member.parameters, collect2);
|
|
206179
|
+
collect2(member.body);
|
|
206180
206180
|
} else if (isClassStaticBlockDeclaration(member)) {
|
|
206181
|
-
|
|
206181
|
+
collect2(member);
|
|
206182
206182
|
}
|
|
206183
206183
|
}
|
|
206184
206184
|
}
|
|
206185
206185
|
function collectCallSites(program2, node) {
|
|
206186
206186
|
const callSites = [];
|
|
206187
|
-
const
|
|
206187
|
+
const collect2 = createCallSiteCollector(program2, callSites);
|
|
206188
206188
|
switch (node.kind) {
|
|
206189
206189
|
case 308:
|
|
206190
|
-
collectCallSitesOfSourceFile(node,
|
|
206190
|
+
collectCallSitesOfSourceFile(node, collect2);
|
|
206191
206191
|
break;
|
|
206192
206192
|
case 268:
|
|
206193
|
-
collectCallSitesOfModuleDeclaration(node,
|
|
206193
|
+
collectCallSitesOfModuleDeclaration(node, collect2);
|
|
206194
206194
|
break;
|
|
206195
206195
|
case 263:
|
|
206196
206196
|
case 219:
|
|
@@ -206198,14 +206198,14 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
|
|
|
206198
206198
|
case 175:
|
|
206199
206199
|
case 178:
|
|
206200
206200
|
case 179:
|
|
206201
|
-
collectCallSitesOfFunctionLikeDeclaration(program2.getTypeChecker(), node,
|
|
206201
|
+
collectCallSitesOfFunctionLikeDeclaration(program2.getTypeChecker(), node, collect2);
|
|
206202
206202
|
break;
|
|
206203
206203
|
case 264:
|
|
206204
206204
|
case 232:
|
|
206205
|
-
collectCallSitesOfClassLikeDeclaration(node,
|
|
206205
|
+
collectCallSitesOfClassLikeDeclaration(node, collect2);
|
|
206206
206206
|
break;
|
|
206207
206207
|
case 176:
|
|
206208
|
-
collectCallSitesOfClassStaticBlockDeclaration(node,
|
|
206208
|
+
collectCallSitesOfClassStaticBlockDeclaration(node, collect2);
|
|
206209
206209
|
break;
|
|
206210
206210
|
default:
|
|
206211
206211
|
Debug.assertNever(node);
|
|
@@ -282314,9 +282314,9 @@ var require_buffer_crc32 = __commonJS({
|
|
|
282314
282314
|
throw new Error("input must be buffer, number, or string, received " + typeof input);
|
|
282315
282315
|
}
|
|
282316
282316
|
}
|
|
282317
|
-
function bufferizeInt(
|
|
282317
|
+
function bufferizeInt(num3) {
|
|
282318
282318
|
var tmp = ensureBuffer(4);
|
|
282319
|
-
tmp.writeInt32BE(
|
|
282319
|
+
tmp.writeInt32BE(num3, 0);
|
|
282320
282320
|
return tmp;
|
|
282321
282321
|
}
|
|
282322
282322
|
function _crc32(buf, previous) {
|
|
@@ -285417,9 +285417,9 @@ var require_headers = __commonJS({
|
|
|
285417
285417
|
}
|
|
285418
285418
|
return 0;
|
|
285419
285419
|
};
|
|
285420
|
-
var indexOf = function(block,
|
|
285420
|
+
var indexOf = function(block, num3, offset, end) {
|
|
285421
285421
|
for (; offset < end; offset++) {
|
|
285422
|
-
if (block[offset] ===
|
|
285422
|
+
if (block[offset] === num3) return offset;
|
|
285423
285423
|
}
|
|
285424
285424
|
return end;
|
|
285425
285425
|
};
|
|
@@ -288702,6 +288702,23 @@ var init_package = __esm({
|
|
|
288702
288702
|
}
|
|
288703
288703
|
});
|
|
288704
288704
|
|
|
288705
|
+
// src/commands/lambda/helpers/spread.ts
|
|
288706
|
+
function spreadScaleOptions(cmd, spec) {
|
|
288707
|
+
const spread = cmd.spread ?? spec?.spread;
|
|
288708
|
+
const strict = cmd.spreadStrict ?? spec?.spreadStrict;
|
|
288709
|
+
if (spread != null && !["none", "machines"].includes(String(spread))) {
|
|
288710
|
+
throw new Error(`--spread must be 'machines' or 'none' (got '${spread}')`);
|
|
288711
|
+
}
|
|
288712
|
+
return {
|
|
288713
|
+
...spread != null ? { spread: String(spread) } : {},
|
|
288714
|
+
...strict != null ? { spreadStrict: String(strict) === "true" } : {}
|
|
288715
|
+
};
|
|
288716
|
+
}
|
|
288717
|
+
var init_spread = __esm({
|
|
288718
|
+
"src/commands/lambda/helpers/spread.ts"() {
|
|
288719
|
+
}
|
|
288720
|
+
});
|
|
288721
|
+
|
|
288705
288722
|
// src/commands/lambda/helpers/index.ts
|
|
288706
288723
|
function streamToBufferPromise(file2) {
|
|
288707
288724
|
return new Promise((resolve2, reject) => {
|
|
@@ -288728,6 +288745,7 @@ var init_helpers2 = __esm({
|
|
|
288728
288745
|
init_package();
|
|
288729
288746
|
init_load_spec();
|
|
288730
288747
|
init_read_file();
|
|
288748
|
+
init_spread();
|
|
288731
288749
|
ReadFile2 = (file2) => readFileAsObservable(file2).pipe((0, import_operators18.catchError)(() => (0, import_rxjs35.of)("")));
|
|
288732
288750
|
createOrUpdateLambda = (cmd, type) => (0, import_rxjs35.lastValueFrom)(
|
|
288733
288751
|
parseProjectId(cmd.project).pipe(
|
|
@@ -288823,7 +288841,8 @@ var init_helpers2 = __esm({
|
|
|
288823
288841
|
// 500 / 60 / 120 here was refused on plans with lower maxima.
|
|
288824
288842
|
concurrency: cmd.concurrency || payload.scaleOptions?.concurrency || 0,
|
|
288825
288843
|
functionTimeout: cmd.functionTimeout || payload.scaleOptions?.functionTimeout || 0,
|
|
288826
|
-
specializationTimeout: cmd.specializationTimeout || payload.scaleOptions?.specializationTimeout || 0
|
|
288844
|
+
specializationTimeout: cmd.specializationTimeout || payload.scaleOptions?.specializationTimeout || 0,
|
|
288845
|
+
...spreadScaleOptions(cmd, payload.scaleOptions)
|
|
288827
288846
|
}
|
|
288828
288847
|
})
|
|
288829
288848
|
);
|
|
@@ -320697,44 +320716,6 @@ var init_delete2 = __esm({
|
|
|
320697
320716
|
}
|
|
320698
320717
|
});
|
|
320699
320718
|
|
|
320700
|
-
// src/commands/runner/config.ts
|
|
320701
|
-
var import_promises5, DEFAULT_WS_URL, deriveSubscriptionsUrl, readLoginApiUrl, readSavedRunner, saveRunner, forgetRunner;
|
|
320702
|
-
var init_config = __esm({
|
|
320703
|
-
"src/commands/runner/config.ts"() {
|
|
320704
|
-
import_promises5 = require("fs/promises");
|
|
320705
|
-
init_types();
|
|
320706
|
-
DEFAULT_WS_URL = "wss://api.lambforge.com/subscriptions";
|
|
320707
|
-
deriveSubscriptionsUrl = (apiUrl) => {
|
|
320708
|
-
if (!apiUrl?.trim()) {
|
|
320709
|
-
return DEFAULT_WS_URL;
|
|
320710
|
-
}
|
|
320711
|
-
const url2 = new URL(apiUrl.trim());
|
|
320712
|
-
if (["localhost", "127.0.0.1"].includes(url2.hostname) && url2.port === "9004") {
|
|
320713
|
-
return `ws://${url2.hostname}:9000/subscriptions`;
|
|
320714
|
-
}
|
|
320715
|
-
url2.protocol = url2.protocol === "http:" ? "ws:" : "wss:";
|
|
320716
|
-
url2.pathname = "/subscriptions";
|
|
320717
|
-
url2.search = "";
|
|
320718
|
-
return url2.toString();
|
|
320719
|
-
};
|
|
320720
|
-
readLoginApiUrl = () => (0, import_promises5.readFile)(urlDirectory, "utf-8").catch(() => "");
|
|
320721
|
-
readSavedRunner = async () => {
|
|
320722
|
-
try {
|
|
320723
|
-
const saved = JSON.parse(await (0, import_promises5.readFile)(runnerDirectory, "utf-8"));
|
|
320724
|
-
return saved?.id && saved?.token ? saved : null;
|
|
320725
|
-
} catch {
|
|
320726
|
-
return null;
|
|
320727
|
-
}
|
|
320728
|
-
};
|
|
320729
|
-
saveRunner = async (runner) => {
|
|
320730
|
-
await (0, import_promises5.mkdir)(mainDirectory, { recursive: true });
|
|
320731
|
-
await (0, import_promises5.writeFile)(runnerDirectory, JSON.stringify(runner, null, 2), "utf-8");
|
|
320732
|
-
await (0, import_promises5.chmod)(runnerDirectory, 384);
|
|
320733
|
-
};
|
|
320734
|
-
forgetRunner = () => (0, import_promises5.rm)(runnerDirectory, { force: true });
|
|
320735
|
-
}
|
|
320736
|
-
});
|
|
320737
|
-
|
|
320738
320719
|
// src/commands/runner/ollama.ts
|
|
320739
320720
|
var ALLOWED_REQUESTS, isAllowedRequest, resolveOllamaUrl, OllamaModels;
|
|
320740
320721
|
var init_ollama = __esm({
|
|
@@ -320847,6 +320828,273 @@ var init_ollama = __esm({
|
|
|
320847
320828
|
}
|
|
320848
320829
|
});
|
|
320849
320830
|
|
|
320831
|
+
// src/commands/runner/adapters/base.ts
|
|
320832
|
+
var HttpModelAdapter;
|
|
320833
|
+
var init_base2 = __esm({
|
|
320834
|
+
"src/commands/runner/adapters/base.ts"() {
|
|
320835
|
+
HttpModelAdapter = class {
|
|
320836
|
+
constructor(spec, deps = {}) {
|
|
320837
|
+
this.name = spec.name;
|
|
320838
|
+
this.kind = spec.kind;
|
|
320839
|
+
this.url = spec.url.replace(/\/+$/, "");
|
|
320840
|
+
this.apiKey = spec.apiKey;
|
|
320841
|
+
this.fetchFn = deps.fetchFn ?? fetch;
|
|
320842
|
+
}
|
|
320843
|
+
forward(method, path2, body, signal) {
|
|
320844
|
+
return this.fetchFn(`${this.url}${path2}`, {
|
|
320845
|
+
method,
|
|
320846
|
+
headers: this.headers({ "Content-Type": "application/json" }),
|
|
320847
|
+
body,
|
|
320848
|
+
signal
|
|
320849
|
+
});
|
|
320850
|
+
}
|
|
320851
|
+
headers(extra = {}) {
|
|
320852
|
+
return this.apiKey ? { ...extra, Authorization: `Bearer ${this.apiKey}` } : extra;
|
|
320853
|
+
}
|
|
320854
|
+
};
|
|
320855
|
+
}
|
|
320856
|
+
});
|
|
320857
|
+
|
|
320858
|
+
// src/commands/runner/adapters/ollama.ts
|
|
320859
|
+
var OllamaAdapter;
|
|
320860
|
+
var init_ollama2 = __esm({
|
|
320861
|
+
"src/commands/runner/adapters/ollama.ts"() {
|
|
320862
|
+
init_ollama();
|
|
320863
|
+
init_base2();
|
|
320864
|
+
OllamaAdapter = class extends HttpModelAdapter {
|
|
320865
|
+
constructor(spec, deps = {}) {
|
|
320866
|
+
super(spec, deps);
|
|
320867
|
+
this.models = new OllamaModels(this.url, this.fetchFn);
|
|
320868
|
+
}
|
|
320869
|
+
listModels() {
|
|
320870
|
+
return this.models.list();
|
|
320871
|
+
}
|
|
320872
|
+
};
|
|
320873
|
+
}
|
|
320874
|
+
});
|
|
320875
|
+
|
|
320876
|
+
// src/commands/runner/adapters/openai.ts
|
|
320877
|
+
var formatParams, num, OpenAIAdapter;
|
|
320878
|
+
var init_openai = __esm({
|
|
320879
|
+
"src/commands/runner/adapters/openai.ts"() {
|
|
320880
|
+
init_base2();
|
|
320881
|
+
formatParams = (n) => typeof n === "number" && n > 0 ? `${(n / 1e9).toFixed(n >= 1e10 ? 0 : 1)}B` : void 0;
|
|
320882
|
+
num = (v) => typeof v === "number" && v > 0 ? v : void 0;
|
|
320883
|
+
OpenAIAdapter = class extends HttpModelAdapter {
|
|
320884
|
+
async listModels() {
|
|
320885
|
+
const res = await this.fetchFn(`${this.url}/v1/models`, {
|
|
320886
|
+
headers: this.headers()
|
|
320887
|
+
});
|
|
320888
|
+
if (!res.ok) {
|
|
320889
|
+
throw new Error(`/v1/models returned ${res.status}`);
|
|
320890
|
+
}
|
|
320891
|
+
const { data = [] } = await res.json();
|
|
320892
|
+
const props = await this.props();
|
|
320893
|
+
const models = data.filter((m2) => typeof m2.id === "string" && m2.id);
|
|
320894
|
+
const kept = [];
|
|
320895
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
320896
|
+
for (const m2 of models) {
|
|
320897
|
+
const names = [m2.id, ...m2.aliases ?? []];
|
|
320898
|
+
if (names.some((n) => claimed.has(n))) {
|
|
320899
|
+
continue;
|
|
320900
|
+
}
|
|
320901
|
+
kept.push(m2);
|
|
320902
|
+
names.forEach((n) => claimed.add(n));
|
|
320903
|
+
}
|
|
320904
|
+
return kept.map((m2) => {
|
|
320905
|
+
const runtime = num(m2.max_model_len) ?? num(m2.meta?.n_ctx) ?? this.runningContext(props);
|
|
320906
|
+
return {
|
|
320907
|
+
name: m2.id,
|
|
320908
|
+
parameterSize: formatParams(m2.meta?.n_params),
|
|
320909
|
+
capabilities: this.capabilities(m2, props),
|
|
320910
|
+
contextLength: num(m2.meta?.n_ctx_train) ?? num(m2.context_length) ?? num(m2.max_model_len),
|
|
320911
|
+
// A llama.cpp server serves exactly one model, so /props applies to it.
|
|
320912
|
+
...runtime ? { runtimeContextLength: runtime } : {}
|
|
320913
|
+
};
|
|
320914
|
+
});
|
|
320915
|
+
}
|
|
320916
|
+
capabilities(model, props) {
|
|
320917
|
+
if (!props) {
|
|
320918
|
+
return [];
|
|
320919
|
+
}
|
|
320920
|
+
const caps = ["completion"];
|
|
320921
|
+
const tpl = props.chat_template_caps;
|
|
320922
|
+
if (tpl?.supports_tools || tpl?.supports_tool_calls) {
|
|
320923
|
+
caps.push("tools");
|
|
320924
|
+
}
|
|
320925
|
+
if (props.modalities?.vision || model.architecture?.input_modalities?.includes("image")) {
|
|
320926
|
+
caps.push("vision");
|
|
320927
|
+
}
|
|
320928
|
+
return caps;
|
|
320929
|
+
}
|
|
320930
|
+
runningContext(props) {
|
|
320931
|
+
return num(props?.default_generation_settings?.n_ctx) ?? num(props?.n_ctx);
|
|
320932
|
+
}
|
|
320933
|
+
async props() {
|
|
320934
|
+
try {
|
|
320935
|
+
const res = await this.fetchFn(`${this.url}/props`, {
|
|
320936
|
+
headers: this.headers()
|
|
320937
|
+
});
|
|
320938
|
+
return res.ok ? await res.json() : void 0;
|
|
320939
|
+
} catch {
|
|
320940
|
+
return void 0;
|
|
320941
|
+
}
|
|
320942
|
+
}
|
|
320943
|
+
};
|
|
320944
|
+
}
|
|
320945
|
+
});
|
|
320946
|
+
|
|
320947
|
+
// src/commands/runner/adapters/registry.ts
|
|
320948
|
+
var factories, registerAdapter, adapterKinds, hasAdapterKind, createAdapter;
|
|
320949
|
+
var init_registry = __esm({
|
|
320950
|
+
"src/commands/runner/adapters/registry.ts"() {
|
|
320951
|
+
init_ollama2();
|
|
320952
|
+
init_openai();
|
|
320953
|
+
factories = /* @__PURE__ */ new Map();
|
|
320954
|
+
registerAdapter = (kind, factory) => {
|
|
320955
|
+
factories.set(kind.toLowerCase(), factory);
|
|
320956
|
+
};
|
|
320957
|
+
adapterKinds = () => [...factories.keys()];
|
|
320958
|
+
hasAdapterKind = (kind) => factories.has(kind?.toLowerCase());
|
|
320959
|
+
createAdapter = (spec, deps = {}) => {
|
|
320960
|
+
const factory = factories.get(spec.kind?.toLowerCase());
|
|
320961
|
+
if (!factory) {
|
|
320962
|
+
throw new Error(
|
|
320963
|
+
`Unknown backend kind "${spec.kind}" for "${spec.name}" (known: ${adapterKinds().join(", ")})`
|
|
320964
|
+
);
|
|
320965
|
+
}
|
|
320966
|
+
return factory(spec, deps);
|
|
320967
|
+
};
|
|
320968
|
+
registerAdapter("ollama", (spec, deps) => new OllamaAdapter(spec, deps));
|
|
320969
|
+
registerAdapter("openai", (spec, deps) => new OpenAIAdapter(spec, deps));
|
|
320970
|
+
}
|
|
320971
|
+
});
|
|
320972
|
+
|
|
320973
|
+
// src/commands/runner/adapters/spec.ts
|
|
320974
|
+
var NAME2, normaliseUrl, parseBackendSpec, parseKey, apiKeyEnvVar, resolveBackends, describeBackends;
|
|
320975
|
+
var init_spec = __esm({
|
|
320976
|
+
"src/commands/runner/adapters/spec.ts"() {
|
|
320977
|
+
init_ollama();
|
|
320978
|
+
init_registry();
|
|
320979
|
+
NAME2 = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
320980
|
+
normaliseUrl = (raw) => {
|
|
320981
|
+
const withScheme = /^https?:\/\//.test(raw) ? raw : `http://${raw}`;
|
|
320982
|
+
const url2 = new URL(withScheme);
|
|
320983
|
+
if (url2.hostname === "0.0.0.0") {
|
|
320984
|
+
url2.hostname = "127.0.0.1";
|
|
320985
|
+
}
|
|
320986
|
+
return `${url2.origin}${url2.pathname.replace(/\/+$/, "")}`;
|
|
320987
|
+
};
|
|
320988
|
+
parseBackendSpec = (value) => {
|
|
320989
|
+
const eq = value.indexOf("=");
|
|
320990
|
+
if (eq < 1) {
|
|
320991
|
+
throw new Error(
|
|
320992
|
+
`--backend "${value}": expected <name>=<kind>:<url>, e.g. strata=openai:http://127.0.0.1:8080`
|
|
320993
|
+
);
|
|
320994
|
+
}
|
|
320995
|
+
const name2 = value.slice(0, eq).trim();
|
|
320996
|
+
let rest = value.slice(eq + 1).trim();
|
|
320997
|
+
if (!NAME2.test(name2)) {
|
|
320998
|
+
throw new Error(
|
|
320999
|
+
`--backend "${value}": the name may only use letters, digits, - and _`
|
|
321000
|
+
);
|
|
321001
|
+
}
|
|
321002
|
+
const kindMatch = /^([a-z][a-z0-9_-]*):(?!\/\/)/i.exec(rest);
|
|
321003
|
+
let kind = name2;
|
|
321004
|
+
if (kindMatch && hasAdapterKind(kindMatch[1])) {
|
|
321005
|
+
kind = kindMatch[1];
|
|
321006
|
+
rest = rest.slice(kindMatch[0].length);
|
|
321007
|
+
}
|
|
321008
|
+
if (!hasAdapterKind(kind)) {
|
|
321009
|
+
throw new Error(
|
|
321010
|
+
`--backend "${value}": unknown kind "${kind}" (known: ${adapterKinds().join(", ")})`
|
|
321011
|
+
);
|
|
321012
|
+
}
|
|
321013
|
+
if (!rest) {
|
|
321014
|
+
throw new Error(`--backend "${value}": missing URL`);
|
|
321015
|
+
}
|
|
321016
|
+
return { name: name2, kind: kind.toLowerCase(), url: normaliseUrl(rest) };
|
|
321017
|
+
};
|
|
321018
|
+
parseKey = (value) => {
|
|
321019
|
+
const eq = value.indexOf("=");
|
|
321020
|
+
if (eq < 1 || eq === value.length - 1) {
|
|
321021
|
+
throw new Error("--backend-key: expected <name>=<key>");
|
|
321022
|
+
}
|
|
321023
|
+
return [value.slice(0, eq).trim(), value.slice(eq + 1)];
|
|
321024
|
+
};
|
|
321025
|
+
apiKeyEnvVar = (name2) => `${name2.toUpperCase().replace(/-/g, "_")}_API_KEY`;
|
|
321026
|
+
resolveBackends = (cmd, saved, env = process.env) => {
|
|
321027
|
+
const ollamaUrl = () => resolveOllamaUrl(cmd.ollama || env.OLLAMA_HOST || "http://127.0.0.1:11434");
|
|
321028
|
+
let specs;
|
|
321029
|
+
if (cmd.backend?.length) {
|
|
321030
|
+
specs = cmd.backend.map(parseBackendSpec);
|
|
321031
|
+
if (cmd.ollama && !specs.some((s2) => s2.name === "ollama")) {
|
|
321032
|
+
specs.unshift({
|
|
321033
|
+
name: "ollama",
|
|
321034
|
+
kind: "ollama",
|
|
321035
|
+
url: ollamaUrl()
|
|
321036
|
+
});
|
|
321037
|
+
}
|
|
321038
|
+
} else if (saved?.length && !cmd.ollama) {
|
|
321039
|
+
specs = saved.map((s2) => ({ ...s2 }));
|
|
321040
|
+
} else {
|
|
321041
|
+
specs = [{ name: "ollama", kind: "ollama", url: ollamaUrl() }];
|
|
321042
|
+
}
|
|
321043
|
+
const keys = new Map((cmd.backendKey ?? []).map(parseKey));
|
|
321044
|
+
for (const name2 of keys.keys()) {
|
|
321045
|
+
if (!specs.some((s2) => s2.name === name2)) {
|
|
321046
|
+
throw new Error(`--backend-key ${name2}=...: no backend named "${name2}"`);
|
|
321047
|
+
}
|
|
321048
|
+
}
|
|
321049
|
+
return specs.map((spec) => {
|
|
321050
|
+
const apiKey = keys.get(spec.name) ?? env[apiKeyEnvVar(spec.name)] ?? spec.apiKey;
|
|
321051
|
+
return apiKey ? { ...spec, apiKey } : spec;
|
|
321052
|
+
});
|
|
321053
|
+
};
|
|
321054
|
+
describeBackends = (specs) => specs.map(
|
|
321055
|
+
(s2) => `${s2.name}${s2.kind === s2.name ? "" : ` (${s2.kind})`} ${s2.url}${s2.apiKey ? " [key]" : ""}`
|
|
321056
|
+
).join(", ");
|
|
321057
|
+
}
|
|
321058
|
+
});
|
|
321059
|
+
|
|
321060
|
+
// src/commands/runner/config.ts
|
|
321061
|
+
var import_promises5, DEFAULT_WS_URL, deriveSubscriptionsUrl, readLoginApiUrl, readSavedRunner, saveRunner, forgetRunner;
|
|
321062
|
+
var init_config = __esm({
|
|
321063
|
+
"src/commands/runner/config.ts"() {
|
|
321064
|
+
import_promises5 = require("fs/promises");
|
|
321065
|
+
init_types();
|
|
321066
|
+
DEFAULT_WS_URL = "wss://api.lambforge.com/subscriptions";
|
|
321067
|
+
deriveSubscriptionsUrl = (apiUrl) => {
|
|
321068
|
+
if (!apiUrl?.trim()) {
|
|
321069
|
+
return DEFAULT_WS_URL;
|
|
321070
|
+
}
|
|
321071
|
+
const url2 = new URL(apiUrl.trim());
|
|
321072
|
+
if (["localhost", "127.0.0.1"].includes(url2.hostname) && url2.port === "9004") {
|
|
321073
|
+
return `ws://${url2.hostname}:9000/subscriptions`;
|
|
321074
|
+
}
|
|
321075
|
+
url2.protocol = url2.protocol === "http:" ? "ws:" : "wss:";
|
|
321076
|
+
url2.pathname = "/subscriptions";
|
|
321077
|
+
url2.search = "";
|
|
321078
|
+
return url2.toString();
|
|
321079
|
+
};
|
|
321080
|
+
readLoginApiUrl = () => (0, import_promises5.readFile)(urlDirectory, "utf-8").catch(() => "");
|
|
321081
|
+
readSavedRunner = async () => {
|
|
321082
|
+
try {
|
|
321083
|
+
const saved = JSON.parse(await (0, import_promises5.readFile)(runnerDirectory, "utf-8"));
|
|
321084
|
+
return saved?.id && saved?.token ? saved : null;
|
|
321085
|
+
} catch {
|
|
321086
|
+
return null;
|
|
321087
|
+
}
|
|
321088
|
+
};
|
|
321089
|
+
saveRunner = async (runner) => {
|
|
321090
|
+
await (0, import_promises5.mkdir)(mainDirectory, { recursive: true });
|
|
321091
|
+
await (0, import_promises5.writeFile)(runnerDirectory, JSON.stringify(runner, null, 2), "utf-8");
|
|
321092
|
+
await (0, import_promises5.chmod)(runnerDirectory, 384);
|
|
321093
|
+
};
|
|
321094
|
+
forgetRunner = () => (0, import_promises5.rm)(runnerDirectory, { force: true });
|
|
321095
|
+
}
|
|
321096
|
+
});
|
|
321097
|
+
|
|
320850
321098
|
// src/commands/runner/tunnel.ts
|
|
320851
321099
|
var OPEN, SUBSCRIPTION_ID, MAX_CHUNK_CHARS, REQUESTS_SUBSCRIPTION, RESPOND_MUTATION, RunnerAuthError, describeError, FrameSender, TunnelConnection;
|
|
320852
321100
|
var init_tunnel = __esm({
|
|
@@ -321123,10 +321371,138 @@ var init_tunnel = __esm({
|
|
|
321123
321371
|
}
|
|
321124
321372
|
});
|
|
321125
321373
|
|
|
321374
|
+
// src/commands/runner/adapters/router.ts
|
|
321375
|
+
var ModelRouter;
|
|
321376
|
+
var init_router = __esm({
|
|
321377
|
+
"src/commands/runner/adapters/router.ts"() {
|
|
321378
|
+
init_tunnel();
|
|
321379
|
+
ModelRouter = class {
|
|
321380
|
+
constructor(adapters, logger) {
|
|
321381
|
+
this.adapters = adapters;
|
|
321382
|
+
this.logger = logger;
|
|
321383
|
+
this.routes = /* @__PURE__ */ new Map();
|
|
321384
|
+
this.reachable = /* @__PURE__ */ new Map();
|
|
321385
|
+
if (!adapters.length) {
|
|
321386
|
+
throw new Error("A runner needs at least one backend");
|
|
321387
|
+
}
|
|
321388
|
+
const names = adapters.map((a) => a.name);
|
|
321389
|
+
const dup = names.find((n, i2) => names.indexOf(n) !== i2);
|
|
321390
|
+
if (dup) {
|
|
321391
|
+
throw new Error(`Backend name "${dup}" is used twice`);
|
|
321392
|
+
}
|
|
321393
|
+
}
|
|
321394
|
+
get primary() {
|
|
321395
|
+
return this.adapters[0];
|
|
321396
|
+
}
|
|
321397
|
+
/** `strata/Qwen3` for a secondary adapter, the plain name for the primary. */
|
|
321398
|
+
exposedName(adapter, model) {
|
|
321399
|
+
return adapter === this.primary ? model : `${adapter.name}/${model}`;
|
|
321400
|
+
}
|
|
321401
|
+
/**
|
|
321402
|
+
* Every backend's models under their exposed names. A backend that can't be
|
|
321403
|
+
* reached contributes nothing this round (its models drop out of the
|
|
321404
|
+
* picker) without affecting the others; reachability changes are logged once.
|
|
321405
|
+
*/
|
|
321406
|
+
async listModels(announce = false) {
|
|
321407
|
+
const perAdapter = await Promise.all(
|
|
321408
|
+
this.adapters.map(async (adapter) => {
|
|
321409
|
+
try {
|
|
321410
|
+
const models = await adapter.listModels();
|
|
321411
|
+
if (this.reachable.get(adapter.name) === false || announce) {
|
|
321412
|
+
this.logger.info(
|
|
321413
|
+
`${this.label(adapter)}: ${models.length} model(s)`
|
|
321414
|
+
);
|
|
321415
|
+
}
|
|
321416
|
+
this.reachable.set(adapter.name, true);
|
|
321417
|
+
const routes = /* @__PURE__ */ new Map();
|
|
321418
|
+
for (const model of models) {
|
|
321419
|
+
routes.set(this.exposedName(adapter, model.name), {
|
|
321420
|
+
adapter,
|
|
321421
|
+
upstream: model.name
|
|
321422
|
+
});
|
|
321423
|
+
}
|
|
321424
|
+
this.routes.set(adapter.name, routes);
|
|
321425
|
+
return models.map((m2) => ({
|
|
321426
|
+
...m2,
|
|
321427
|
+
name: this.exposedName(adapter, m2.name)
|
|
321428
|
+
}));
|
|
321429
|
+
} catch (e2) {
|
|
321430
|
+
if (this.reachable.get(adapter.name) !== false) {
|
|
321431
|
+
this.logger.warn(
|
|
321432
|
+
`Cannot reach ${this.label(adapter)} (${describeError(e2)}). Is it running? Retrying...`
|
|
321433
|
+
);
|
|
321434
|
+
}
|
|
321435
|
+
this.reachable.set(adapter.name, false);
|
|
321436
|
+
return [];
|
|
321437
|
+
}
|
|
321438
|
+
})
|
|
321439
|
+
);
|
|
321440
|
+
const seen = /* @__PURE__ */ new Set();
|
|
321441
|
+
return perAdapter.flat().filter((m2) => {
|
|
321442
|
+
if (seen.has(m2.name)) {
|
|
321443
|
+
return false;
|
|
321444
|
+
}
|
|
321445
|
+
seen.add(m2.name);
|
|
321446
|
+
return true;
|
|
321447
|
+
});
|
|
321448
|
+
}
|
|
321449
|
+
/** True when at least one backend answered the last `listModels`. */
|
|
321450
|
+
get anyReachable() {
|
|
321451
|
+
return [...this.reachable.values()].some(Boolean);
|
|
321452
|
+
}
|
|
321453
|
+
/**
|
|
321454
|
+
* Which backend serves `model`, and the request body with the model renamed
|
|
321455
|
+
* to the backend's own name. Unknown models (e.g. a request racing the first
|
|
321456
|
+
* heartbeat) go to the backend named by the prefix, else to the primary,
|
|
321457
|
+
* unchanged.
|
|
321458
|
+
*/
|
|
321459
|
+
route(body) {
|
|
321460
|
+
let parsed;
|
|
321461
|
+
try {
|
|
321462
|
+
parsed = JSON.parse(body ?? "");
|
|
321463
|
+
} catch {
|
|
321464
|
+
parsed = void 0;
|
|
321465
|
+
}
|
|
321466
|
+
const model = typeof parsed?.model === "string" ? parsed.model : void 0;
|
|
321467
|
+
if (!model) {
|
|
321468
|
+
return { adapter: this.primary, body, model: "unknown model" };
|
|
321469
|
+
}
|
|
321470
|
+
const route = this.find(model);
|
|
321471
|
+
if (!route || route.upstream === model) {
|
|
321472
|
+
return { adapter: route?.adapter ?? this.primary, body, model };
|
|
321473
|
+
}
|
|
321474
|
+
return {
|
|
321475
|
+
adapter: route.adapter,
|
|
321476
|
+
body: JSON.stringify({ ...parsed, model: route.upstream }),
|
|
321477
|
+
model
|
|
321478
|
+
};
|
|
321479
|
+
}
|
|
321480
|
+
label(adapter) {
|
|
321481
|
+
const kind = adapter.kind === adapter.name ? "" : ` (${adapter.kind})`;
|
|
321482
|
+
return `${adapter.name}${kind} at ${adapter.url}`;
|
|
321483
|
+
}
|
|
321484
|
+
find(model) {
|
|
321485
|
+
for (const routes of this.routes.values()) {
|
|
321486
|
+
const route = routes.get(model);
|
|
321487
|
+
if (route) {
|
|
321488
|
+
return route;
|
|
321489
|
+
}
|
|
321490
|
+
}
|
|
321491
|
+
const adapter = this.adapters.find(
|
|
321492
|
+
(a) => a !== this.primary && model.startsWith(`${a.name}/`)
|
|
321493
|
+
);
|
|
321494
|
+
return adapter ? { adapter, upstream: model.slice(adapter.name.length + 1) } : void 0;
|
|
321495
|
+
}
|
|
321496
|
+
};
|
|
321497
|
+
}
|
|
321498
|
+
});
|
|
321499
|
+
|
|
321126
321500
|
// src/commands/runner/connection.ts
|
|
321127
321501
|
var HEARTBEAT_MUTATION, RunnerConnection;
|
|
321128
321502
|
var init_connection = __esm({
|
|
321129
321503
|
"src/commands/runner/connection.ts"() {
|
|
321504
|
+
init_registry();
|
|
321505
|
+
init_router();
|
|
321130
321506
|
init_ollama();
|
|
321131
321507
|
init_tunnel();
|
|
321132
321508
|
HEARTBEAT_MUTATION = `mutation runnerHeartbeat($models: [LocalRunnerModelInput], $runnerVersion: String) {
|
|
@@ -321137,8 +321513,18 @@ var init_connection = __esm({
|
|
|
321137
321513
|
super(options);
|
|
321138
321514
|
this.options = options;
|
|
321139
321515
|
this.announcedModels = "";
|
|
321140
|
-
|
|
321141
|
-
|
|
321516
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
321517
|
+
const specs = options.backends?.length ? options.backends : [
|
|
321518
|
+
{
|
|
321519
|
+
name: "ollama",
|
|
321520
|
+
kind: "ollama",
|
|
321521
|
+
url: options.ollamaUrl ?? "http://127.0.0.1:11434"
|
|
321522
|
+
}
|
|
321523
|
+
];
|
|
321524
|
+
this.router = new ModelRouter(
|
|
321525
|
+
options.adapters?.length ? options.adapters : specs.map((spec) => createAdapter(spec, { fetchFn })),
|
|
321526
|
+
options.logger
|
|
321527
|
+
);
|
|
321142
321528
|
}
|
|
321143
321529
|
connectionParams() {
|
|
321144
321530
|
return { runnerToken: this.options.token };
|
|
@@ -321154,27 +321540,9 @@ var init_connection = __esm({
|
|
|
321154
321540
|
);
|
|
321155
321541
|
}
|
|
321156
321542
|
async heartbeat(announce) {
|
|
321157
|
-
|
|
321158
|
-
|
|
321159
|
-
|
|
321160
|
-
if (this.ollamaReachable === false || announce) {
|
|
321161
|
-
this.options.logger.info(
|
|
321162
|
-
`Ollama at ${this.options.ollamaUrl}: ${models.length} model(s)`
|
|
321163
|
-
);
|
|
321164
|
-
}
|
|
321165
|
-
this.ollamaReachable = true;
|
|
321166
|
-
} catch (e2) {
|
|
321167
|
-
if (this.ollamaReachable !== false) {
|
|
321168
|
-
this.options.logger.warn(
|
|
321169
|
-
`Cannot reach Ollama at ${this.options.ollamaUrl} (${describeError(e2)}). Is it running? Retrying...`
|
|
321170
|
-
);
|
|
321171
|
-
}
|
|
321172
|
-
this.ollamaReachable = false;
|
|
321173
|
-
}
|
|
321174
|
-
const names = JSON.stringify(
|
|
321175
|
-
models.map((m2) => m2.name)
|
|
321176
|
-
);
|
|
321177
|
-
if (!announce && names !== this.announcedModels && this.ollamaReachable) {
|
|
321543
|
+
const models = await this.router.listModels(announce);
|
|
321544
|
+
const names = JSON.stringify(models.map((m2) => m2.name));
|
|
321545
|
+
if (!announce && names !== this.announcedModels && this.router.anyReachable) {
|
|
321178
321546
|
this.options.logger.info(
|
|
321179
321547
|
`Models: ${models.map((m2) => m2.name).join(", ") || "(none)"}`
|
|
321180
321548
|
);
|
|
@@ -321191,17 +321559,15 @@ var init_connection = __esm({
|
|
|
321191
321559
|
}
|
|
321192
321560
|
async serve(request, sender, signal) {
|
|
321193
321561
|
const started = Date.now();
|
|
321194
|
-
const model = this.
|
|
321195
|
-
this.
|
|
321562
|
+
const { adapter, body, model } = this.router.route(request.body);
|
|
321563
|
+
const via = this.router.adapters.length > 1 ? ` via ${adapter.name}` : "";
|
|
321564
|
+
this.options.logger.info(`-> chat request (${model})${via}`);
|
|
321196
321565
|
try {
|
|
321197
|
-
const response = await
|
|
321198
|
-
|
|
321199
|
-
|
|
321200
|
-
|
|
321201
|
-
|
|
321202
|
-
body: request.body,
|
|
321203
|
-
signal
|
|
321204
|
-
}
|
|
321566
|
+
const response = await adapter.forward(
|
|
321567
|
+
request.method,
|
|
321568
|
+
request.path,
|
|
321569
|
+
body,
|
|
321570
|
+
signal
|
|
321205
321571
|
);
|
|
321206
321572
|
sender.push({
|
|
321207
321573
|
type: "head",
|
|
@@ -321236,18 +321602,11 @@ var init_connection = __esm({
|
|
|
321236
321602
|
this.options.logger.error(`x ${reason}`);
|
|
321237
321603
|
sender.push({
|
|
321238
321604
|
type: "error",
|
|
321239
|
-
error: /fetch failed|ECONNREFUSED/.test(reason) ? `Could not reach
|
|
321605
|
+
error: /fetch failed|ECONNREFUSED/.test(reason) ? `Could not reach ${this.router.label(adapter)} on the runner machine - is it running?` : reason
|
|
321240
321606
|
});
|
|
321241
321607
|
}
|
|
321242
321608
|
}
|
|
321243
321609
|
}
|
|
321244
|
-
modelOf(body) {
|
|
321245
|
-
try {
|
|
321246
|
-
return JSON.parse(body ?? "{}").model ?? "unknown model";
|
|
321247
|
-
} catch {
|
|
321248
|
-
return "unknown model";
|
|
321249
|
-
}
|
|
321250
|
-
}
|
|
321251
321610
|
};
|
|
321252
321611
|
}
|
|
321253
321612
|
});
|
|
@@ -321413,10 +321772,10 @@ var init_start2 = __esm({
|
|
|
321413
321772
|
import_rxjs52 = __toESM(require_cjs());
|
|
321414
321773
|
init_gql_client();
|
|
321415
321774
|
init_log();
|
|
321775
|
+
init_spec();
|
|
321416
321776
|
init_config();
|
|
321417
321777
|
init_connection();
|
|
321418
321778
|
init_daemon();
|
|
321419
|
-
init_ollama();
|
|
321420
321779
|
RUNNER_VERSION = "gcli-runner/1";
|
|
321421
321780
|
resolveRunner = async (cmd) => {
|
|
321422
321781
|
if (cmd.token) {
|
|
@@ -321444,20 +321803,20 @@ var init_start2 = __esm({
|
|
|
321444
321803
|
};
|
|
321445
321804
|
start_default = async (cmd) => {
|
|
321446
321805
|
const runner = await resolveRunner(cmd);
|
|
321447
|
-
const
|
|
321806
|
+
const backends = resolveBackends(cmd, runner.backends);
|
|
321448
321807
|
const wsUrl = cmd.wsUrl || runner.wsUrl || deriveSubscriptionsUrl(await readLoginApiUrl());
|
|
321449
321808
|
Logger.log("-------------------");
|
|
321450
321809
|
Logger.log("[Lambforge local AI runner]");
|
|
321451
321810
|
Logger.info(`Lambforge: ${wsUrl}`);
|
|
321452
|
-
Logger.info(`
|
|
321811
|
+
Logger.info(`Backends: ${describeBackends(backends)}`);
|
|
321453
321812
|
Logger.info(
|
|
321454
|
-
"Tip: agent mode sends large prompts (instructions + tool list). Give
|
|
321813
|
+
"Tip: agent mode sends large prompts (instructions + tool list). Give your model server a big context window, e.g. start Ollama with OLLAMA_CONTEXT_LENGTH=32768."
|
|
321455
321814
|
);
|
|
321456
321815
|
Logger.log("-------------------");
|
|
321457
321816
|
const connection = new RunnerConnection({
|
|
321458
321817
|
wsUrl,
|
|
321459
321818
|
token: runner.token,
|
|
321460
|
-
|
|
321819
|
+
backends,
|
|
321461
321820
|
version: RUNNER_VERSION,
|
|
321462
321821
|
logger: Logger
|
|
321463
321822
|
});
|
|
@@ -321497,6 +321856,7 @@ var init_daemon_commands = __esm({
|
|
|
321497
321856
|
"src/commands/runner/daemon-commands.ts"() {
|
|
321498
321857
|
import_child_process5 = require("child_process");
|
|
321499
321858
|
init_log();
|
|
321859
|
+
init_spec();
|
|
321500
321860
|
init_config();
|
|
321501
321861
|
init_daemon();
|
|
321502
321862
|
init_ollama();
|
|
@@ -321508,12 +321868,11 @@ var init_daemon_commands = __esm({
|
|
|
321508
321868
|
if (warning) {
|
|
321509
321869
|
Logger.warn(warning);
|
|
321510
321870
|
}
|
|
321511
|
-
const
|
|
321871
|
+
const backends = cmd.backend?.length ? resolveBackends(cmd) : void 0;
|
|
321512
321872
|
const execStart = [
|
|
321513
321873
|
...command,
|
|
321514
321874
|
"runner:start",
|
|
321515
|
-
"--ollama",
|
|
321516
|
-
ollamaUrl,
|
|
321875
|
+
...backends ? [] : ["--ollama", resolveOllamaUrl(cmd.ollama)],
|
|
321517
321876
|
...cmd.wsUrl ? ["--wsUrl", cmd.wsUrl] : []
|
|
321518
321877
|
];
|
|
321519
321878
|
const unit = buildUnit({ serviceName, execStart });
|
|
@@ -321536,6 +321895,15 @@ var init_daemon_commands = __esm({
|
|
|
321536
321895
|
await resolveRunner({ name: cmd.name, reset: cmd.reset });
|
|
321537
321896
|
}
|
|
321538
321897
|
const runner = await readSavedRunner();
|
|
321898
|
+
if (runner) {
|
|
321899
|
+
delete runner.backends;
|
|
321900
|
+
await saveRunner(backends ? { ...runner, backends } : runner);
|
|
321901
|
+
}
|
|
321902
|
+
if (backends) {
|
|
321903
|
+
Logger.info(
|
|
321904
|
+
`Backends saved to the runner config: ${describeBackends(backends)}`
|
|
321905
|
+
);
|
|
321906
|
+
}
|
|
321539
321907
|
const systemd = new SystemdUserService(serviceName);
|
|
321540
321908
|
const path2 = await systemd.install(unit);
|
|
321541
321909
|
Logger.log(
|
|
@@ -323844,7 +324212,7 @@ ${this.text}` : this.text;
|
|
|
323844
324212
|
});
|
|
323845
324213
|
|
|
323846
324214
|
// src/commands/workspace/connection.ts
|
|
323847
|
-
var import_os7, WORKSPACE_PATH_PREFIX, WORKSPACE_OPS, HEARTBEAT_MUTATION2, REQUEST_APPROVAL_MUTATION, SETTLE_APPROVAL_MUTATION, str,
|
|
324215
|
+
var import_os7, WORKSPACE_PATH_PREFIX, WORKSPACE_OPS, HEARTBEAT_MUTATION2, REQUEST_APPROVAL_MUTATION, SETTLE_APPROVAL_MUTATION, str, num2, short, WorkspaceConnection;
|
|
323848
324216
|
var init_connection2 = __esm({
|
|
323849
324217
|
"src/commands/workspace/connection.ts"() {
|
|
323850
324218
|
import_os7 = require("os");
|
|
@@ -323877,7 +324245,7 @@ var init_connection2 = __esm({
|
|
|
323877
324245
|
settleLocalWorkspaceApproval(approvalId: $approvalId, decision: $decision) { status }
|
|
323878
324246
|
}`;
|
|
323879
324247
|
str = (v) => typeof v === "string" ? v : void 0;
|
|
323880
|
-
|
|
324248
|
+
num2 = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
323881
324249
|
short = (text, max = 100) => text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
|
|
323882
324250
|
WorkspaceConnection = class extends TunnelConnection {
|
|
323883
324251
|
constructor(options) {
|
|
@@ -324011,14 +324379,14 @@ var init_connection2 = __esm({
|
|
|
324011
324379
|
return this.files.list({
|
|
324012
324380
|
path: str(args.path),
|
|
324013
324381
|
recursive: args.recursive !== false,
|
|
324014
|
-
limit:
|
|
324382
|
+
limit: num2(args.limit)
|
|
324015
324383
|
});
|
|
324016
324384
|
case "read":
|
|
324017
324385
|
log2(`-> read ${str(args.path)}`);
|
|
324018
324386
|
return this.files.read({
|
|
324019
324387
|
path: str(args.path),
|
|
324020
|
-
startLine:
|
|
324021
|
-
endLine:
|
|
324388
|
+
startLine: num2(args.startLine),
|
|
324389
|
+
endLine: num2(args.endLine)
|
|
324022
324390
|
});
|
|
324023
324391
|
case "search":
|
|
324024
324392
|
log2(`-> search /${str(args.pattern)}/ in ${str(args.path) ?? "."}`);
|
|
@@ -324028,7 +324396,7 @@ var init_connection2 = __esm({
|
|
|
324028
324396
|
glob: str(args.glob),
|
|
324029
324397
|
regex: args.regex !== false,
|
|
324030
324398
|
caseSensitive: args.caseSensitive === true,
|
|
324031
|
-
maxResults:
|
|
324399
|
+
maxResults: num2(args.maxResults)
|
|
324032
324400
|
});
|
|
324033
324401
|
case "write": {
|
|
324034
324402
|
const result = await this.files.write({
|
|
@@ -324064,8 +324432,8 @@ var init_connection2 = __esm({
|
|
|
324064
324432
|
case "process/logs":
|
|
324065
324433
|
return this.processes.logs({
|
|
324066
324434
|
processId: str(args.processId),
|
|
324067
|
-
tail:
|
|
324068
|
-
sinceLine:
|
|
324435
|
+
tail: num2(args.tail),
|
|
324436
|
+
sinceLine: num2(args.sinceLine)
|
|
324069
324437
|
});
|
|
324070
324438
|
case "process/stop": {
|
|
324071
324439
|
const result = await this.processes.stop({
|
|
@@ -324106,7 +324474,7 @@ var init_connection2 = __esm({
|
|
|
324106
324474
|
command,
|
|
324107
324475
|
cwd,
|
|
324108
324476
|
displayCwd,
|
|
324109
|
-
timeoutSeconds:
|
|
324477
|
+
timeoutSeconds: num2(args.timeoutSeconds),
|
|
324110
324478
|
env: buildEnv(this.options, { CI: "1" }),
|
|
324111
324479
|
signal
|
|
324112
324480
|
});
|
|
@@ -324125,7 +324493,7 @@ var init_connection2 = __esm({
|
|
|
324125
324493
|
displayCwd,
|
|
324126
324494
|
name: str(args.name),
|
|
324127
324495
|
waitFor: str(args.waitFor),
|
|
324128
|
-
waitSeconds:
|
|
324496
|
+
waitSeconds: num2(args.waitSeconds),
|
|
324129
324497
|
env: buildEnv(this.options),
|
|
324130
324498
|
signal
|
|
324131
324499
|
});
|
|
@@ -324815,6 +325183,14 @@ function registerLambdaCommands(program2) {
|
|
|
324815
325183
|
[
|
|
324816
325184
|
"--specializationTimeout <specializationTimeout>",
|
|
324817
325185
|
"Timeout for executor to wait for function pod creation"
|
|
325186
|
+
],
|
|
325187
|
+
[
|
|
325188
|
+
"--spread <spread>",
|
|
325189
|
+
"Where the replicas run (newdeploy): 'machines' = on different machines of the cluster, as evenly as possible; 'none' = the scheduler decides"
|
|
325190
|
+
],
|
|
325191
|
+
[
|
|
325192
|
+
"--spreadStrict <spreadStrict>",
|
|
325193
|
+
"With --spread machines: 'true' = a replica waits rather than share a machine; 'false' (default) = prefer different machines, never block a scale-up"
|
|
324818
325194
|
]
|
|
324819
325195
|
];
|
|
324820
325196
|
createCommand("lambda:create")(createOrUpdateOptions)(program2).action(
|
|
@@ -324901,9 +325277,13 @@ function registerRabbitMqCommands(program2) {
|
|
|
324901
325277
|
|
|
324902
325278
|
// src/commands/runner/index.ts
|
|
324903
325279
|
init_helpers();
|
|
325280
|
+
var collect = (value, previous = []) => [
|
|
325281
|
+
...previous,
|
|
325282
|
+
value
|
|
325283
|
+
];
|
|
324904
325284
|
function registerRunnerCommands(program2) {
|
|
324905
325285
|
program2.command("runner:start").description(
|
|
324906
|
-
"Connect this machine's Ollama to the Lambforge chat as a local AI runner (outbound connection only - works behind NAT,
|
|
325286
|
+
"Connect this machine's model servers (Ollama, Strata or any OpenAI-compatible server) to the Lambforge chat as a local AI runner (outbound connection only - works behind NAT, nothing is exposed)"
|
|
324907
325287
|
).option(
|
|
324908
325288
|
"-n, --name <name>",
|
|
324909
325289
|
"Runner name shown in the chat model picker (default: hostname)"
|
|
@@ -324913,6 +325293,14 @@ function registerRunnerCommands(program2) {
|
|
|
324913
325293
|
).option(
|
|
324914
325294
|
"--ollama <url>",
|
|
324915
325295
|
"Ollama URL (default: $OLLAMA_HOST or http://127.0.0.1:11434)"
|
|
325296
|
+
).option(
|
|
325297
|
+
"--backend <name=kind:url>",
|
|
325298
|
+
"Model server to serve from, repeatable; kinds: ollama, openai (Strata, llama-server, LM Studio, vLLM). E.g. --backend strata=openai:http://127.0.0.1:8080. With --ollama, Ollama comes first",
|
|
325299
|
+
collect
|
|
325300
|
+
).option(
|
|
325301
|
+
"--backend-key <name=key>",
|
|
325302
|
+
"API key for a backend, repeatable (default: $<NAME>_API_KEY, e.g. $STRATA_API_KEY)",
|
|
325303
|
+
collect
|
|
324916
325304
|
).option("--wsUrl <url>", "Lambforge subscriptions endpoint override").option("--reset", "Forget the saved runner and register a new one").action(lazy(() => Promise.resolve().then(() => (init_start2(), start_exports2)).then((m2) => m2.default)));
|
|
324917
325305
|
program2.command("runner:daemon:install").alias("runner:start:daemon").description(
|
|
324918
325306
|
"Run the runner in the background as a systemd user service: starts with your session, restarts on failure (Linux)"
|
|
@@ -324925,6 +325313,14 @@ function registerRunnerCommands(program2) {
|
|
|
324925
325313
|
).option(
|
|
324926
325314
|
"--ollama <url>",
|
|
324927
325315
|
"Ollama URL (default: $OLLAMA_HOST or http://127.0.0.1:11434)"
|
|
325316
|
+
).option(
|
|
325317
|
+
"--backend <name=kind:url>",
|
|
325318
|
+
"Model server to serve from, repeatable; kinds: ollama, openai (Strata, llama-server, LM Studio, vLLM). E.g. --backend strata=openai:http://127.0.0.1:8080. With --ollama, Ollama comes first",
|
|
325319
|
+
collect
|
|
325320
|
+
).option(
|
|
325321
|
+
"--backend-key <name=key>",
|
|
325322
|
+
"API key for a backend, repeatable (default: $<NAME>_API_KEY, e.g. $STRATA_API_KEY)",
|
|
325323
|
+
collect
|
|
324928
325324
|
).option("--wsUrl <url>", "Lambforge subscriptions endpoint override").option("--reset", "Forget the saved runner and register a new one").option("--service <name>", "systemd unit name (default: lambforge-runner)").option("--dry-run", "Print the unit file instead of installing it").action(lazy(() => Promise.resolve().then(() => (init_daemon_commands(), daemon_commands_exports)).then((m2) => m2.install)));
|
|
324929
325325
|
program2.command("runner:daemon:status").description("Show the runner service status (systemctl --user status)").option("--service <name>", "systemd unit name (default: lambforge-runner)").action(lazy(() => Promise.resolve().then(() => (init_daemon_commands(), daemon_commands_exports)).then((m2) => m2.status)));
|
|
324930
325326
|
program2.command("runner:daemon:start").description(
|