blun-king-cli 9.1.651 → 9.1.652
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/LIESMICH.txt +3 -3
- package/README.md +3 -3
- package/blun.mjs +523 -170
- package/package.json +1 -1
- package/worker-host.mjs +468 -125
package/worker-host.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// BLUN_BUILD_INPUT_SHA256:
|
|
2
|
+
// BLUN_BUILD_INPUT_SHA256:eb9ff5c11e4d39258f3ee406617ae870eb89e80c7311e5c8e6c81b578c4432a1
|
|
3
3
|
import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname as __cjsShimDirname } from 'node:path';
|
|
5
5
|
const __filename = __cjsShimFileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = __cjsShimDirname(__filename);
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import crypto$1, { createHash, randomBytes, randomInt, randomUUID } from "node:crypto";
|
|
9
|
-
import * as fs$
|
|
9
|
+
import * as fs$11 from "node:fs";
|
|
10
10
|
import Vt, { appendFileSync, chmodSync, closeSync, constants, createReadStream, createWriteStream, existsSync, fsyncSync, mkdirSync, openSync, promises, readFileSync, readSync, readdirSync, renameSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
11
11
|
import * as path$10 from "node:path";
|
|
12
12
|
import path, { basename, dirname, isAbsolute, join, parse, posix, relative, resolve, sep, win32 } from "node:path";
|
|
@@ -20,7 +20,7 @@ import { EventEmitter } from "node:events";
|
|
|
20
20
|
import { TextDecoder as TextDecoder$1 } from "node:util";
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23
|
-
import
|
|
23
|
+
import jn, { access, appendFile, chmod, copyFile, cp, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
24
24
|
import * as nodeOs from "node:os";
|
|
25
25
|
import os, { arch, homedir, hostname, release, tmpdir, type, userInfo } from "node:os";
|
|
26
26
|
import Kr, { EventEmitter as EventEmitter$1 } from "events";
|
|
@@ -23557,11 +23557,11 @@ var BlunFiles = class {
|
|
|
23557
23557
|
signal?.throwIfAborted();
|
|
23558
23558
|
let file;
|
|
23559
23559
|
if (typeof input === "string") {
|
|
23560
|
-
if (!fs$
|
|
23560
|
+
if (!fs$11.existsSync(input)) throw new ChatProviderError(`Video file not found: ${input}`);
|
|
23561
23561
|
const filename = path$10.basename(input);
|
|
23562
23562
|
const mimeType = guessMimeTypeFromExt(filename);
|
|
23563
23563
|
if (mimeType === void 0 || !mimeType.startsWith("video/")) throw new ChatProviderError(`BlunFiles.uploadVideo: file extension does not indicate a video type: ${filename}`);
|
|
23564
|
-
const data = await fs$
|
|
23564
|
+
const data = await fs$11.promises.readFile(input, { signal });
|
|
23565
23565
|
file = new File$1([new Blob$1([new Uint8Array(data)], { type: mimeType })], filename, { type: mimeType });
|
|
23566
23566
|
} else {
|
|
23567
23567
|
if (!input.mimeType.startsWith("video/")) throw new ChatProviderError(`Expected a video mime type, got ${input.mimeType}`);
|
|
@@ -31330,7 +31330,7 @@ async function syncDir(dirPath) {
|
|
|
31330
31330
|
*/
|
|
31331
31331
|
function syncFd(fd) {
|
|
31332
31332
|
return new Promise((resolve, reject) => {
|
|
31333
|
-
fs$
|
|
31333
|
+
fs$11.fsync(fd, (err) => {
|
|
31334
31334
|
if (err) {
|
|
31335
31335
|
reject(err);
|
|
31336
31336
|
return;
|
|
@@ -37094,8 +37094,8 @@ function parseSkillText(options) {
|
|
|
37094
37094
|
if (!isRecord$5(frontmatter)) throw new SkillParseError(`Frontmatter in ${options.skillMdPath} must be a mapping at the top level`);
|
|
37095
37095
|
const metadata = normalizeMetadata(frontmatter);
|
|
37096
37096
|
if (!isSupportedSkillType(metadata.type)) throw new UnsupportedSkillTypeError(metadata.type ?? String(frontmatter["type"]));
|
|
37097
|
-
const name = nonEmptyString$
|
|
37098
|
-
const description = nonEmptyString$
|
|
37097
|
+
const name = nonEmptyString$6(metadata.name);
|
|
37098
|
+
const description = nonEmptyString$6(metadata.description);
|
|
37099
37099
|
if (isDirectorySkill && (name === void 0 || description === void 0)) throw new SkillParseError(`Missing required frontmatter field ${name === void 0 ? "\"name\"" : "\"description\""} in ${options.skillMdPath}`);
|
|
37100
37100
|
const skillPath = posix$2.resolve(options.skillMdPath);
|
|
37101
37101
|
const content = parsed.body.trim();
|
|
@@ -37155,11 +37155,11 @@ function normalizeMetadata(raw) {
|
|
|
37155
37155
|
const key = METADATA_ALIASES[rawKey] ?? rawKey;
|
|
37156
37156
|
out[key] = value;
|
|
37157
37157
|
}
|
|
37158
|
-
const type = nonEmptyString$
|
|
37158
|
+
const type = nonEmptyString$6(out["type"]);
|
|
37159
37159
|
if (type !== void 0) out["type"] = type;
|
|
37160
|
-
const name = nonEmptyString$
|
|
37160
|
+
const name = nonEmptyString$6(out["name"]);
|
|
37161
37161
|
if (name !== void 0) out["name"] = name;
|
|
37162
|
-
const description = nonEmptyString$
|
|
37162
|
+
const description = nonEmptyString$6(out["description"]);
|
|
37163
37163
|
if (description !== void 0) out["description"] = description;
|
|
37164
37164
|
return out;
|
|
37165
37165
|
}
|
|
@@ -37201,7 +37201,7 @@ function tokenizeArgs(raw) {
|
|
|
37201
37201
|
if (hasContent) out.push(current);
|
|
37202
37202
|
return out;
|
|
37203
37203
|
}
|
|
37204
|
-
function nonEmptyString$
|
|
37204
|
+
function nonEmptyString$6(value) {
|
|
37205
37205
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
37206
37206
|
}
|
|
37207
37207
|
function isRecord$5(value) {
|
|
@@ -37214,12 +37214,12 @@ function parseCommandText(input) {
|
|
|
37214
37214
|
const parsed = parseFrontmatter(text);
|
|
37215
37215
|
const frontmatter = isRecord$4(parsed.data) ? parsed.data : {};
|
|
37216
37216
|
const baseName = input.fallbackName ?? path.basename(commandPath).replace(/\.md$/i, "");
|
|
37217
|
-
const name = nonEmptyString$
|
|
37217
|
+
const name = nonEmptyString$5(frontmatter["name"]) ?? baseName;
|
|
37218
37218
|
const body = parsed.body.trim();
|
|
37219
37219
|
return {
|
|
37220
37220
|
pluginId,
|
|
37221
37221
|
name,
|
|
37222
|
-
description: nonEmptyString$
|
|
37222
|
+
description: nonEmptyString$5(frontmatter["description"]) ?? descriptionFromBody(body),
|
|
37223
37223
|
body,
|
|
37224
37224
|
path: path.resolve(commandPath)
|
|
37225
37225
|
};
|
|
@@ -37246,7 +37246,7 @@ function expandCommandArguments(body, args) {
|
|
|
37246
37246
|
if (!body.includes("$ARGUMENTS") && args.length > 0) return `${replaced}\n\nARGUMENTS: ${args}`;
|
|
37247
37247
|
return replaced;
|
|
37248
37248
|
}
|
|
37249
|
-
function nonEmptyString$
|
|
37249
|
+
function nonEmptyString$5(value) {
|
|
37250
37250
|
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
37251
37251
|
}
|
|
37252
37252
|
function descriptionFromBody(body) {
|
|
@@ -42897,7 +42897,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
42897
42897
|
};
|
|
42898
42898
|
return _setPrototypeOf(o, p);
|
|
42899
42899
|
}
|
|
42900
|
-
var fs$
|
|
42900
|
+
var fs$10 = __require("fs");
|
|
42901
42901
|
var path$8 = __require("path");
|
|
42902
42902
|
var Loader = require_loader();
|
|
42903
42903
|
var PrecompiledLoader = require_precompiled_loader().PrecompiledLoader;
|
|
@@ -42921,7 +42921,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
42921
42921
|
} catch (e) {
|
|
42922
42922
|
throw new Error("watch requires chokidar to be installed");
|
|
42923
42923
|
}
|
|
42924
|
-
var paths = _this.searchPaths.filter(fs$
|
|
42924
|
+
var paths = _this.searchPaths.filter(fs$10.existsSync);
|
|
42925
42925
|
var watcher = chokidar.watch(paths);
|
|
42926
42926
|
watcher.on("all", function(event, fullname) {
|
|
42927
42927
|
fullname = path$8.resolve(fullname);
|
|
@@ -42940,7 +42940,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
42940
42940
|
for (var i = 0; i < paths.length; i++) {
|
|
42941
42941
|
var basePath = path$8.resolve(paths[i]);
|
|
42942
42942
|
var p = path$8.resolve(paths[i], name);
|
|
42943
|
-
if (p.indexOf(basePath) === 0 && fs$
|
|
42943
|
+
if (p.indexOf(basePath) === 0 && fs$10.existsSync(p)) {
|
|
42944
42944
|
fullpath = p;
|
|
42945
42945
|
break;
|
|
42946
42946
|
}
|
|
@@ -42948,7 +42948,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
42948
42948
|
if (!fullpath) return null;
|
|
42949
42949
|
this.pathsToNames[fullpath] = name;
|
|
42950
42950
|
var source = {
|
|
42951
|
-
src: fs$
|
|
42951
|
+
src: fs$10.readFileSync(fullpath, "utf-8"),
|
|
42952
42952
|
path: fullpath,
|
|
42953
42953
|
noCache: this.noCache
|
|
42954
42954
|
};
|
|
@@ -42996,7 +42996,7 @@ var require_node_loaders = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
42996
42996
|
}
|
|
42997
42997
|
this.pathsToNames[fullpath] = name;
|
|
42998
42998
|
var source = {
|
|
42999
|
-
src: fs$
|
|
42999
|
+
src: fs$10.readFileSync(fullpath, "utf-8"),
|
|
43000
43000
|
path: fullpath,
|
|
43001
43001
|
noCache: this.noCache
|
|
43002
43002
|
};
|
|
@@ -43740,7 +43740,7 @@ var require_precompile_global = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
43740
43740
|
//#endregion
|
|
43741
43741
|
//#region ../../node_modules/.pnpm/nunjucks@3.2.4_chokidar@4.0.3/node_modules/nunjucks/src/precompile.js
|
|
43742
43742
|
var require_precompile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
43743
|
-
var fs$
|
|
43743
|
+
var fs$9 = __require("fs");
|
|
43744
43744
|
var path$6 = __require("path");
|
|
43745
43745
|
var _prettifyError = require_lib$3()._prettifyError;
|
|
43746
43746
|
var compiler = require_compiler();
|
|
@@ -43765,27 +43765,27 @@ var require_precompile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
43765
43765
|
var env = opts.env || new Environment([]);
|
|
43766
43766
|
var wrapper = opts.wrapper || precompileGlobal;
|
|
43767
43767
|
if (opts.isString) return precompileString(input, opts);
|
|
43768
|
-
var pathStats = fs$
|
|
43768
|
+
var pathStats = fs$9.existsSync(input) && fs$9.statSync(input);
|
|
43769
43769
|
var precompiled = [];
|
|
43770
43770
|
var templates = [];
|
|
43771
43771
|
function addTemplates(dir) {
|
|
43772
|
-
fs$
|
|
43772
|
+
fs$9.readdirSync(dir).forEach(function(file) {
|
|
43773
43773
|
var filepath = path$6.join(dir, file);
|
|
43774
43774
|
var subpath = filepath.substr(path$6.join(input, "/").length);
|
|
43775
|
-
var stat = fs$
|
|
43775
|
+
var stat = fs$9.statSync(filepath);
|
|
43776
43776
|
if (stat && stat.isDirectory()) {
|
|
43777
43777
|
subpath += "/";
|
|
43778
43778
|
if (!match(subpath, opts.exclude)) addTemplates(filepath);
|
|
43779
43779
|
} else if (match(subpath, opts.include)) templates.push(filepath);
|
|
43780
43780
|
});
|
|
43781
43781
|
}
|
|
43782
|
-
if (pathStats.isFile()) precompiled.push(_precompile(fs$
|
|
43782
|
+
if (pathStats.isFile()) precompiled.push(_precompile(fs$9.readFileSync(input, "utf-8"), opts.name || input, env));
|
|
43783
43783
|
else if (pathStats.isDirectory()) {
|
|
43784
43784
|
addTemplates(input);
|
|
43785
43785
|
for (var i = 0; i < templates.length; i++) {
|
|
43786
43786
|
var name = templates[i].replace(path$6.join(input, "/"), "");
|
|
43787
43787
|
try {
|
|
43788
|
-
precompiled.push(_precompile(fs$
|
|
43788
|
+
precompiled.push(_precompile(fs$9.readFileSync(templates[i], "utf-8"), name, env));
|
|
43789
43789
|
} catch (e) {
|
|
43790
43790
|
if (opts.force) console.error(e);
|
|
43791
43791
|
else throw e;
|
|
@@ -57710,7 +57710,7 @@ var require_gifframe = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
57710
57710
|
//#region ../../node_modules/.pnpm/gifwrap@0.10.1/node_modules/gifwrap/src/gifutil.js
|
|
57711
57711
|
var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
57712
57712
|
/** @namespace GifUtil */
|
|
57713
|
-
const fs$
|
|
57713
|
+
const fs$8 = __require("fs");
|
|
57714
57714
|
const ImageQ = require_image_q();
|
|
57715
57715
|
const BitmapImage = require_bitmapimage();
|
|
57716
57716
|
const { GifFrame } = require_gifframe();
|
|
@@ -57977,7 +57977,7 @@ var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
57977
57977
|
}
|
|
57978
57978
|
function _readBinary(path) {
|
|
57979
57979
|
return new Promise((resolve, reject) => {
|
|
57980
|
-
fs$
|
|
57980
|
+
fs$8.readFile(path, (err, buffer) => {
|
|
57981
57981
|
if (err) return reject(err);
|
|
57982
57982
|
return resolve(buffer);
|
|
57983
57983
|
});
|
|
@@ -57985,7 +57985,7 @@ var require_gifutil = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
57985
57985
|
}
|
|
57986
57986
|
function _writeBinary(path, buffer) {
|
|
57987
57987
|
return new Promise((resolve, reject) => {
|
|
57988
|
-
fs$
|
|
57988
|
+
fs$8.writeFile(path, buffer, (err) => {
|
|
57989
57989
|
if (err) return reject(err);
|
|
57990
57990
|
return resolve();
|
|
57991
57991
|
});
|
|
@@ -83803,7 +83803,7 @@ var init_file_type = __esmMin((() => {
|
|
|
83803
83803
|
}
|
|
83804
83804
|
async fromFile(path) {
|
|
83805
83805
|
this.options.signal?.throwIfAborted();
|
|
83806
|
-
const fileHandle = await
|
|
83806
|
+
const fileHandle = await jn.open(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
83807
83807
|
const fileStat = await fileHandle.stat();
|
|
83808
83808
|
if (!fileStat.isFile()) {
|
|
83809
83809
|
await fileHandle.close();
|
|
@@ -100105,7 +100105,7 @@ K(Un, Hn, Wn, Gn, (s, t) => {
|
|
|
100105
100105
|
if (!t?.length) throw new TypeError("no paths specified to add to archive");
|
|
100106
100106
|
});
|
|
100107
100107
|
var fr = (process.env.__FAKE_PLATFORM__ || process.platform) === "win32", { O_CREAT: dr, O_NOFOLLOW: ar, O_TRUNC: ur, O_WRONLY: mr } = I.constants, pr = Number(process.env.__FAKE_FS_O_FILENAME__) || I.constants.UV_FS_O_FILEMAP || 0, Kn = fr && !!pr, Vn = 512 * 1024, $n = pr | ur | dr | mr, lr = !fr && typeof ar == "number" ? ar | ur | dr | mr : null, cs = lr !== null ? () => lr : Kn ? (s) => s < Vn ? $n : "w" : () => "w";
|
|
100108
|
-
var fs$
|
|
100108
|
+
var fs$7 = (s, t, e) => {
|
|
100109
100109
|
try {
|
|
100110
100110
|
return Vt.lchownSync(s, t, e);
|
|
100111
100111
|
} catch (i) {
|
|
@@ -100137,7 +100137,7 @@ var fs$8 = (s, t, e) => {
|
|
|
100137
100137
|
for (let l of n) Xn(s, l, t, e, a);
|
|
100138
100138
|
});
|
|
100139
100139
|
}, qn = (s, t, e, i) => {
|
|
100140
|
-
t.isDirectory() && us(path.resolve(s, t.name), e, i), fs$
|
|
100140
|
+
t.isDirectory() && us(path.resolve(s, t.name), e, i), fs$7(path.resolve(s, t.name), e, i);
|
|
100141
100141
|
}, us = (s, t, e) => {
|
|
100142
100142
|
let i;
|
|
100143
100143
|
try {
|
|
@@ -100145,11 +100145,11 @@ var fs$8 = (s, t, e) => {
|
|
|
100145
100145
|
} catch (r) {
|
|
100146
100146
|
let n = r;
|
|
100147
100147
|
if (n?.code === "ENOENT") return;
|
|
100148
|
-
if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return fs$
|
|
100148
|
+
if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return fs$7(s, t, e);
|
|
100149
100149
|
throw n;
|
|
100150
100150
|
}
|
|
100151
100151
|
for (let r of i) qn(s, r, t, e);
|
|
100152
|
-
return fs$
|
|
100152
|
+
return fs$7(s, t, e);
|
|
100153
100153
|
};
|
|
100154
100154
|
var we = class extends Error {
|
|
100155
100155
|
path;
|
|
@@ -100184,7 +100184,7 @@ var Qn = (s, t) => {
|
|
|
100184
100184
|
E ? e(E) : x && a ? ds(x, o, h, (xe) => S(xe)) : n ? Vt.chmod(s, r, e) : e();
|
|
100185
100185
|
};
|
|
100186
100186
|
if (s === d) return Qn(s, S);
|
|
100187
|
-
if (l) return
|
|
100187
|
+
if (l) return jn.mkdir(s, {
|
|
100188
100188
|
mode: r,
|
|
100189
100189
|
recursive: !0
|
|
100190
100190
|
}).then((E) => S(null, E ?? void 0), S);
|
|
@@ -100943,7 +100943,7 @@ var require_pend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
100943
100943
|
//#endregion
|
|
100944
100944
|
//#region ../../node_modules/.pnpm/yauzl@3.3.0/node_modules/yauzl/fd-slicer.js
|
|
100945
100945
|
var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
100946
|
-
var fs$
|
|
100946
|
+
var fs$6 = __require("fs");
|
|
100947
100947
|
var util$3 = __require("util");
|
|
100948
100948
|
var stream$1 = __require("stream");
|
|
100949
100949
|
var Readable = stream$1.Readable;
|
|
@@ -100968,7 +100968,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
100968
100968
|
FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
100969
100969
|
var self = this;
|
|
100970
100970
|
self.pend.go(function(cb) {
|
|
100971
|
-
fs$
|
|
100971
|
+
fs$6.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
|
|
100972
100972
|
cb();
|
|
100973
100973
|
callback(err, bytesRead, buffer);
|
|
100974
100974
|
});
|
|
@@ -100977,7 +100977,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
100977
100977
|
FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
|
|
100978
100978
|
var self = this;
|
|
100979
100979
|
self.pend.go(function(cb) {
|
|
100980
|
-
fs$
|
|
100980
|
+
fs$6.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
|
|
100981
100981
|
cb();
|
|
100982
100982
|
callback(err, written, buffer);
|
|
100983
100983
|
});
|
|
@@ -100997,7 +100997,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
100997
100997
|
self.refCount -= 1;
|
|
100998
100998
|
if (self.refCount > 0) return;
|
|
100999
100999
|
if (self.refCount < 0) throw new Error("invalid unref");
|
|
101000
|
-
if (self.autoClose) fs$
|
|
101000
|
+
if (self.autoClose) fs$6.close(self.fd, onCloseDone);
|
|
101001
101001
|
function onCloseDone(err) {
|
|
101002
101002
|
if (err) self.emit("error", err);
|
|
101003
101003
|
else self.emit("close");
|
|
@@ -101028,7 +101028,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
101028
101028
|
self.context.pend.go(function(cb) {
|
|
101029
101029
|
if (self.destroyed) return cb();
|
|
101030
101030
|
var buffer = Buffer.allocUnsafe(toRead);
|
|
101031
|
-
fs$
|
|
101031
|
+
fs$6.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
|
|
101032
101032
|
if (err) self.destroy(err);
|
|
101033
101033
|
else if (bytesRead === 0) {
|
|
101034
101034
|
self.destroyed = true;
|
|
@@ -101074,7 +101074,7 @@ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
101074
101074
|
}
|
|
101075
101075
|
self.context.pend.go(function(cb) {
|
|
101076
101076
|
if (self.destroyed) return cb();
|
|
101077
|
-
fs$
|
|
101077
|
+
fs$6.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
|
|
101078
101078
|
if (err) {
|
|
101079
101079
|
self.destroy();
|
|
101080
101080
|
cb();
|
|
@@ -135695,7 +135695,7 @@ function reconcileChildNoProxy(childEnv, configEnv) {
|
|
|
135695
135695
|
var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
135696
135696
|
module.exports = isexe;
|
|
135697
135697
|
isexe.sync = sync;
|
|
135698
|
-
var fs$
|
|
135698
|
+
var fs$4 = __require("fs");
|
|
135699
135699
|
function checkPathExt(path, options) {
|
|
135700
135700
|
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
135701
135701
|
if (!pathext) return true;
|
|
@@ -135712,12 +135712,12 @@ var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
135712
135712
|
return checkPathExt(path, options);
|
|
135713
135713
|
}
|
|
135714
135714
|
function isexe(path, options, cb) {
|
|
135715
|
-
fs$
|
|
135715
|
+
fs$4.stat(path, function(er, stat) {
|
|
135716
135716
|
cb(er, er ? false : checkStat(stat, path, options));
|
|
135717
135717
|
});
|
|
135718
135718
|
}
|
|
135719
135719
|
function sync(path, options) {
|
|
135720
|
-
return checkStat(fs$
|
|
135720
|
+
return checkStat(fs$4.statSync(path), path, options);
|
|
135721
135721
|
}
|
|
135722
135722
|
}));
|
|
135723
135723
|
//#endregion
|
|
@@ -135725,14 +135725,14 @@ var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
135725
135725
|
var require_mode = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
135726
135726
|
module.exports = isexe;
|
|
135727
135727
|
isexe.sync = sync;
|
|
135728
|
-
var fs$
|
|
135728
|
+
var fs$3 = __require("fs");
|
|
135729
135729
|
function isexe(path, options, cb) {
|
|
135730
|
-
fs$
|
|
135730
|
+
fs$3.stat(path, function(er, stat) {
|
|
135731
135731
|
cb(er, er ? false : checkStat(stat, options));
|
|
135732
135732
|
});
|
|
135733
135733
|
}
|
|
135734
135734
|
function sync(path, options) {
|
|
135735
|
-
return checkStat(fs$
|
|
135735
|
+
return checkStat(fs$3.statSync(path), options);
|
|
135736
135736
|
}
|
|
135737
135737
|
function checkStat(stat, options) {
|
|
135738
135738
|
return stat.isFile() && checkMode(stat, options);
|
|
@@ -135947,16 +135947,16 @@ var require_shebang_command = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
135947
135947
|
//#endregion
|
|
135948
135948
|
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
|
|
135949
135949
|
var require_readShebang = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
135950
|
-
const fs$
|
|
135950
|
+
const fs$2 = __require("fs");
|
|
135951
135951
|
const shebangCommand = require_shebang_command();
|
|
135952
135952
|
function readShebang(command) {
|
|
135953
135953
|
const size = 150;
|
|
135954
135954
|
const buffer = Buffer.alloc(size);
|
|
135955
135955
|
let fd;
|
|
135956
135956
|
try {
|
|
135957
|
-
fd = fs$
|
|
135958
|
-
fs$
|
|
135959
|
-
fs$
|
|
135957
|
+
fd = fs$2.openSync(command, "r");
|
|
135958
|
+
fs$2.readSync(fd, buffer, 0, size, 0);
|
|
135959
|
+
fs$2.closeSync(fd);
|
|
135960
135960
|
} catch (e) {}
|
|
135961
135961
|
return shebangCommand(buffer.toString());
|
|
135962
135962
|
}
|
|
@@ -153794,7 +153794,7 @@ var require_dist = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
153794
153794
|
//#endregion
|
|
153795
153795
|
//#region ../../packages/agent-core/src/session/export/zip.ts
|
|
153796
153796
|
var import_yazl = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
153797
|
-
var fs$
|
|
153797
|
+
var fs$1 = __require("fs");
|
|
153798
153798
|
var Transform = __require("stream").Transform;
|
|
153799
153799
|
var PassThrough$1 = __require("stream").PassThrough;
|
|
153800
153800
|
var zlib = __require("zlib");
|
|
@@ -153823,14 +153823,14 @@ var import_yazl = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
153823
153823
|
if (shouldIgnoreAdding(self)) return;
|
|
153824
153824
|
var entry = new Entry(metadataPath, false, options);
|
|
153825
153825
|
self.entries.push(entry);
|
|
153826
|
-
fs$
|
|
153826
|
+
fs$1.stat(realPath, function(err, stats) {
|
|
153827
153827
|
if (err) return self.emit("error", err);
|
|
153828
153828
|
if (!stats.isFile()) return self.emit("error", /* @__PURE__ */ new Error("not a file: " + realPath));
|
|
153829
153829
|
entry.uncompressedSize = stats.size;
|
|
153830
153830
|
if (options.mtime == null) entry.setLastModDate(stats.mtime);
|
|
153831
153831
|
if (options.mode == null) entry.setFileAttributesMode(stats.mode);
|
|
153832
153832
|
entry.setFileDataPumpFunction(function() {
|
|
153833
|
-
var readStream = fs$
|
|
153833
|
+
var readStream = fs$1.createReadStream(realPath);
|
|
153834
153834
|
entry.state = Entry.FILE_DATA_IN_PROGRESS;
|
|
153835
153835
|
readStream.on("error", function(err) {
|
|
153836
153836
|
self.emit("error", err);
|
|
@@ -154650,7 +154650,7 @@ function extractApiErrorMessage(value) {
|
|
|
154650
154650
|
if (message !== void 0) return message;
|
|
154651
154651
|
}
|
|
154652
154652
|
const error = value["error"];
|
|
154653
|
-
const errorString = nonEmptyString$
|
|
154653
|
+
const errorString = nonEmptyString$4(error);
|
|
154654
154654
|
if (errorString !== void 0) return errorString;
|
|
154655
154655
|
if (isRecord$1(error)) for (const key of NESTED_ERROR_KEYS) {
|
|
154656
154656
|
const message = stringField(error, key);
|
|
@@ -154672,9 +154672,9 @@ async function readApiErrorMessage(response, fallback) {
|
|
|
154672
154672
|
return extractApiErrorMessage(parsed) ?? fallback;
|
|
154673
154673
|
}
|
|
154674
154674
|
function stringField(record, key) {
|
|
154675
|
-
return nonEmptyString$
|
|
154675
|
+
return nonEmptyString$4(record[key]);
|
|
154676
154676
|
}
|
|
154677
|
-
function nonEmptyString$
|
|
154677
|
+
function nonEmptyString$4(value) {
|
|
154678
154678
|
if (typeof value !== "string") return void 0;
|
|
154679
154679
|
const trimmed = value.trim();
|
|
154680
154680
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -155201,7 +155201,7 @@ var require_clone = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
155201
155201
|
//#endregion
|
|
155202
155202
|
//#region ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
|
|
155203
155203
|
var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
155204
|
-
var fs
|
|
155204
|
+
var fs = __require("fs");
|
|
155205
155205
|
var polyfills = require_polyfills();
|
|
155206
155206
|
var legacy = require_legacy_streams();
|
|
155207
155207
|
var clone = require_clone();
|
|
@@ -155230,36 +155230,36 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
155230
155230
|
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
155231
155231
|
console.error(m);
|
|
155232
155232
|
};
|
|
155233
|
-
if (!fs
|
|
155234
|
-
publishQueue(fs
|
|
155235
|
-
fs
|
|
155233
|
+
if (!fs[gracefulQueue]) {
|
|
155234
|
+
publishQueue(fs, global[gracefulQueue] || []);
|
|
155235
|
+
fs.close = (function(fs$close) {
|
|
155236
155236
|
function close(fd, cb) {
|
|
155237
|
-
return fs$close.call(fs
|
|
155237
|
+
return fs$close.call(fs, fd, function(err) {
|
|
155238
155238
|
if (!err) resetQueue();
|
|
155239
155239
|
if (typeof cb === "function") cb.apply(this, arguments);
|
|
155240
155240
|
});
|
|
155241
155241
|
}
|
|
155242
155242
|
Object.defineProperty(close, previousSymbol, { value: fs$close });
|
|
155243
155243
|
return close;
|
|
155244
|
-
})(fs
|
|
155245
|
-
fs
|
|
155244
|
+
})(fs.close);
|
|
155245
|
+
fs.closeSync = (function(fs$closeSync) {
|
|
155246
155246
|
function closeSync(fd) {
|
|
155247
|
-
fs$closeSync.apply(fs
|
|
155247
|
+
fs$closeSync.apply(fs, arguments);
|
|
155248
155248
|
resetQueue();
|
|
155249
155249
|
}
|
|
155250
155250
|
Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync });
|
|
155251
155251
|
return closeSync;
|
|
155252
|
-
})(fs
|
|
155252
|
+
})(fs.closeSync);
|
|
155253
155253
|
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) process.on("exit", function() {
|
|
155254
|
-
debug(fs
|
|
155255
|
-
__require("assert").equal(fs
|
|
155254
|
+
debug(fs[gracefulQueue]);
|
|
155255
|
+
__require("assert").equal(fs[gracefulQueue].length, 0);
|
|
155256
155256
|
});
|
|
155257
155257
|
}
|
|
155258
|
-
if (!global[gracefulQueue]) publishQueue(global, fs
|
|
155259
|
-
module.exports = patch(clone(fs
|
|
155260
|
-
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs
|
|
155261
|
-
module.exports = patch(fs
|
|
155262
|
-
fs
|
|
155258
|
+
if (!global[gracefulQueue]) publishQueue(global, fs[gracefulQueue]);
|
|
155259
|
+
module.exports = patch(clone(fs));
|
|
155260
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
|
|
155261
|
+
module.exports = patch(fs);
|
|
155262
|
+
fs.__patched = true;
|
|
155263
155263
|
}
|
|
155264
155264
|
function patch(fs) {
|
|
155265
155265
|
polyfills(fs);
|
|
@@ -155514,23 +155514,23 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
155514
155514
|
}
|
|
155515
155515
|
function enqueue(elem) {
|
|
155516
155516
|
debug("ENQUEUE", elem[0].name, elem[1]);
|
|
155517
|
-
fs
|
|
155517
|
+
fs[gracefulQueue].push(elem);
|
|
155518
155518
|
retry();
|
|
155519
155519
|
}
|
|
155520
155520
|
var retryTimer;
|
|
155521
155521
|
function resetQueue() {
|
|
155522
155522
|
var now = Date.now();
|
|
155523
|
-
for (var i = 0; i < fs
|
|
155524
|
-
fs
|
|
155525
|
-
fs
|
|
155523
|
+
for (var i = 0; i < fs[gracefulQueue].length; ++i) if (fs[gracefulQueue][i].length > 2) {
|
|
155524
|
+
fs[gracefulQueue][i][3] = now;
|
|
155525
|
+
fs[gracefulQueue][i][4] = now;
|
|
155526
155526
|
}
|
|
155527
155527
|
retry();
|
|
155528
155528
|
}
|
|
155529
155529
|
function retry() {
|
|
155530
155530
|
clearTimeout(retryTimer);
|
|
155531
155531
|
retryTimer = void 0;
|
|
155532
|
-
if (fs
|
|
155533
|
-
var elem = fs
|
|
155532
|
+
if (fs[gracefulQueue].length === 0) return;
|
|
155533
|
+
var elem = fs[gracefulQueue].shift();
|
|
155534
155534
|
var fn = elem[0];
|
|
155535
155535
|
var args = elem[1];
|
|
155536
155536
|
var err = elem[2];
|
|
@@ -155549,7 +155549,7 @@ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
155549
155549
|
if (sinceAttempt >= Math.min(sinceStart * 1.2, 100)) {
|
|
155550
155550
|
debug("RETRY", fn.name, args);
|
|
155551
155551
|
fn.apply(null, args.concat([startTime]));
|
|
155552
|
-
} else fs
|
|
155552
|
+
} else fs[gracefulQueue].push(elem);
|
|
155553
155553
|
}
|
|
155554
155554
|
if (retryTimer === void 0) retryTimer = setTimeout(retry, 0);
|
|
155555
155555
|
}
|
|
@@ -156578,18 +156578,22 @@ function requiredAsciiHeader(value, fieldName) {
|
|
|
156578
156578
|
if (cleaned.length === 0) throw new Error(`${fieldName} must be a non-empty ASCII string.`);
|
|
156579
156579
|
return cleaned;
|
|
156580
156580
|
}
|
|
156581
|
+
//#endregion
|
|
156582
|
+
//#region ../../packages/oauth/src/constants.ts
|
|
156583
|
+
const DEFAULT_BLUN_OAUTH_HOST = "https://account.blun.ai";
|
|
156581
156584
|
const BLUN_FLOW_CONFIG = {
|
|
156582
156585
|
name: "blun",
|
|
156583
|
-
oauthHost: process.env["BLUN_OAUTH_HOST"] ?? "https://
|
|
156584
|
-
clientId: "
|
|
156586
|
+
oauthHost: process.env["BLUN_OAUTH_HOST"] ?? "https://account.blun.ai",
|
|
156587
|
+
clientId: "blun-code"
|
|
156585
156588
|
};
|
|
156586
156589
|
//#endregion
|
|
156587
156590
|
//#region ../../packages/oauth/src/managed-usage.ts
|
|
156588
156591
|
/**
|
|
156589
156592
|
* Managed-platform usage fetch / parse.
|
|
156590
156593
|
*
|
|
156591
|
-
* Only `managed:blun` is supported today.
|
|
156592
|
-
* `/
|
|
156594
|
+
* Only `managed:blun` is supported today. Account usage is read from the
|
|
156595
|
+
* authenticated `/api/verbrauch/mein-stand` endpoint. Legacy payloads remain
|
|
156596
|
+
* accepted for older deployments and tests:
|
|
156593
156597
|
*
|
|
156594
156598
|
* {
|
|
156595
156599
|
* "usage": { "name": "Weekly limit", "used": 40, "limit": 1000, "resetAt": "..." },
|
|
@@ -156603,12 +156607,44 @@ const BLUN_FLOW_CONFIG = {
|
|
|
156603
156607
|
* drifted across versions (`used` vs `remaining`, `resetAt` vs
|
|
156604
156608
|
* `reset_at`, `duration+timeUnit` window labels, etc.).
|
|
156605
156609
|
*/
|
|
156606
|
-
const DEFAULT_BLUN_BASE_URL = "https://api.blun.ai/
|
|
156610
|
+
const DEFAULT_BLUN_BASE_URL = "https://api.blun.ai/v1";
|
|
156611
|
+
const DEFAULT_BLUN_AUXILIARY_BASE_URL = "https://api.blun.ai/coding/v1";
|
|
156607
156612
|
function blunCodeBaseUrl() {
|
|
156608
|
-
return process.env["BLUN_BASE_URL"] ?? "https://api.blun.ai/
|
|
156613
|
+
return process.env["BLUN_BASE_URL"] ?? "https://api.blun.ai/v1";
|
|
156614
|
+
}
|
|
156615
|
+
function blunCodeAuxiliaryBaseUrl(baseUrl) {
|
|
156616
|
+
const normalized = (baseUrl ?? blunCodeBaseUrl()).replace(/\/+$/, "");
|
|
156617
|
+
return normalized === "https://api.blun.ai/v1" ? DEFAULT_BLUN_AUXILIARY_BASE_URL : normalized;
|
|
156618
|
+
}
|
|
156619
|
+
function blunContextWindowsUrl(oauthHost) {
|
|
156620
|
+
return `${(oauthHost ?? process.env["BLUN_OAUTH_HOST"] ?? "https://account.blun.ai").replace(/\/+$/, "")}/api/verbrauch/tarife`;
|
|
156621
|
+
}
|
|
156622
|
+
function parseManagedContextWindow(payload, plan) {
|
|
156623
|
+
if (!isRecord$1(payload)) return void 0;
|
|
156624
|
+
const contextWindows = payload["kontext"];
|
|
156625
|
+
if (!isRecord$1(contextWindows)) return void 0;
|
|
156626
|
+
const value = contextWindows[plan];
|
|
156627
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
156609
156628
|
}
|
|
156610
|
-
function
|
|
156611
|
-
|
|
156629
|
+
async function fetchManagedContextWindow(url, plan, opts = {}) {
|
|
156630
|
+
const controller = new AbortController();
|
|
156631
|
+
const timer = setTimeout(() => {
|
|
156632
|
+
controller.abort();
|
|
156633
|
+
}, opts.timeoutMs ?? 8e3);
|
|
156634
|
+
timer.unref?.();
|
|
156635
|
+
try {
|
|
156636
|
+
const response = await fetch(url, {
|
|
156637
|
+
headers: { Accept: "application/json" },
|
|
156638
|
+
signal: controller.signal,
|
|
156639
|
+
redirect: "error"
|
|
156640
|
+
});
|
|
156641
|
+
if (!response.ok) return void 0;
|
|
156642
|
+
return parseManagedContextWindow(await response.json(), plan);
|
|
156643
|
+
} catch {
|
|
156644
|
+
return;
|
|
156645
|
+
} finally {
|
|
156646
|
+
clearTimeout(timer);
|
|
156647
|
+
}
|
|
156612
156648
|
}
|
|
156613
156649
|
function parseManagedUsagePayload(payload) {
|
|
156614
156650
|
if (typeof payload !== "object" || payload === null) return {
|
|
@@ -156618,8 +156654,17 @@ function parseManagedUsagePayload(payload) {
|
|
|
156618
156654
|
const rec = payload;
|
|
156619
156655
|
const summary = toUsageRow(rec["usage"], "Weekly limit");
|
|
156620
156656
|
const limits = [];
|
|
156657
|
+
const accountId = managedAccountIdFrom(rec["account_id"]);
|
|
156658
|
+
const plan = typeof rec["plan"] === "string" && rec["plan"].trim().length > 0 ? rec["plan"].trim() : void 0;
|
|
156659
|
+
const contextWindowTokens = managedContextWindowFrom(rec);
|
|
156660
|
+
const unlimited = rec["unlimited"] === true;
|
|
156661
|
+
const stand = isRecord$1(rec["stand"]) ? rec["stand"] : void 0;
|
|
156662
|
+
if (stand !== void 0) for (const [sourceKey, id, label] of ACCOUNT_USAGE_WINDOWS) {
|
|
156663
|
+
const row = toAccountUsageRow(stand[sourceKey], id, label, unlimited);
|
|
156664
|
+
if (row !== null) limits.push(row);
|
|
156665
|
+
}
|
|
156621
156666
|
const rawLimits = rec["limits"];
|
|
156622
|
-
if (Array.isArray(rawLimits)) for (let idx = 0; idx < rawLimits.length; idx++) {
|
|
156667
|
+
if (stand === void 0 && Array.isArray(rawLimits)) for (let idx = 0; idx < rawLimits.length; idx++) {
|
|
156623
156668
|
const item = rawLimits[idx];
|
|
156624
156669
|
if (!item || typeof item !== "object") continue;
|
|
156625
156670
|
const detailRaw = item["detail"];
|
|
@@ -156629,26 +156674,105 @@ function parseManagedUsagePayload(payload) {
|
|
|
156629
156674
|
if (row !== null) limits.push(row);
|
|
156630
156675
|
}
|
|
156631
156676
|
return {
|
|
156677
|
+
...accountId === void 0 ? {} : { accountId },
|
|
156678
|
+
...plan === void 0 ? {} : { plan },
|
|
156679
|
+
...contextWindowTokens === void 0 ? {} : { contextWindowTokens },
|
|
156632
156680
|
summary,
|
|
156633
156681
|
limits
|
|
156634
156682
|
};
|
|
156635
156683
|
}
|
|
156684
|
+
function managedAccountIdFrom(value) {
|
|
156685
|
+
if (typeof value !== "string") return void 0;
|
|
156686
|
+
const normalized = value.trim();
|
|
156687
|
+
return normalized.length > 0 && normalized.length <= 512 ? normalized : void 0;
|
|
156688
|
+
}
|
|
156689
|
+
function managedContextWindowFrom(payload) {
|
|
156690
|
+
const values = [payload["context_window_tokens"], payload["contextWindowTokens"]].filter((value) => value !== void 0);
|
|
156691
|
+
if (values.length === 0) return void 0;
|
|
156692
|
+
if (values.some((value) => !Number.isSafeInteger(value) || value <= 0)) return;
|
|
156693
|
+
const [first] = values;
|
|
156694
|
+
return values.every((value) => value === first) ? first : void 0;
|
|
156695
|
+
}
|
|
156696
|
+
const ACCOUNT_USAGE_WINDOWS = [
|
|
156697
|
+
[
|
|
156698
|
+
"fuenf_stunden",
|
|
156699
|
+
"five_hours",
|
|
156700
|
+
"5h"
|
|
156701
|
+
],
|
|
156702
|
+
[
|
|
156703
|
+
"sieben_tage",
|
|
156704
|
+
"seven_days",
|
|
156705
|
+
"7d"
|
|
156706
|
+
],
|
|
156707
|
+
[
|
|
156708
|
+
"monat",
|
|
156709
|
+
"month",
|
|
156710
|
+
"month"
|
|
156711
|
+
]
|
|
156712
|
+
];
|
|
156713
|
+
function toAccountUsageRow(raw, id, label, accountUnlimited) {
|
|
156714
|
+
if (!isRecord$1(raw)) return null;
|
|
156715
|
+
const used = toInt(raw["verbraucht"]);
|
|
156716
|
+
const unlimited = accountUnlimited || raw["unlimited"] === true;
|
|
156717
|
+
const fraction = raw["anteil"];
|
|
156718
|
+
const resetAt = typeof raw["zuruecksetzung"] === "string" && raw["zuruecksetzung"].length > 0 ? raw["zuruecksetzung"] : void 0;
|
|
156719
|
+
if (unlimited) {
|
|
156720
|
+
if (used === null || used < 0) return null;
|
|
156721
|
+
return {
|
|
156722
|
+
id,
|
|
156723
|
+
label,
|
|
156724
|
+
used,
|
|
156725
|
+
limit: 0,
|
|
156726
|
+
unlimited: true,
|
|
156727
|
+
resetAt,
|
|
156728
|
+
resetHint: resetAt === void 0 ? void 0 : formatResetTime(resetAt)
|
|
156729
|
+
};
|
|
156730
|
+
}
|
|
156731
|
+
if (typeof fraction !== "number" || !Number.isFinite(fraction) || fraction < 0) return null;
|
|
156732
|
+
const limit = toInt(raw["grenze"]);
|
|
156733
|
+
const remaining = toInt(raw["uebrig"]);
|
|
156734
|
+
if (used === null || limit === null || remaining === null || used < 0 || limit < 0 || remaining < 0 || remaining !== Math.max(limit - used, 0)) return null;
|
|
156735
|
+
return {
|
|
156736
|
+
id,
|
|
156737
|
+
label,
|
|
156738
|
+
used,
|
|
156739
|
+
limit,
|
|
156740
|
+
fraction,
|
|
156741
|
+
remaining,
|
|
156742
|
+
resetAt,
|
|
156743
|
+
resetHint: resetAt === void 0 ? void 0 : formatResetTime(resetAt)
|
|
156744
|
+
};
|
|
156745
|
+
}
|
|
156636
156746
|
function toUsageRow(raw, defaultLabel) {
|
|
156637
156747
|
if (!isRecord$1(raw)) return null;
|
|
156748
|
+
const unlimited = raw["unlimited"] === true;
|
|
156638
156749
|
const limit = toInt(raw["limit"]);
|
|
156639
156750
|
let used = toInt(raw["used"]);
|
|
156751
|
+
const remaining = toInt(raw["remaining"]);
|
|
156752
|
+
if (unlimited) {
|
|
156753
|
+
if (used === null || used < 0) return null;
|
|
156754
|
+
const name = typeof raw["name"] === "string" ? raw["name"] : typeof raw["label"] === "string" ? raw["label"] : defaultLabel;
|
|
156755
|
+
const resetHint = resetHintFrom(raw);
|
|
156756
|
+
return {
|
|
156757
|
+
label: name,
|
|
156758
|
+
used,
|
|
156759
|
+
limit: 0,
|
|
156760
|
+
unlimited: true,
|
|
156761
|
+
...resetHint === void 0 ? {} : { resetHint }
|
|
156762
|
+
};
|
|
156763
|
+
}
|
|
156640
156764
|
if (used === null) {
|
|
156641
|
-
const remaining = toInt(raw["remaining"]);
|
|
156642
156765
|
if (remaining !== null && limit !== null) used = limit - remaining;
|
|
156643
156766
|
}
|
|
156644
|
-
if (used === null
|
|
156767
|
+
if (used === null || limit === null || used < 0 || limit < 0 || remaining !== null && (remaining < 0 || remaining !== Math.max(limit - used, 0))) return null;
|
|
156645
156768
|
const name = typeof raw["name"] === "string" ? raw["name"] : typeof raw["title"] === "string" ? raw["title"] : defaultLabel;
|
|
156646
156769
|
const resetHint = resetHintFrom(raw);
|
|
156647
156770
|
return {
|
|
156648
156771
|
label: name,
|
|
156649
|
-
used
|
|
156650
|
-
limit
|
|
156651
|
-
|
|
156772
|
+
used,
|
|
156773
|
+
limit,
|
|
156774
|
+
...remaining === null ? {} : { remaining },
|
|
156775
|
+
...resetHint === void 0 ? {} : { resetHint }
|
|
156652
156776
|
};
|
|
156653
156777
|
}
|
|
156654
156778
|
function limitLabel(item, detail, window, idx) {
|
|
@@ -156728,39 +156852,95 @@ function toInt(value) {
|
|
|
156728
156852
|
}
|
|
156729
156853
|
return null;
|
|
156730
156854
|
}
|
|
156855
|
+
async function managedUsageErrorCode(response) {
|
|
156856
|
+
if (response.status === 401) return "unauthenticated";
|
|
156857
|
+
if (response.status !== 403) return "unavailable";
|
|
156858
|
+
return isManagedQuotaErrorMessage(await readApiErrorMessage(response, "")) ? "unavailable" : "unauthenticated";
|
|
156859
|
+
}
|
|
156860
|
+
function isManagedQuotaErrorMessage(message) {
|
|
156861
|
+
if (message === void 0) return false;
|
|
156862
|
+
const normalized = message.toLowerCase();
|
|
156863
|
+
if (/\bquota\b.*\b(?:exceeded|exhausted|limit(?:ed)?)\b/.test(normalized)) return true;
|
|
156864
|
+
if (/\b(?:insufficient|no) credits?\b|\bpayment required\b/.test(normalized)) return true;
|
|
156865
|
+
return /you(?:'|’)?ve reached your usage limit/.test(normalized) && /billing cycle|quota will be (?:refreshed|reset)|purchase extra usage/.test(normalized);
|
|
156866
|
+
}
|
|
156867
|
+
function hasManagedUsageShape(payload) {
|
|
156868
|
+
if (!isRecord$1(payload)) return false;
|
|
156869
|
+
let recognized = false;
|
|
156870
|
+
if ("context_window_tokens" in payload || "contextWindowTokens" in payload) {
|
|
156871
|
+
recognized = true;
|
|
156872
|
+
if (managedContextWindowFrom(payload) === void 0) return false;
|
|
156873
|
+
}
|
|
156874
|
+
if ("usage" in payload) {
|
|
156875
|
+
recognized = true;
|
|
156876
|
+
if (payload["usage"] !== null && toUsageRow(payload["usage"], "Weekly limit") === null) return false;
|
|
156877
|
+
}
|
|
156878
|
+
if ("limits" in payload) {
|
|
156879
|
+
recognized = true;
|
|
156880
|
+
const limits = payload["limits"];
|
|
156881
|
+
if (!Array.isArray(limits)) return false;
|
|
156882
|
+
for (let index = 0; index < limits.length; index++) {
|
|
156883
|
+
const item = limits[index];
|
|
156884
|
+
if (!isRecord$1(item)) return false;
|
|
156885
|
+
const detail = isRecord$1(item["detail"]) ? item["detail"] : item;
|
|
156886
|
+
if (toUsageRow(detail, limitLabel(item, detail, isRecord$1(item["window"]) ? item["window"] : {}, index)) === null) return false;
|
|
156887
|
+
}
|
|
156888
|
+
}
|
|
156889
|
+
if ("stand" in payload) {
|
|
156890
|
+
recognized = true;
|
|
156891
|
+
const stand = payload["stand"];
|
|
156892
|
+
if (!isRecord$1(stand)) return false;
|
|
156893
|
+
const windows = ACCOUNT_USAGE_WINDOWS.filter(([sourceKey]) => sourceKey in stand);
|
|
156894
|
+
if (windows.length === 0) return false;
|
|
156895
|
+
const unlimited = payload["unlimited"] === true;
|
|
156896
|
+
for (const [sourceKey, id, label] of windows) if (toAccountUsageRow(stand[sourceKey], id, label, unlimited) === null) return false;
|
|
156897
|
+
}
|
|
156898
|
+
return recognized;
|
|
156899
|
+
}
|
|
156731
156900
|
async function fetchManagedUsage(url, accessToken, opts = {}) {
|
|
156732
156901
|
const controller = new AbortController();
|
|
156733
156902
|
const timer = setTimeout(() => {
|
|
156734
156903
|
controller.abort();
|
|
156735
156904
|
}, opts.timeoutMs ?? 8e3);
|
|
156905
|
+
timer.unref?.();
|
|
156736
156906
|
try {
|
|
156737
156907
|
const res = await fetch(url, {
|
|
156738
156908
|
headers: {
|
|
156739
156909
|
Authorization: `Bearer ${accessToken}`,
|
|
156740
156910
|
Accept: "application/json"
|
|
156741
156911
|
},
|
|
156742
|
-
signal: controller.signal
|
|
156912
|
+
signal: controller.signal,
|
|
156913
|
+
redirect: "error"
|
|
156743
156914
|
});
|
|
156744
156915
|
if (!res.ok) {
|
|
156745
156916
|
const status = res.status;
|
|
156746
156917
|
return {
|
|
156747
156918
|
kind: "error",
|
|
156748
|
-
|
|
156749
|
-
|
|
156919
|
+
code: await managedUsageErrorCode(res),
|
|
156920
|
+
status
|
|
156921
|
+
};
|
|
156922
|
+
}
|
|
156923
|
+
let json;
|
|
156924
|
+
try {
|
|
156925
|
+
json = await res.json();
|
|
156926
|
+
} catch {
|
|
156927
|
+
return {
|
|
156928
|
+
kind: "error",
|
|
156929
|
+
code: "invalid_payload"
|
|
156750
156930
|
};
|
|
156751
156931
|
}
|
|
156932
|
+
if (!hasManagedUsageShape(json)) return {
|
|
156933
|
+
kind: "error",
|
|
156934
|
+
code: "invalid_payload"
|
|
156935
|
+
};
|
|
156752
156936
|
return {
|
|
156753
156937
|
kind: "ok",
|
|
156754
|
-
parsed: parseManagedUsagePayload(
|
|
156755
|
-
};
|
|
156756
|
-
} catch (error) {
|
|
156757
|
-
if (error instanceof Error && error.name === "AbortError") return {
|
|
156758
|
-
kind: "error",
|
|
156759
|
-
message: "Failed to fetch usage: request timed out."
|
|
156938
|
+
parsed: parseManagedUsagePayload(json)
|
|
156760
156939
|
};
|
|
156940
|
+
} catch {
|
|
156761
156941
|
return {
|
|
156762
156942
|
kind: "error",
|
|
156763
|
-
|
|
156943
|
+
code: "unavailable"
|
|
156764
156944
|
};
|
|
156765
156945
|
} finally {
|
|
156766
156946
|
clearTimeout(timer);
|
|
@@ -156854,8 +157034,8 @@ function normalizeEndpoint(value) {
|
|
|
156854
157034
|
}
|
|
156855
157035
|
function persistedOAuthHost(options) {
|
|
156856
157036
|
const oauthHost = options.oauthHost;
|
|
156857
|
-
const normalized = normalizeEndpoint(oauthHost ?? "https://
|
|
156858
|
-
if (options.key === "oauth/blun" && normalized === normalizeEndpoint("https://
|
|
157037
|
+
const normalized = normalizeEndpoint(oauthHost ?? "https://account.blun.ai");
|
|
157038
|
+
if (options.key === "oauth/blun" && normalized === normalizeEndpoint("https://account.blun.ai")) return;
|
|
156859
157039
|
return normalized;
|
|
156860
157040
|
}
|
|
156861
157041
|
function managedOAuthRef(options) {
|
|
@@ -156882,11 +157062,12 @@ function blunCodeEnvBaseUrl(env = process.env) {
|
|
|
156882
157062
|
function blunCodeEnvOAuthHost(env = process.env) {
|
|
156883
157063
|
return env.BLUN_OAUTH_HOST;
|
|
156884
157064
|
}
|
|
156885
|
-
const SHARED_DEFAULT_BASE_URLS = [normalizeEndpoint(DEFAULT_BLUN_BASE_URL)];
|
|
157065
|
+
const SHARED_DEFAULT_BASE_URLS = new Set([normalizeEndpoint(DEFAULT_BLUN_BASE_URL), normalizeEndpoint(DEFAULT_BLUN_AUXILIARY_BASE_URL)]);
|
|
157066
|
+
const SHARED_DEFAULT_OAUTH_HOSTS = new Set([normalizeEndpoint(DEFAULT_BLUN_OAUTH_HOST), normalizeEndpoint("https://auth.blun.ai")]);
|
|
156886
157067
|
function resolveBlunCodeOAuthKey(options) {
|
|
156887
|
-
const oauthHost = normalizeEndpoint(options.oauthHost ?? "https://
|
|
157068
|
+
const oauthHost = normalizeEndpoint(options.oauthHost ?? "https://account.blun.ai");
|
|
156888
157069
|
const baseUrl = defaultBaseUrl(options.baseUrl);
|
|
156889
|
-
if (oauthHost
|
|
157070
|
+
if (SHARED_DEFAULT_OAUTH_HOSTS.has(oauthHost) && SHARED_DEFAULT_BASE_URLS.has(baseUrl)) return BLUN_OAUTH_KEY;
|
|
156890
157071
|
return `${BLUN_SCOPED_OAUTH_KEY_PREFIX}${createHash("sha256").update(JSON.stringify({
|
|
156891
157072
|
oauthHost,
|
|
156892
157073
|
baseUrl
|
|
@@ -156965,11 +157146,27 @@ function resolveBlunCodeLoginAuth(options) {
|
|
|
156965
157146
|
oauthHost
|
|
156966
157147
|
};
|
|
156967
157148
|
}
|
|
157149
|
+
const MODEL_CONTEXT_LENGTH_FIELDS = [
|
|
157150
|
+
"context_length",
|
|
157151
|
+
"max_model_len",
|
|
157152
|
+
"context_window"
|
|
157153
|
+
];
|
|
157154
|
+
function parseModelContextLength(item, modelId) {
|
|
157155
|
+
let contextLength;
|
|
157156
|
+
for (const field of MODEL_CONTEXT_LENGTH_FIELDS) {
|
|
157157
|
+
if (!Object.hasOwn(item, field)) continue;
|
|
157158
|
+
const length = Number(item[field]);
|
|
157159
|
+
if (!Number.isInteger(length) || length <= 0) throw new Error(`Model "${modelId}" must include a positive context_length, max_model_len, or context_window.`);
|
|
157160
|
+
if (contextLength !== void 0 && contextLength !== length) throw new Error(`Model "${modelId}" reports conflicting context length values.`);
|
|
157161
|
+
contextLength = length;
|
|
157162
|
+
}
|
|
157163
|
+
if (contextLength === void 0) throw new Error(`Model "${modelId}" must include a positive context_length, max_model_len, or context_window.`);
|
|
157164
|
+
return contextLength;
|
|
157165
|
+
}
|
|
156968
157166
|
function toModelInfo$1(item, blunOnly) {
|
|
156969
157167
|
if (!isRecord$1(item) || typeof item["id"] !== "string" || item["id"].length === 0) return;
|
|
156970
157168
|
if (blunOnly && !isNativeModelProtocol(item["protocol"])) return void 0;
|
|
156971
|
-
const contextLength =
|
|
156972
|
-
if (!Number.isInteger(contextLength) || contextLength <= 0) throw new Error(`BLUN model "${item["id"]}" must include a positive context_length.`);
|
|
157169
|
+
const contextLength = parseModelContextLength(item, item["id"]);
|
|
156973
157170
|
const displayName = item["display_name"];
|
|
156974
157171
|
const normalizedDisplayName = typeof displayName === "string" && displayName.length > 0 ? displayName : void 0;
|
|
156975
157172
|
const supportsToolUse = Object.hasOwn(item, "supports_tool_use") ? Boolean(item["supports_tool_use"]) : true;
|
|
@@ -157024,6 +157221,7 @@ async function fetchManagedBlunCodeModels(options) {
|
|
|
157024
157221
|
const baseUrl = defaultBaseUrl(options.baseUrl);
|
|
157025
157222
|
const response = await fetchImpl(`${baseUrl}/models`, {
|
|
157026
157223
|
signal: options.signal,
|
|
157224
|
+
redirect: "error",
|
|
157027
157225
|
headers: {
|
|
157028
157226
|
...parseBlunCodeCustomHeaders(),
|
|
157029
157227
|
...options.headers,
|
|
@@ -157094,15 +157292,16 @@ function applyManagedBlunCodeConfig(config, options) {
|
|
|
157094
157292
|
...config.thinking,
|
|
157095
157293
|
enabled: selectedDefault.thinking
|
|
157096
157294
|
};
|
|
157295
|
+
const auxiliaryBaseUrl = blunCodeAuxiliaryBaseUrl(baseUrl);
|
|
157097
157296
|
config.services = {
|
|
157098
157297
|
...config.services,
|
|
157099
157298
|
blunSearch: {
|
|
157100
|
-
baseUrl: `${
|
|
157299
|
+
baseUrl: `${auxiliaryBaseUrl}/search`,
|
|
157101
157300
|
apiKey,
|
|
157102
157301
|
oauth
|
|
157103
157302
|
},
|
|
157104
157303
|
blunFetch: {
|
|
157105
|
-
baseUrl: `${
|
|
157304
|
+
baseUrl: `${auxiliaryBaseUrl}/fetch`,
|
|
157106
157305
|
apiKey,
|
|
157107
157306
|
oauth
|
|
157108
157307
|
}
|
|
@@ -157181,6 +157380,116 @@ async function provisionManagedBlunCodeConfig(options) {
|
|
|
157181
157380
|
};
|
|
157182
157381
|
}
|
|
157183
157382
|
//#endregion
|
|
157383
|
+
//#region ../../packages/oauth/src/managed-quota.ts
|
|
157384
|
+
const MANAGED_QUOTA_PATH = "/api/verbrauch/mein-stand";
|
|
157385
|
+
const REQUIRED_WINDOWS = [
|
|
157386
|
+
["fuenf_stunden", "five_hours"],
|
|
157387
|
+
["sieben_tage", "seven_days"],
|
|
157388
|
+
["monat", "month"]
|
|
157389
|
+
];
|
|
157390
|
+
function blunManagedQuotaUrl(oauthHost) {
|
|
157391
|
+
return `${(oauthHost ?? process.env["BLUN_OAUTH_HOST"] ?? "https://account.blun.ai").replace(/\/+$/, "")}${MANAGED_QUOTA_PATH}`;
|
|
157392
|
+
}
|
|
157393
|
+
function parseManagedQuotaPayload(payload) {
|
|
157394
|
+
if (!isRecord$1(payload)) return void 0;
|
|
157395
|
+
const plan = nonEmptyString$3(payload["plan"]);
|
|
157396
|
+
const paid = payload["bezahlt"];
|
|
157397
|
+
const creditCents = payload["guthaben_cent"];
|
|
157398
|
+
const billingKind = nonEmptyString$3(payload["art"]);
|
|
157399
|
+
const globalUnlimited = payload["unlimited"];
|
|
157400
|
+
if (plan === void 0 || typeof paid !== "boolean" || !Number.isSafeInteger(creditCents) || creditCents < 0 || billingKind === void 0 || globalUnlimited !== void 0 && typeof globalUnlimited !== "boolean" || !isRecord$1(payload["stand"])) return;
|
|
157401
|
+
if (!hasStrictQuotaStand(payload["stand"], globalUnlimited === true)) return void 0;
|
|
157402
|
+
const limits = parseManagedUsagePayload(payload).limits;
|
|
157403
|
+
if (limits.length !== REQUIRED_WINDOWS.length || REQUIRED_WINDOWS.some(([, id]) => limits.filter((row) => row.id === id).length !== 1)) return;
|
|
157404
|
+
return {
|
|
157405
|
+
plan,
|
|
157406
|
+
paid,
|
|
157407
|
+
creditCents,
|
|
157408
|
+
billingKind,
|
|
157409
|
+
limits
|
|
157410
|
+
};
|
|
157411
|
+
}
|
|
157412
|
+
async function fetchManagedQuota(url, accessToken, opts = {}) {
|
|
157413
|
+
const controller = new AbortController();
|
|
157414
|
+
const timer = setTimeout(() => {
|
|
157415
|
+
controller.abort();
|
|
157416
|
+
}, opts.timeoutMs ?? 8e3);
|
|
157417
|
+
timer.unref?.();
|
|
157418
|
+
try {
|
|
157419
|
+
const response = await fetch(url, {
|
|
157420
|
+
headers: {
|
|
157421
|
+
Authorization: `Bearer ${accessToken}`,
|
|
157422
|
+
Accept: "application/json"
|
|
157423
|
+
},
|
|
157424
|
+
signal: controller.signal,
|
|
157425
|
+
redirect: "error"
|
|
157426
|
+
});
|
|
157427
|
+
if (!response.ok) return {
|
|
157428
|
+
kind: "error",
|
|
157429
|
+
code: await managedQuotaErrorCode(response),
|
|
157430
|
+
status: response.status
|
|
157431
|
+
};
|
|
157432
|
+
let payload;
|
|
157433
|
+
try {
|
|
157434
|
+
payload = await response.json();
|
|
157435
|
+
} catch {
|
|
157436
|
+
return {
|
|
157437
|
+
kind: "error",
|
|
157438
|
+
code: "invalid_payload"
|
|
157439
|
+
};
|
|
157440
|
+
}
|
|
157441
|
+
const parsed = parseManagedQuotaPayload(payload);
|
|
157442
|
+
return parsed === void 0 ? {
|
|
157443
|
+
kind: "error",
|
|
157444
|
+
code: "invalid_payload"
|
|
157445
|
+
} : {
|
|
157446
|
+
kind: "ok",
|
|
157447
|
+
parsed
|
|
157448
|
+
};
|
|
157449
|
+
} catch {
|
|
157450
|
+
return {
|
|
157451
|
+
kind: "error",
|
|
157452
|
+
code: "unavailable"
|
|
157453
|
+
};
|
|
157454
|
+
} finally {
|
|
157455
|
+
clearTimeout(timer);
|
|
157456
|
+
}
|
|
157457
|
+
}
|
|
157458
|
+
async function managedQuotaErrorCode(response) {
|
|
157459
|
+
if (response.status === 401) return "unauthenticated";
|
|
157460
|
+
if (response.status !== 403) return "unavailable";
|
|
157461
|
+
return isManagedQuotaErrorMessage(await readApiErrorMessage(response, "")) ? "unavailable" : "unauthenticated";
|
|
157462
|
+
}
|
|
157463
|
+
function nonEmptyString$3(value) {
|
|
157464
|
+
if (typeof value !== "string") return void 0;
|
|
157465
|
+
const normalized = value.trim();
|
|
157466
|
+
return normalized.length === 0 ? void 0 : normalized;
|
|
157467
|
+
}
|
|
157468
|
+
function hasStrictQuotaStand(stand, globalUnlimited) {
|
|
157469
|
+
return REQUIRED_WINDOWS.every(([sourceKey]) => {
|
|
157470
|
+
const row = stand[sourceKey];
|
|
157471
|
+
if (!isRecord$1(row)) return false;
|
|
157472
|
+
const used = row["verbraucht"];
|
|
157473
|
+
const rowUnlimited = row["unlimited"];
|
|
157474
|
+
if (rowUnlimited !== void 0 && typeof rowUnlimited !== "boolean") return false;
|
|
157475
|
+
const resetAt = row["zuruecksetzung"];
|
|
157476
|
+
if (!hasValidResetAt(resetAt)) return false;
|
|
157477
|
+
if (globalUnlimited || rowUnlimited === true) return isNonNegativeSafeInteger(used);
|
|
157478
|
+
const limit = row["grenze"];
|
|
157479
|
+
const remaining = row["uebrig"];
|
|
157480
|
+
const fraction = row["anteil"];
|
|
157481
|
+
return isNonNegativeSafeInteger(used) && isNonNegativeSafeInteger(limit) && isNonNegativeSafeInteger(remaining) && remaining === Math.max(limit - used, 0) && typeof fraction === "number" && Number.isFinite(fraction) && fraction >= 0;
|
|
157482
|
+
});
|
|
157483
|
+
}
|
|
157484
|
+
function isNonNegativeSafeInteger(value) {
|
|
157485
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
157486
|
+
}
|
|
157487
|
+
function hasValidResetAt(value) {
|
|
157488
|
+
if (value === null) return true;
|
|
157489
|
+
if (typeof value !== "string") return false;
|
|
157490
|
+
return /(?:Z|[+-]\d{2}:\d{2})$/i.test(value) && Number.isFinite(Date.parse(value));
|
|
157491
|
+
}
|
|
157492
|
+
//#endregion
|
|
157184
157493
|
//#region ../../packages/oauth/src/managed-feedback.ts
|
|
157185
157494
|
/**
|
|
157186
157495
|
* Submit user feedback to the managed BLUN King platform.
|
|
@@ -157190,7 +157499,7 @@ async function provisionManagedBlunCodeConfig(options) {
|
|
|
157190
157499
|
* backend can identify this client.
|
|
157191
157500
|
*/
|
|
157192
157501
|
function blunCodeFeedbackUrl(baseUrl) {
|
|
157193
|
-
return `${(baseUrl
|
|
157502
|
+
return `${blunCodeAuxiliaryBaseUrl(baseUrl)}/feedback`;
|
|
157194
157503
|
}
|
|
157195
157504
|
async function fetchSubmitFeedback(url, accessToken, body, opts = {}) {
|
|
157196
157505
|
const controller = new AbortController();
|
|
@@ -157313,7 +157622,7 @@ async function postJson(url, accessToken, body, opts) {
|
|
|
157313
157622
|
}
|
|
157314
157623
|
}
|
|
157315
157624
|
function feedbackBaseUrl(baseUrl) {
|
|
157316
|
-
return (baseUrl
|
|
157625
|
+
return blunCodeAuxiliaryBaseUrl(baseUrl);
|
|
157317
157626
|
}
|
|
157318
157627
|
function readUpload(payload) {
|
|
157319
157628
|
const upload = readRecord(payload, "upload");
|
|
@@ -157552,18 +157861,40 @@ var BlunOAuthToolkit = class {
|
|
|
157552
157861
|
async getManagedUsage(providerName, options = {}) {
|
|
157553
157862
|
const name = providerName ?? "managed:blun";
|
|
157554
157863
|
try {
|
|
157555
|
-
const
|
|
157556
|
-
const
|
|
157864
|
+
const oauthRef = options.oauthRef ?? this.defaultOAuthRef(options.baseUrl);
|
|
157865
|
+
const accessToken = await this.ensureFresh(name, { oauthRef });
|
|
157866
|
+
const oauthHost = this.oauthHostFor(oauthRef);
|
|
157867
|
+
const result = await fetchManagedUsage(blunManagedQuotaUrl(oauthHost), accessToken);
|
|
157557
157868
|
if (result.kind === "error") return result;
|
|
157869
|
+
const contextWindowTokens = result.parsed.contextWindowTokens ?? (result.parsed.plan === void 0 ? void 0 : await fetchManagedContextWindow(blunContextWindowsUrl(oauthHost), result.parsed.plan));
|
|
157558
157870
|
return {
|
|
157559
157871
|
kind: "ok",
|
|
157560
|
-
|
|
157561
|
-
|
|
157872
|
+
...result.parsed,
|
|
157873
|
+
...contextWindowTokens === void 0 ? {} : { contextWindowTokens }
|
|
157562
157874
|
};
|
|
157563
157875
|
} catch (error) {
|
|
157876
|
+
if (error instanceof OAuthUnauthorizedError) return {
|
|
157877
|
+
kind: "error",
|
|
157878
|
+
code: "unauthenticated"
|
|
157879
|
+
};
|
|
157564
157880
|
return {
|
|
157565
157881
|
kind: "error",
|
|
157566
|
-
|
|
157882
|
+
code: "unavailable"
|
|
157883
|
+
};
|
|
157884
|
+
}
|
|
157885
|
+
}
|
|
157886
|
+
async getManagedQuota(providerName, oauthRef = this.defaultOAuthRef()) {
|
|
157887
|
+
try {
|
|
157888
|
+
const accessToken = await this.ensureFresh(providerName ?? "managed:blun", { oauthRef });
|
|
157889
|
+
const result = await fetchManagedQuota(blunManagedQuotaUrl(this.oauthHostFor(oauthRef)), accessToken);
|
|
157890
|
+
return result.kind === "ok" ? {
|
|
157891
|
+
kind: "ok",
|
|
157892
|
+
...result.parsed
|
|
157893
|
+
} : result;
|
|
157894
|
+
} catch (error) {
|
|
157895
|
+
return {
|
|
157896
|
+
kind: "error",
|
|
157897
|
+
code: error instanceof OAuthUnauthorizedError ? "unauthenticated" : "unavailable"
|
|
157567
157898
|
};
|
|
157568
157899
|
}
|
|
157569
157900
|
}
|
|
@@ -157650,10 +157981,6 @@ function defaultBlunHome() {
|
|
|
157650
157981
|
if (override !== void 0 && override.length > 0) return override;
|
|
157651
157982
|
return join(homedir(), ".blun");
|
|
157652
157983
|
}
|
|
157653
|
-
function managedUsageUrl(baseUrl) {
|
|
157654
|
-
if (baseUrl === void 0) return blunCodeUsageUrl();
|
|
157655
|
-
return `${baseUrl.replace(/\/+$/, "")}/usages`;
|
|
157656
|
-
}
|
|
157657
157984
|
function managedFeedbackUrl(baseUrl) {
|
|
157658
157985
|
return blunCodeFeedbackUrl(baseUrl);
|
|
157659
157986
|
}
|
|
@@ -168961,6 +169288,22 @@ var BlunAuthFacade = class {
|
|
|
168961
169288
|
baseUrl: auth.baseUrl
|
|
168962
169289
|
});
|
|
168963
169290
|
}
|
|
169291
|
+
async getManagedQuota(providerName) {
|
|
169292
|
+
const auth = this.resolveManagedAuth(providerName);
|
|
169293
|
+
const apiKey = auth.apiKey?.trim();
|
|
169294
|
+
if (apiKey) {
|
|
169295
|
+
if (auth.oauthRef !== void 0 || auth.baseUrl !== void 0 && auth.baseUrl.replace(/\/+$/, "") !== "https://api.blun.ai/v1") return {
|
|
169296
|
+
kind: "error",
|
|
169297
|
+
code: "unavailable"
|
|
169298
|
+
};
|
|
169299
|
+
const result = await fetchManagedQuota(blunManagedQuotaUrl(DEFAULT_BLUN_OAUTH_HOST), apiKey);
|
|
169300
|
+
return result.kind === "ok" ? {
|
|
169301
|
+
kind: "ok",
|
|
169302
|
+
...result.parsed
|
|
169303
|
+
} : result;
|
|
169304
|
+
}
|
|
169305
|
+
return this.toolkit.getManagedQuota(providerName, this.resolveRuntimeManagedAuth(providerName).oauthRef);
|
|
169306
|
+
}
|
|
168964
169307
|
async submitFeedback(input, providerName) {
|
|
168965
169308
|
const auth = this.resolveRuntimeManagedAuth(providerName);
|
|
168966
169309
|
return this.toolkit.submitFeedback({
|
|
@@ -169711,7 +170054,7 @@ function optionalBuildString(value) {
|
|
|
169711
170054
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
169712
170055
|
}
|
|
169713
170056
|
const BLUN_BUILD_INFO = {
|
|
169714
|
-
version: optionalBuildString("9.1.
|
|
170057
|
+
version: optionalBuildString("9.1.652"),
|
|
169715
170058
|
channel: typeof __BLUN_CHANNEL__ === "string" ? optionalBuildString(__BLUN_CHANNEL__) : void 0,
|
|
169716
170059
|
commit: typeof __BLUN_COMMIT__ === "string" ? optionalBuildString(__BLUN_COMMIT__) : void 0,
|
|
169717
170060
|
buildTarget: typeof __BLUN_BUILD_TARGET__ === "string" ? optionalBuildString(__BLUN_BUILD_TARGET__) : void 0
|