@camstack/addon-ai 0.4.29 → 0.4.31
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/dist/addon.js +142 -159
- package/dist/addon.mjs +154 -170
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -4,14 +4,11 @@ Object.defineProperties(exports, {
|
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("./chunk-CVvi-lCc.js");
|
|
6
6
|
let node_path = require("node:path");
|
|
7
|
-
let node_path$1 = require_chunk.__toESM(node_path, 1);
|
|
8
7
|
node_path = require_chunk.__toESM(node_path);
|
|
9
8
|
let node_crypto = require("node:crypto");
|
|
10
9
|
let node_net = require("node:net");
|
|
11
10
|
let node_fs = require("node:fs");
|
|
12
|
-
|
|
13
|
-
let node_util = require("node:util");
|
|
14
|
-
let node_zlib = require("node:zlib");
|
|
11
|
+
let _camstack_system_addon_utils = require("@camstack/system/addon-utils");
|
|
15
12
|
let node_fs_promises = require("node:fs/promises");
|
|
16
13
|
node_fs_promises = require_chunk.__toESM(node_fs_promises);
|
|
17
14
|
let node_child_process = require("node:child_process");
|
|
@@ -6079,6 +6076,40 @@ var BaseAddon = class {
|
|
|
6079
6076
|
deviceSettingsSchema() {
|
|
6080
6077
|
return null;
|
|
6081
6078
|
}
|
|
6079
|
+
/**
|
|
6080
|
+
* INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
|
|
6081
|
+
* ARE the configuration of its integration.
|
|
6082
|
+
*
|
|
6083
|
+
* Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
|
|
6084
|
+
* operator should find on the addon's integration page (System →
|
|
6085
|
+
* Integrations → <name>) rather than only in the cluster-wide list of every
|
|
6086
|
+
* addon. Empty (the default) means the addon has no integration-level
|
|
6087
|
+
* settings and no such surface is offered — this is opt-in, because whether
|
|
6088
|
+
* an addon's configuration IS its integration's configuration depends on the
|
|
6089
|
+
* nature of the integration.
|
|
6090
|
+
*
|
|
6091
|
+
* WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
|
|
6092
|
+
* the ONE global schema, in the ONE addon store, written by the ONE
|
|
6093
|
+
* `updateGlobalSettings` path. There is deliberately no
|
|
6094
|
+
* `updateIntegrationSettings`: a second write path is how a surface acquires
|
|
6095
|
+
* a second store key, and this repo has shipped that twice (`btmPath@hub`,
|
|
6096
|
+
* D266). Selecting sections cannot introduce a key that selecting cannot.
|
|
6097
|
+
*
|
|
6098
|
+
* WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
|
|
6099
|
+
* `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
|
|
6100
|
+
* removed with the reason recorded at
|
|
6101
|
+
* `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
|
|
6102
|
+
* determined by WHICH schema it lives in, not by a field-level marker."* A
|
|
6103
|
+
* marker sprinkled across sections also has to borrow a field that already
|
|
6104
|
+
* means something else; borrowing `section.tab` put the literal word
|
|
6105
|
+
* "integration" into an operator-facing tab bar, because `tab` means "how to
|
|
6106
|
+
* GROUP this visually" and cannot also mean "where this lives" (D269
|
|
6107
|
+
* supersedes D268). One declaration, in one place, next to the schema whose
|
|
6108
|
+
* ids it names.
|
|
6109
|
+
*/
|
|
6110
|
+
integrationSettingSections() {
|
|
6111
|
+
return [];
|
|
6112
|
+
}
|
|
6082
6113
|
async getGlobalSettings(overlay, cap, nodeId) {
|
|
6083
6114
|
const schema = this.globalSettingsSchema(cap);
|
|
6084
6115
|
if (!schema) return { sections: [] };
|
|
@@ -6089,6 +6120,55 @@ var BaseAddon = class {
|
|
|
6089
6120
|
} : projected);
|
|
6090
6121
|
}
|
|
6091
6122
|
/**
|
|
6123
|
+
* The integration-level view of this addon's settings: exactly the sections
|
|
6124
|
+
* named by {@link integrationSettingSections}, hydrated from the SAME store
|
|
6125
|
+
* `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
|
|
6126
|
+
*
|
|
6127
|
+
* Returns `null` when the addon declared nothing — an addon that opts out has
|
|
6128
|
+
* no integration settings surface at all, rather than an empty one that reads
|
|
6129
|
+
* as a failed load.
|
|
6130
|
+
*
|
|
6131
|
+
* Three properties hold BY CONSTRUCTION, which is why they are here in core
|
|
6132
|
+
* and not in whichever UI happens to render this:
|
|
6133
|
+
*
|
|
6134
|
+
* 1. **One key.** The payload is a SUBSET of the global schema, so a field
|
|
6135
|
+
* shown here is the same field, with the same bare key, that the addon's
|
|
6136
|
+
* own page shows. There is no integration-specific writer — callers save
|
|
6137
|
+
* through `updateGlobalSettings` — so a second store key is unreachable,
|
|
6138
|
+
* not merely discouraged.
|
|
6139
|
+
* 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
|
|
6140
|
+
* is `<key>@<nodeId>` and an integration is not a node; whichever node
|
|
6141
|
+
* such a field silently picked would be a wrong answer for the operator
|
|
6142
|
+
* who opened the page (D266).
|
|
6143
|
+
* 3. **No silent typo.** A declared id that names no section throws. The
|
|
6144
|
+
* alternative — skip it — turns a rename into a surface that quietly
|
|
6145
|
+
* empties, which looks exactly like an addon with nothing to configure.
|
|
6146
|
+
*/
|
|
6147
|
+
async getIntegrationSettings(nodeId) {
|
|
6148
|
+
const declared = this.integrationSettingSections();
|
|
6149
|
+
if (declared.length === 0) return null;
|
|
6150
|
+
const schema = this.globalSettingsSchema();
|
|
6151
|
+
if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
|
|
6152
|
+
const byId = new Map(schema.sections.map((section) => [section.id, section]));
|
|
6153
|
+
const sections = [];
|
|
6154
|
+
for (const id of declared) {
|
|
6155
|
+
const section = byId.get(id);
|
|
6156
|
+
if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
|
|
6157
|
+
const fields = dropPerNodeFields(section.fields);
|
|
6158
|
+
if (fields.length === 0) continue;
|
|
6159
|
+
sections.push({
|
|
6160
|
+
...section,
|
|
6161
|
+
fields
|
|
6162
|
+
});
|
|
6163
|
+
}
|
|
6164
|
+
if (sections.length === 0) return null;
|
|
6165
|
+
const projected = await this.resolveGlobalStore(nodeId);
|
|
6166
|
+
return hydrateSchema({
|
|
6167
|
+
...schema,
|
|
6168
|
+
sections
|
|
6169
|
+
}, projected);
|
|
6170
|
+
}
|
|
6171
|
+
/**
|
|
6092
6172
|
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
6093
6173
|
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
6094
6174
|
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
@@ -6392,6 +6472,41 @@ var BaseAddon = class {
|
|
|
6392
6472
|
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6393
6473
|
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6394
6474
|
*/
|
|
6475
|
+
/**
|
|
6476
|
+
* The same fields with every `perNode: true` one removed, recursing into layout
|
|
6477
|
+
* containers exactly as {@link collectPerNodeFieldKeys} does. A container left
|
|
6478
|
+
* with no child is dropped rather than rendered empty.
|
|
6479
|
+
*
|
|
6480
|
+
* Used by `getIntegrationSettings`: an integration is not a node, so a field
|
|
6481
|
+
* whose store key is `<key>@<nodeId>` has no node to belong to there.
|
|
6482
|
+
*/
|
|
6483
|
+
function dropPerNodeFields(fields) {
|
|
6484
|
+
const kept = [];
|
|
6485
|
+
for (const field of fields) {
|
|
6486
|
+
if (field.type === "group") {
|
|
6487
|
+
const inner = dropPerNodeFields(field.fields);
|
|
6488
|
+
if (inner.length > 0) kept.push({
|
|
6489
|
+
...field,
|
|
6490
|
+
fields: inner
|
|
6491
|
+
});
|
|
6492
|
+
continue;
|
|
6493
|
+
}
|
|
6494
|
+
if (field.type === "sub-tabs") {
|
|
6495
|
+
const tabs = field.tabs.map((tab) => ({
|
|
6496
|
+
...tab,
|
|
6497
|
+
fields: dropPerNodeFields(tab.fields)
|
|
6498
|
+
})).filter((tab) => tab.fields.length > 0);
|
|
6499
|
+
if (tabs.length > 0) kept.push({
|
|
6500
|
+
...field,
|
|
6501
|
+
tabs
|
|
6502
|
+
});
|
|
6503
|
+
continue;
|
|
6504
|
+
}
|
|
6505
|
+
if ("perNode" in field && field.perNode === true) continue;
|
|
6506
|
+
kept.push(field);
|
|
6507
|
+
}
|
|
6508
|
+
return kept;
|
|
6509
|
+
}
|
|
6395
6510
|
function collectPerNodeFieldKeys(fields) {
|
|
6396
6511
|
const collected = [];
|
|
6397
6512
|
for (const field of fields) {
|
|
@@ -9604,6 +9719,9 @@ method(object({
|
|
|
9604
9719
|
kind: "mutation",
|
|
9605
9720
|
auth: "admin"
|
|
9606
9721
|
}), method(object({
|
|
9722
|
+
addonId: string(),
|
|
9723
|
+
nodeId: string().optional()
|
|
9724
|
+
}), SettingsSchemaWithValuesSchema.nullable()), method(object({
|
|
9607
9725
|
addonId: string(),
|
|
9608
9726
|
deviceId: number$1(),
|
|
9609
9727
|
nodeId: string().optional()
|
|
@@ -28092,6 +28210,12 @@ Object.freeze({
|
|
|
28092
28210
|
addonId: null,
|
|
28093
28211
|
access: "view"
|
|
28094
28212
|
},
|
|
28213
|
+
"addonSettings.getIntegrationSettings": {
|
|
28214
|
+
capName: "addon-settings",
|
|
28215
|
+
capScope: "system",
|
|
28216
|
+
addonId: null,
|
|
28217
|
+
access: "view"
|
|
28218
|
+
},
|
|
28095
28219
|
"addonSettings.updateDeviceSettings": {
|
|
28096
28220
|
capName: "addon-settings",
|
|
28097
28221
|
capScope: "system",
|
|
@@ -61226,12 +61350,12 @@ var require_auth_config = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61226
61350
|
});
|
|
61227
61351
|
module.exports = __toCommonJS(auth_config_exports);
|
|
61228
61352
|
var fs$1 = __toESM(require("fs"));
|
|
61229
|
-
var path$
|
|
61353
|
+
var path$1 = __toESM(require("path"));
|
|
61230
61354
|
var import_token_util = require_token_util();
|
|
61231
61355
|
function getAuthConfigPath() {
|
|
61232
61356
|
const dataDir = (0, import_token_util.getVercelDataDir)();
|
|
61233
61357
|
if (!dataDir) throw new Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);
|
|
61234
|
-
return path$
|
|
61358
|
+
return path$1.join(dataDir, "auth.json");
|
|
61235
61359
|
}
|
|
61236
61360
|
function readAuthConfig() {
|
|
61237
61361
|
try {
|
|
@@ -61246,7 +61370,7 @@ var require_auth_config = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61246
61370
|
}
|
|
61247
61371
|
function writeAuthConfig(config) {
|
|
61248
61372
|
const authPath = getAuthConfigPath();
|
|
61249
|
-
const authDir = path$
|
|
61373
|
+
const authDir = path$1.dirname(authPath);
|
|
61250
61374
|
if (!fs$1.existsSync(authDir)) fs$1.mkdirSync(authDir, {
|
|
61251
61375
|
mode: 504,
|
|
61252
61376
|
recursive: true
|
|
@@ -61384,7 +61508,7 @@ var require_token_util = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61384
61508
|
saveToken: () => saveToken
|
|
61385
61509
|
});
|
|
61386
61510
|
module.exports = __toCommonJS(token_util_exports);
|
|
61387
|
-
var path
|
|
61511
|
+
var path = __toESM(require("path"));
|
|
61388
61512
|
var fs = __toESM(require("fs"));
|
|
61389
61513
|
var import_token_error = require_token_error();
|
|
61390
61514
|
var import_token_io = require_token_io();
|
|
@@ -61395,7 +61519,7 @@ var require_token_util = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61395
61519
|
const vercelFolder = "com.vercel.cli";
|
|
61396
61520
|
const dataDir = (0, import_token_io.getUserDataDir)();
|
|
61397
61521
|
if (!dataDir) return null;
|
|
61398
|
-
return path
|
|
61522
|
+
return path.join(dataDir, vercelFolder);
|
|
61399
61523
|
}
|
|
61400
61524
|
async function getVercelToken(options) {
|
|
61401
61525
|
const authConfig = (0, import_auth_config.readAuthConfig)();
|
|
@@ -61443,7 +61567,7 @@ var require_token_util = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61443
61567
|
function findProjectInfo() {
|
|
61444
61568
|
const dir = (0, import_token_io.findRootDir)();
|
|
61445
61569
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
|
|
61446
|
-
const prjPath = path
|
|
61570
|
+
const prjPath = path.join(dir, ".vercel", "project.json");
|
|
61447
61571
|
if (!fs.existsSync(prjPath)) throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
|
|
61448
61572
|
const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
|
|
61449
61573
|
if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
|
|
@@ -61455,9 +61579,9 @@ var require_token_util = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61455
61579
|
function saveToken(token, projectId) {
|
|
61456
61580
|
const dir = (0, import_token_io.getUserDataDir)();
|
|
61457
61581
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
61458
|
-
const tokenPath = path
|
|
61582
|
+
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61459
61583
|
const tokenJson = JSON.stringify(token);
|
|
61460
|
-
fs.mkdirSync(path
|
|
61584
|
+
fs.mkdirSync(path.dirname(tokenPath), {
|
|
61461
61585
|
mode: 504,
|
|
61462
61586
|
recursive: true
|
|
61463
61587
|
});
|
|
@@ -61467,7 +61591,7 @@ var require_token_util = /* @__PURE__ */ require_chunk.__commonJSMin(((exports,
|
|
|
61467
61591
|
function loadToken(projectId) {
|
|
61468
61592
|
const dir = (0, import_token_io.getUserDataDir)();
|
|
61469
61593
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
61470
|
-
const tokenPath = path
|
|
61594
|
+
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61471
61595
|
if (!fs.existsSync(tokenPath)) return null;
|
|
61472
61596
|
const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
|
|
61473
61597
|
assertVercelOidcTokenResponse(token);
|
|
@@ -73473,147 +73597,6 @@ function entryForRef(ref) {
|
|
|
73473
73597
|
};
|
|
73474
73598
|
}
|
|
73475
73599
|
//#endregion
|
|
73476
|
-
//#region ../system/dist/file-data-plane-BhKdxJgf.mjs
|
|
73477
|
-
function isNonEmptyFile(filePath) {
|
|
73478
|
-
return node_fs.existsSync(filePath) && node_fs.statSync(filePath).size > 0;
|
|
73479
|
-
}
|
|
73480
|
-
/**
|
|
73481
|
-
* Sibling files of a single-file (non-directory) format — extra files the
|
|
73482
|
-
* format needs, fetched from the same remote directory as `url` and stored
|
|
73483
|
-
* flat alongside the main file in `modelsDir`. Catalog-declared via
|
|
73484
|
-
* `formatEntry.files`, e.g. OpenVINO IR lists its `.bin` weights next to the
|
|
73485
|
-
* `.xml`. The downloader stays format-agnostic; the convention lives in the
|
|
73486
|
-
* catalog data (like `MLPACKAGE_FILES` for the directory case).
|
|
73487
|
-
*/
|
|
73488
|
-
function siblingFilesFor(formatEntry) {
|
|
73489
|
-
return formatEntry.isDirectory ? [] : formatEntry.files ?? [];
|
|
73490
|
-
}
|
|
73491
|
-
/** Build fetch headers, including HF auth token for huggingface.co URLs */
|
|
73492
|
-
function buildHeaders(url) {
|
|
73493
|
-
const headers = { "User-Agent": "CamStack/1.0" };
|
|
73494
|
-
const hfToken = process.env["HF_TOKEN"] ?? process.env["HUGGING_FACE_HUB_TOKEN"];
|
|
73495
|
-
if (hfToken && url.includes("huggingface.co")) headers["Authorization"] = `Bearer ${hfToken}`;
|
|
73496
|
-
return headers;
|
|
73497
|
-
}
|
|
73498
|
-
var DEFAULT_MAX_REDIRECTS = 5;
|
|
73499
|
-
function normalizeDownloadOptions(third) {
|
|
73500
|
-
if (typeof third === "function") return { onProgress: third };
|
|
73501
|
-
return third ?? {};
|
|
73502
|
-
}
|
|
73503
|
-
function isRedirectStatus(status) {
|
|
73504
|
-
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
73505
|
-
}
|
|
73506
|
-
function resolveRedirectUrl(current, location) {
|
|
73507
|
-
return new URL(location, current);
|
|
73508
|
-
}
|
|
73509
|
-
async function downloadFile(url, destPath, onProgressOrOptions) {
|
|
73510
|
-
if (node_fs.existsSync(destPath)) return destPath;
|
|
73511
|
-
const opts = normalizeDownloadOptions(onProgressOrOptions);
|
|
73512
|
-
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
73513
|
-
const maxRedirects = opts.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
73514
|
-
node_fs.mkdirSync(node_path$1.dirname(destPath), { recursive: true });
|
|
73515
|
-
const tmpPath = destPath + ".downloading";
|
|
73516
|
-
try {
|
|
73517
|
-
let current = url;
|
|
73518
|
-
const seen = /* @__PURE__ */ new Set();
|
|
73519
|
-
let response;
|
|
73520
|
-
const manual = opts.redirectPolicy !== void 0;
|
|
73521
|
-
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
73522
|
-
const parsed = new URL(current);
|
|
73523
|
-
if (opts.redirectPolicy) opts.redirectPolicy(parsed, hop);
|
|
73524
|
-
if (seen.has(parsed.href)) throw new Error(`Redirect loop detected at ${parsed.href}`);
|
|
73525
|
-
seen.add(parsed.href);
|
|
73526
|
-
const controller = opts.timeoutMs !== void 0 ? new AbortController() : void 0;
|
|
73527
|
-
const timer = controller && opts.timeoutMs !== void 0 ? setTimeout(() => controller.abort(), opts.timeoutMs) : void 0;
|
|
73528
|
-
try {
|
|
73529
|
-
response = await fetchImpl(current, {
|
|
73530
|
-
redirect: manual ? "manual" : "follow",
|
|
73531
|
-
headers: buildHeaders(current),
|
|
73532
|
-
...controller ? { signal: controller.signal } : {}
|
|
73533
|
-
});
|
|
73534
|
-
} finally {
|
|
73535
|
-
if (timer) clearTimeout(timer);
|
|
73536
|
-
}
|
|
73537
|
-
if (manual && isRedirectStatus(response.status)) {
|
|
73538
|
-
const location = response.headers.get("location");
|
|
73539
|
-
if (!location) throw new Error(`Redirect ${response.status} missing Location header`);
|
|
73540
|
-
if (hop >= maxRedirects) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
|
|
73541
|
-
current = resolveRedirectUrl(current, location).href;
|
|
73542
|
-
continue;
|
|
73543
|
-
}
|
|
73544
|
-
break;
|
|
73545
|
-
}
|
|
73546
|
-
if (!response) throw new Error(`No response downloading ${url}`);
|
|
73547
|
-
if (manual && isRedirectStatus(response.status)) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
|
|
73548
|
-
if (!response.ok) throw new Error(`HTTP ${response.status} downloading ${url}`);
|
|
73549
|
-
if (!response.body) throw new Error(`No response body from ${url}`);
|
|
73550
|
-
const total = parseInt(response.headers.get("content-length") ?? "0", 10);
|
|
73551
|
-
let downloaded = 0;
|
|
73552
|
-
const fileStream = node_fs.createWriteStream(tmpPath);
|
|
73553
|
-
const reader = response.body.getReader();
|
|
73554
|
-
try {
|
|
73555
|
-
for (;;) {
|
|
73556
|
-
const { done, value } = await reader.read();
|
|
73557
|
-
if (done || !value) break;
|
|
73558
|
-
downloaded += value.length;
|
|
73559
|
-
if (opts.maxBytes !== void 0 && downloaded > opts.maxBytes) throw new Error(`Downloaded ${downloaded} bytes exceeds the ${opts.maxBytes}-byte limit`);
|
|
73560
|
-
fileStream.write(value);
|
|
73561
|
-
opts.onProgress?.(downloaded, total);
|
|
73562
|
-
}
|
|
73563
|
-
} finally {
|
|
73564
|
-
fileStream.end();
|
|
73565
|
-
await new Promise((resolve, reject) => {
|
|
73566
|
-
fileStream.on("finish", resolve);
|
|
73567
|
-
fileStream.on("error", reject);
|
|
73568
|
-
});
|
|
73569
|
-
}
|
|
73570
|
-
node_fs.renameSync(tmpPath, destPath);
|
|
73571
|
-
return destPath;
|
|
73572
|
-
} catch (err) {
|
|
73573
|
-
try {
|
|
73574
|
-
node_fs.unlinkSync(tmpPath);
|
|
73575
|
-
} catch {}
|
|
73576
|
-
throw err;
|
|
73577
|
-
}
|
|
73578
|
-
}
|
|
73579
|
-
/** Compute the on-disk path for a given model + format, even when not yet downloaded. */
|
|
73580
|
-
function getModelFilePath(modelsDir, entry, format) {
|
|
73581
|
-
const formatEntry = entry.formats[format];
|
|
73582
|
-
if (!formatEntry) return null;
|
|
73583
|
-
const filename = formatEntry.url.split("/").pop() ?? `${entry.id}.${format}`;
|
|
73584
|
-
return node_path$1.join(modelsDir, filename);
|
|
73585
|
-
}
|
|
73586
|
-
/** True iff the model file (or `Manifest.json` for directory bundles) exists and is non-empty. */
|
|
73587
|
-
function isModelDownloaded(modelsDir, entry, format) {
|
|
73588
|
-
const formatEntry = entry.formats[format];
|
|
73589
|
-
if (!formatEntry) return false;
|
|
73590
|
-
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
73591
|
-
if (!modelPath || !node_fs.existsSync(modelPath)) return false;
|
|
73592
|
-
if (formatEntry.isDirectory) return node_fs.existsSync(node_path$1.join(modelPath, "Manifest.json"));
|
|
73593
|
-
if (node_fs.statSync(modelPath).size <= 0) return false;
|
|
73594
|
-
return siblingFilesFor(formatEntry).every((f) => isNonEmptyFile(node_path$1.join(modelsDir, f)));
|
|
73595
|
-
}
|
|
73596
|
-
/** Remove the on-disk model file/directory. Returns true if something was deleted. */
|
|
73597
|
-
function deleteModelFromDisk(modelsDir, entry, format) {
|
|
73598
|
-
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
73599
|
-
if (!modelPath || !node_fs.existsSync(modelPath)) return false;
|
|
73600
|
-
const formatEntry = entry.formats[format];
|
|
73601
|
-
if (formatEntry?.isDirectory) node_fs.rmSync(modelPath, {
|
|
73602
|
-
recursive: true,
|
|
73603
|
-
force: true
|
|
73604
|
-
});
|
|
73605
|
-
else {
|
|
73606
|
-
node_fs.unlinkSync(modelPath);
|
|
73607
|
-
if (formatEntry) for (const sibling of siblingFilesFor(formatEntry)) {
|
|
73608
|
-
const sibPath = node_path$1.join(modelsDir, sibling);
|
|
73609
|
-
if (node_fs.existsSync(sibPath)) node_fs.unlinkSync(sibPath);
|
|
73610
|
-
}
|
|
73611
|
-
}
|
|
73612
|
-
return true;
|
|
73613
|
-
}
|
|
73614
|
-
(0, node_util.promisify)(node_zlib.brotliCompress);
|
|
73615
|
-
(0, node_util.promisify)(node_zlib.gzip);
|
|
73616
|
-
//#endregion
|
|
73617
73600
|
//#region src/runtime/model-ops.ts
|
|
73618
73601
|
/**
|
|
73619
73602
|
* Default `RuntimeModelOps` — the ONLY place the reused object-detection model
|
|
@@ -73677,7 +73660,7 @@ function createDefaultModelOps(modelsDir) {
|
|
|
73677
73660
|
downloadedBytes: carried,
|
|
73678
73661
|
...totalBytes > 0 ? { totalBytes } : {}
|
|
73679
73662
|
});
|
|
73680
|
-
await downloadFile(file.url, file.destPath, (downloaded) => {
|
|
73663
|
+
await (0, _camstack_system_addon_utils.downloadFile)(file.url, file.destPath, (downloaded) => {
|
|
73681
73664
|
onProgress({
|
|
73682
73665
|
file: file.filename,
|
|
73683
73666
|
fileIndex: index + 1,
|
|
@@ -73688,18 +73671,18 @@ function createDefaultModelOps(modelsDir) {
|
|
|
73688
73671
|
});
|
|
73689
73672
|
carried += (0, node_fs.existsSync)(file.destPath) ? (0, node_fs.statSync)(file.destPath).size : file.expectedBytes;
|
|
73690
73673
|
}
|
|
73691
|
-
const main = getModelFilePath(modelsDir, entry, GGUF);
|
|
73674
|
+
const main = (0, _camstack_system_addon_utils.getModelFilePath)(modelsDir, entry, GGUF);
|
|
73692
73675
|
if (main === null) throw new Error(`no gguf path for model ${entry.id}`);
|
|
73693
73676
|
return main;
|
|
73694
73677
|
},
|
|
73695
|
-
isDownloaded: (entry) => isModelDownloaded(modelsDir, entry, GGUF),
|
|
73678
|
+
isDownloaded: (entry) => (0, _camstack_system_addon_utils.isModelDownloaded)(modelsDir, entry, GGUF),
|
|
73696
73679
|
pathFor: (entry) => {
|
|
73697
|
-
const p = getModelFilePath(modelsDir, entry, GGUF);
|
|
73680
|
+
const p = (0, _camstack_system_addon_utils.getModelFilePath)(modelsDir, entry, GGUF);
|
|
73698
73681
|
if (p === null) throw new Error(`no gguf path for model ${entry.id}`);
|
|
73699
73682
|
return p;
|
|
73700
73683
|
},
|
|
73701
73684
|
delete: async (entry) => {
|
|
73702
|
-
deleteModelFromDisk(modelsDir, entry, GGUF);
|
|
73685
|
+
(0, _camstack_system_addon_utils.deleteModelFromDisk)(modelsDir, entry, GGUF);
|
|
73703
73686
|
},
|
|
73704
73687
|
extraFilePath: (_entry, filename) => node_path.join(modelsDir, filename)
|
|
73705
73688
|
};
|
package/dist/addon.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import * as path
|
|
2
|
+
import * as path from "node:path";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { connect, createServer } from "node:net";
|
|
5
|
-
import * as fs from "node:fs";
|
|
6
5
|
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
7
|
-
import {
|
|
8
|
-
import { brotliCompress, gzip } from "node:zlib";
|
|
6
|
+
import { deleteModelFromDisk, downloadFile, getModelFilePath, isModelDownloaded } from "@camstack/system/addon-utils";
|
|
9
7
|
import * as fsp from "node:fs/promises";
|
|
10
8
|
import { spawn } from "node:child_process";
|
|
11
9
|
//#region \0rolldown/runtime.js
|
|
@@ -6105,6 +6103,40 @@ var BaseAddon = class {
|
|
|
6105
6103
|
deviceSettingsSchema() {
|
|
6106
6104
|
return null;
|
|
6107
6105
|
}
|
|
6106
|
+
/**
|
|
6107
|
+
* INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
|
|
6108
|
+
* ARE the configuration of its integration.
|
|
6109
|
+
*
|
|
6110
|
+
* Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
|
|
6111
|
+
* operator should find on the addon's integration page (System →
|
|
6112
|
+
* Integrations → <name>) rather than only in the cluster-wide list of every
|
|
6113
|
+
* addon. Empty (the default) means the addon has no integration-level
|
|
6114
|
+
* settings and no such surface is offered — this is opt-in, because whether
|
|
6115
|
+
* an addon's configuration IS its integration's configuration depends on the
|
|
6116
|
+
* nature of the integration.
|
|
6117
|
+
*
|
|
6118
|
+
* WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
|
|
6119
|
+
* the ONE global schema, in the ONE addon store, written by the ONE
|
|
6120
|
+
* `updateGlobalSettings` path. There is deliberately no
|
|
6121
|
+
* `updateIntegrationSettings`: a second write path is how a surface acquires
|
|
6122
|
+
* a second store key, and this repo has shipped that twice (`btmPath@hub`,
|
|
6123
|
+
* D266). Selecting sections cannot introduce a key that selecting cannot.
|
|
6124
|
+
*
|
|
6125
|
+
* WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
|
|
6126
|
+
* `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
|
|
6127
|
+
* removed with the reason recorded at
|
|
6128
|
+
* `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
|
|
6129
|
+
* determined by WHICH schema it lives in, not by a field-level marker."* A
|
|
6130
|
+
* marker sprinkled across sections also has to borrow a field that already
|
|
6131
|
+
* means something else; borrowing `section.tab` put the literal word
|
|
6132
|
+
* "integration" into an operator-facing tab bar, because `tab` means "how to
|
|
6133
|
+
* GROUP this visually" and cannot also mean "where this lives" (D269
|
|
6134
|
+
* supersedes D268). One declaration, in one place, next to the schema whose
|
|
6135
|
+
* ids it names.
|
|
6136
|
+
*/
|
|
6137
|
+
integrationSettingSections() {
|
|
6138
|
+
return [];
|
|
6139
|
+
}
|
|
6108
6140
|
async getGlobalSettings(overlay, cap, nodeId) {
|
|
6109
6141
|
const schema = this.globalSettingsSchema(cap);
|
|
6110
6142
|
if (!schema) return { sections: [] };
|
|
@@ -6115,6 +6147,55 @@ var BaseAddon = class {
|
|
|
6115
6147
|
} : projected);
|
|
6116
6148
|
}
|
|
6117
6149
|
/**
|
|
6150
|
+
* The integration-level view of this addon's settings: exactly the sections
|
|
6151
|
+
* named by {@link integrationSettingSections}, hydrated from the SAME store
|
|
6152
|
+
* `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
|
|
6153
|
+
*
|
|
6154
|
+
* Returns `null` when the addon declared nothing — an addon that opts out has
|
|
6155
|
+
* no integration settings surface at all, rather than an empty one that reads
|
|
6156
|
+
* as a failed load.
|
|
6157
|
+
*
|
|
6158
|
+
* Three properties hold BY CONSTRUCTION, which is why they are here in core
|
|
6159
|
+
* and not in whichever UI happens to render this:
|
|
6160
|
+
*
|
|
6161
|
+
* 1. **One key.** The payload is a SUBSET of the global schema, so a field
|
|
6162
|
+
* shown here is the same field, with the same bare key, that the addon's
|
|
6163
|
+
* own page shows. There is no integration-specific writer — callers save
|
|
6164
|
+
* through `updateGlobalSettings` — so a second store key is unreachable,
|
|
6165
|
+
* not merely discouraged.
|
|
6166
|
+
* 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
|
|
6167
|
+
* is `<key>@<nodeId>` and an integration is not a node; whichever node
|
|
6168
|
+
* such a field silently picked would be a wrong answer for the operator
|
|
6169
|
+
* who opened the page (D266).
|
|
6170
|
+
* 3. **No silent typo.** A declared id that names no section throws. The
|
|
6171
|
+
* alternative — skip it — turns a rename into a surface that quietly
|
|
6172
|
+
* empties, which looks exactly like an addon with nothing to configure.
|
|
6173
|
+
*/
|
|
6174
|
+
async getIntegrationSettings(nodeId) {
|
|
6175
|
+
const declared = this.integrationSettingSections();
|
|
6176
|
+
if (declared.length === 0) return null;
|
|
6177
|
+
const schema = this.globalSettingsSchema();
|
|
6178
|
+
if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
|
|
6179
|
+
const byId = new Map(schema.sections.map((section) => [section.id, section]));
|
|
6180
|
+
const sections = [];
|
|
6181
|
+
for (const id of declared) {
|
|
6182
|
+
const section = byId.get(id);
|
|
6183
|
+
if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
|
|
6184
|
+
const fields = dropPerNodeFields(section.fields);
|
|
6185
|
+
if (fields.length === 0) continue;
|
|
6186
|
+
sections.push({
|
|
6187
|
+
...section,
|
|
6188
|
+
fields
|
|
6189
|
+
});
|
|
6190
|
+
}
|
|
6191
|
+
if (sections.length === 0) return null;
|
|
6192
|
+
const projected = await this.resolveGlobalStore(nodeId);
|
|
6193
|
+
return hydrateSchema({
|
|
6194
|
+
...schema,
|
|
6195
|
+
sections
|
|
6196
|
+
}, projected);
|
|
6197
|
+
}
|
|
6198
|
+
/**
|
|
6118
6199
|
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
6119
6200
|
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
6120
6201
|
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
@@ -6418,6 +6499,41 @@ var BaseAddon = class {
|
|
|
6418
6499
|
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6419
6500
|
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6420
6501
|
*/
|
|
6502
|
+
/**
|
|
6503
|
+
* The same fields with every `perNode: true` one removed, recursing into layout
|
|
6504
|
+
* containers exactly as {@link collectPerNodeFieldKeys} does. A container left
|
|
6505
|
+
* with no child is dropped rather than rendered empty.
|
|
6506
|
+
*
|
|
6507
|
+
* Used by `getIntegrationSettings`: an integration is not a node, so a field
|
|
6508
|
+
* whose store key is `<key>@<nodeId>` has no node to belong to there.
|
|
6509
|
+
*/
|
|
6510
|
+
function dropPerNodeFields(fields) {
|
|
6511
|
+
const kept = [];
|
|
6512
|
+
for (const field of fields) {
|
|
6513
|
+
if (field.type === "group") {
|
|
6514
|
+
const inner = dropPerNodeFields(field.fields);
|
|
6515
|
+
if (inner.length > 0) kept.push({
|
|
6516
|
+
...field,
|
|
6517
|
+
fields: inner
|
|
6518
|
+
});
|
|
6519
|
+
continue;
|
|
6520
|
+
}
|
|
6521
|
+
if (field.type === "sub-tabs") {
|
|
6522
|
+
const tabs = field.tabs.map((tab) => ({
|
|
6523
|
+
...tab,
|
|
6524
|
+
fields: dropPerNodeFields(tab.fields)
|
|
6525
|
+
})).filter((tab) => tab.fields.length > 0);
|
|
6526
|
+
if (tabs.length > 0) kept.push({
|
|
6527
|
+
...field,
|
|
6528
|
+
tabs
|
|
6529
|
+
});
|
|
6530
|
+
continue;
|
|
6531
|
+
}
|
|
6532
|
+
if ("perNode" in field && field.perNode === true) continue;
|
|
6533
|
+
kept.push(field);
|
|
6534
|
+
}
|
|
6535
|
+
return kept;
|
|
6536
|
+
}
|
|
6421
6537
|
function collectPerNodeFieldKeys(fields) {
|
|
6422
6538
|
const collected = [];
|
|
6423
6539
|
for (const field of fields) {
|
|
@@ -9630,6 +9746,9 @@ method(object({
|
|
|
9630
9746
|
kind: "mutation",
|
|
9631
9747
|
auth: "admin"
|
|
9632
9748
|
}), method(object({
|
|
9749
|
+
addonId: string(),
|
|
9750
|
+
nodeId: string().optional()
|
|
9751
|
+
}), SettingsSchemaWithValuesSchema.nullable()), method(object({
|
|
9633
9752
|
addonId: string(),
|
|
9634
9753
|
deviceId: number$1(),
|
|
9635
9754
|
nodeId: string().optional()
|
|
@@ -28118,6 +28237,12 @@ Object.freeze({
|
|
|
28118
28237
|
addonId: null,
|
|
28119
28238
|
access: "view"
|
|
28120
28239
|
},
|
|
28240
|
+
"addonSettings.getIntegrationSettings": {
|
|
28241
|
+
capName: "addon-settings",
|
|
28242
|
+
capScope: "system",
|
|
28243
|
+
addonId: null,
|
|
28244
|
+
access: "view"
|
|
28245
|
+
},
|
|
28121
28246
|
"addonSettings.updateDeviceSettings": {
|
|
28122
28247
|
capName: "addon-settings",
|
|
28123
28248
|
capScope: "system",
|
|
@@ -61251,7 +61376,7 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61251
61376
|
writeAuthConfig: () => writeAuthConfig
|
|
61252
61377
|
});
|
|
61253
61378
|
module.exports = __toCommonJS(auth_config_exports);
|
|
61254
|
-
var fs$
|
|
61379
|
+
var fs$1 = __toESM(__require("fs"));
|
|
61255
61380
|
var path$2 = __toESM(__require("path"));
|
|
61256
61381
|
var import_token_util = require_token_util();
|
|
61257
61382
|
function getAuthConfigPath() {
|
|
@@ -61262,8 +61387,8 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61262
61387
|
function readAuthConfig() {
|
|
61263
61388
|
try {
|
|
61264
61389
|
const authPath = getAuthConfigPath();
|
|
61265
|
-
if (!fs$
|
|
61266
|
-
const content = fs$
|
|
61390
|
+
if (!fs$1.existsSync(authPath)) return null;
|
|
61391
|
+
const content = fs$1.readFileSync(authPath, "utf8");
|
|
61267
61392
|
if (!content) return null;
|
|
61268
61393
|
return JSON.parse(content);
|
|
61269
61394
|
} catch (error) {
|
|
@@ -61273,11 +61398,11 @@ var require_auth_config = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61273
61398
|
function writeAuthConfig(config) {
|
|
61274
61399
|
const authPath = getAuthConfigPath();
|
|
61275
61400
|
const authDir = path$2.dirname(authPath);
|
|
61276
|
-
if (!fs$
|
|
61401
|
+
if (!fs$1.existsSync(authDir)) fs$1.mkdirSync(authDir, {
|
|
61277
61402
|
mode: 504,
|
|
61278
61403
|
recursive: true
|
|
61279
61404
|
});
|
|
61280
|
-
fs$
|
|
61405
|
+
fs$1.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
|
|
61281
61406
|
}
|
|
61282
61407
|
function isValidAccessToken(authConfig, expirationBufferMs = 0) {
|
|
61283
61408
|
if (!authConfig.token) return false;
|
|
@@ -61410,8 +61535,8 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61410
61535
|
saveToken: () => saveToken
|
|
61411
61536
|
});
|
|
61412
61537
|
module.exports = __toCommonJS(token_util_exports);
|
|
61413
|
-
var path = __toESM(__require("path"));
|
|
61414
|
-
var fs
|
|
61538
|
+
var path$1 = __toESM(__require("path"));
|
|
61539
|
+
var fs = __toESM(__require("fs"));
|
|
61415
61540
|
var import_token_error = require_token_error();
|
|
61416
61541
|
var import_token_io = require_token_io();
|
|
61417
61542
|
var import_auth_config = require_auth_config();
|
|
@@ -61421,7 +61546,7 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61421
61546
|
const vercelFolder = "com.vercel.cli";
|
|
61422
61547
|
const dataDir = (0, import_token_io.getUserDataDir)();
|
|
61423
61548
|
if (!dataDir) return null;
|
|
61424
|
-
return path.join(dataDir, vercelFolder);
|
|
61549
|
+
return path$1.join(dataDir, vercelFolder);
|
|
61425
61550
|
}
|
|
61426
61551
|
async function getVercelToken(options) {
|
|
61427
61552
|
const authConfig = (0, import_auth_config.readAuthConfig)();
|
|
@@ -61469,9 +61594,9 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61469
61594
|
function findProjectInfo() {
|
|
61470
61595
|
const dir = (0, import_token_io.findRootDir)();
|
|
61471
61596
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
|
|
61472
|
-
const prjPath = path.join(dir, ".vercel", "project.json");
|
|
61473
|
-
if (!fs
|
|
61474
|
-
const prj = JSON.parse(fs
|
|
61597
|
+
const prjPath = path$1.join(dir, ".vercel", "project.json");
|
|
61598
|
+
if (!fs.existsSync(prjPath)) throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
|
|
61599
|
+
const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
|
|
61475
61600
|
if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
|
|
61476
61601
|
return {
|
|
61477
61602
|
projectId: prj.projectId,
|
|
@@ -61481,21 +61606,21 @@ var require_token_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61481
61606
|
function saveToken(token, projectId) {
|
|
61482
61607
|
const dir = (0, import_token_io.getUserDataDir)();
|
|
61483
61608
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
61484
|
-
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61609
|
+
const tokenPath = path$1.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61485
61610
|
const tokenJson = JSON.stringify(token);
|
|
61486
|
-
fs
|
|
61611
|
+
fs.mkdirSync(path$1.dirname(tokenPath), {
|
|
61487
61612
|
mode: 504,
|
|
61488
61613
|
recursive: true
|
|
61489
61614
|
});
|
|
61490
|
-
fs
|
|
61491
|
-
fs
|
|
61615
|
+
fs.writeFileSync(tokenPath, tokenJson);
|
|
61616
|
+
fs.chmodSync(tokenPath, 432);
|
|
61492
61617
|
}
|
|
61493
61618
|
function loadToken(projectId) {
|
|
61494
61619
|
const dir = (0, import_token_io.getUserDataDir)();
|
|
61495
61620
|
if (!dir) throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
|
|
61496
|
-
const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61497
|
-
if (!fs
|
|
61498
|
-
const token = JSON.parse(fs
|
|
61621
|
+
const tokenPath = path$1.join(dir, "com.vercel.token", `${projectId}.json`);
|
|
61622
|
+
if (!fs.existsSync(tokenPath)) return null;
|
|
61623
|
+
const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
|
|
61499
61624
|
assertVercelOidcTokenResponse(token);
|
|
61500
61625
|
return token;
|
|
61501
61626
|
}
|
|
@@ -73499,147 +73624,6 @@ function entryForRef(ref) {
|
|
|
73499
73624
|
};
|
|
73500
73625
|
}
|
|
73501
73626
|
//#endregion
|
|
73502
|
-
//#region ../system/dist/file-data-plane-BhKdxJgf.mjs
|
|
73503
|
-
function isNonEmptyFile(filePath) {
|
|
73504
|
-
return fs.existsSync(filePath) && fs.statSync(filePath).size > 0;
|
|
73505
|
-
}
|
|
73506
|
-
/**
|
|
73507
|
-
* Sibling files of a single-file (non-directory) format — extra files the
|
|
73508
|
-
* format needs, fetched from the same remote directory as `url` and stored
|
|
73509
|
-
* flat alongside the main file in `modelsDir`. Catalog-declared via
|
|
73510
|
-
* `formatEntry.files`, e.g. OpenVINO IR lists its `.bin` weights next to the
|
|
73511
|
-
* `.xml`. The downloader stays format-agnostic; the convention lives in the
|
|
73512
|
-
* catalog data (like `MLPACKAGE_FILES` for the directory case).
|
|
73513
|
-
*/
|
|
73514
|
-
function siblingFilesFor(formatEntry) {
|
|
73515
|
-
return formatEntry.isDirectory ? [] : formatEntry.files ?? [];
|
|
73516
|
-
}
|
|
73517
|
-
/** Build fetch headers, including HF auth token for huggingface.co URLs */
|
|
73518
|
-
function buildHeaders(url) {
|
|
73519
|
-
const headers = { "User-Agent": "CamStack/1.0" };
|
|
73520
|
-
const hfToken = process.env["HF_TOKEN"] ?? process.env["HUGGING_FACE_HUB_TOKEN"];
|
|
73521
|
-
if (hfToken && url.includes("huggingface.co")) headers["Authorization"] = `Bearer ${hfToken}`;
|
|
73522
|
-
return headers;
|
|
73523
|
-
}
|
|
73524
|
-
var DEFAULT_MAX_REDIRECTS = 5;
|
|
73525
|
-
function normalizeDownloadOptions(third) {
|
|
73526
|
-
if (typeof third === "function") return { onProgress: third };
|
|
73527
|
-
return third ?? {};
|
|
73528
|
-
}
|
|
73529
|
-
function isRedirectStatus(status) {
|
|
73530
|
-
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
73531
|
-
}
|
|
73532
|
-
function resolveRedirectUrl(current, location) {
|
|
73533
|
-
return new URL(location, current);
|
|
73534
|
-
}
|
|
73535
|
-
async function downloadFile(url, destPath, onProgressOrOptions) {
|
|
73536
|
-
if (fs.existsSync(destPath)) return destPath;
|
|
73537
|
-
const opts = normalizeDownloadOptions(onProgressOrOptions);
|
|
73538
|
-
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
73539
|
-
const maxRedirects = opts.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
|
|
73540
|
-
fs.mkdirSync(path$1.dirname(destPath), { recursive: true });
|
|
73541
|
-
const tmpPath = destPath + ".downloading";
|
|
73542
|
-
try {
|
|
73543
|
-
let current = url;
|
|
73544
|
-
const seen = /* @__PURE__ */ new Set();
|
|
73545
|
-
let response;
|
|
73546
|
-
const manual = opts.redirectPolicy !== void 0;
|
|
73547
|
-
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
73548
|
-
const parsed = new URL(current);
|
|
73549
|
-
if (opts.redirectPolicy) opts.redirectPolicy(parsed, hop);
|
|
73550
|
-
if (seen.has(parsed.href)) throw new Error(`Redirect loop detected at ${parsed.href}`);
|
|
73551
|
-
seen.add(parsed.href);
|
|
73552
|
-
const controller = opts.timeoutMs !== void 0 ? new AbortController() : void 0;
|
|
73553
|
-
const timer = controller && opts.timeoutMs !== void 0 ? setTimeout(() => controller.abort(), opts.timeoutMs) : void 0;
|
|
73554
|
-
try {
|
|
73555
|
-
response = await fetchImpl(current, {
|
|
73556
|
-
redirect: manual ? "manual" : "follow",
|
|
73557
|
-
headers: buildHeaders(current),
|
|
73558
|
-
...controller ? { signal: controller.signal } : {}
|
|
73559
|
-
});
|
|
73560
|
-
} finally {
|
|
73561
|
-
if (timer) clearTimeout(timer);
|
|
73562
|
-
}
|
|
73563
|
-
if (manual && isRedirectStatus(response.status)) {
|
|
73564
|
-
const location = response.headers.get("location");
|
|
73565
|
-
if (!location) throw new Error(`Redirect ${response.status} missing Location header`);
|
|
73566
|
-
if (hop >= maxRedirects) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
|
|
73567
|
-
current = resolveRedirectUrl(current, location).href;
|
|
73568
|
-
continue;
|
|
73569
|
-
}
|
|
73570
|
-
break;
|
|
73571
|
-
}
|
|
73572
|
-
if (!response) throw new Error(`No response downloading ${url}`);
|
|
73573
|
-
if (manual && isRedirectStatus(response.status)) throw new Error(`Too many redirects (max ${maxRedirects}) downloading ${url}`);
|
|
73574
|
-
if (!response.ok) throw new Error(`HTTP ${response.status} downloading ${url}`);
|
|
73575
|
-
if (!response.body) throw new Error(`No response body from ${url}`);
|
|
73576
|
-
const total = parseInt(response.headers.get("content-length") ?? "0", 10);
|
|
73577
|
-
let downloaded = 0;
|
|
73578
|
-
const fileStream = fs.createWriteStream(tmpPath);
|
|
73579
|
-
const reader = response.body.getReader();
|
|
73580
|
-
try {
|
|
73581
|
-
for (;;) {
|
|
73582
|
-
const { done, value } = await reader.read();
|
|
73583
|
-
if (done || !value) break;
|
|
73584
|
-
downloaded += value.length;
|
|
73585
|
-
if (opts.maxBytes !== void 0 && downloaded > opts.maxBytes) throw new Error(`Downloaded ${downloaded} bytes exceeds the ${opts.maxBytes}-byte limit`);
|
|
73586
|
-
fileStream.write(value);
|
|
73587
|
-
opts.onProgress?.(downloaded, total);
|
|
73588
|
-
}
|
|
73589
|
-
} finally {
|
|
73590
|
-
fileStream.end();
|
|
73591
|
-
await new Promise((resolve, reject) => {
|
|
73592
|
-
fileStream.on("finish", resolve);
|
|
73593
|
-
fileStream.on("error", reject);
|
|
73594
|
-
});
|
|
73595
|
-
}
|
|
73596
|
-
fs.renameSync(tmpPath, destPath);
|
|
73597
|
-
return destPath;
|
|
73598
|
-
} catch (err) {
|
|
73599
|
-
try {
|
|
73600
|
-
fs.unlinkSync(tmpPath);
|
|
73601
|
-
} catch {}
|
|
73602
|
-
throw err;
|
|
73603
|
-
}
|
|
73604
|
-
}
|
|
73605
|
-
/** Compute the on-disk path for a given model + format, even when not yet downloaded. */
|
|
73606
|
-
function getModelFilePath(modelsDir, entry, format) {
|
|
73607
|
-
const formatEntry = entry.formats[format];
|
|
73608
|
-
if (!formatEntry) return null;
|
|
73609
|
-
const filename = formatEntry.url.split("/").pop() ?? `${entry.id}.${format}`;
|
|
73610
|
-
return path$1.join(modelsDir, filename);
|
|
73611
|
-
}
|
|
73612
|
-
/** True iff the model file (or `Manifest.json` for directory bundles) exists and is non-empty. */
|
|
73613
|
-
function isModelDownloaded(modelsDir, entry, format) {
|
|
73614
|
-
const formatEntry = entry.formats[format];
|
|
73615
|
-
if (!formatEntry) return false;
|
|
73616
|
-
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
73617
|
-
if (!modelPath || !fs.existsSync(modelPath)) return false;
|
|
73618
|
-
if (formatEntry.isDirectory) return fs.existsSync(path$1.join(modelPath, "Manifest.json"));
|
|
73619
|
-
if (fs.statSync(modelPath).size <= 0) return false;
|
|
73620
|
-
return siblingFilesFor(formatEntry).every((f) => isNonEmptyFile(path$1.join(modelsDir, f)));
|
|
73621
|
-
}
|
|
73622
|
-
/** Remove the on-disk model file/directory. Returns true if something was deleted. */
|
|
73623
|
-
function deleteModelFromDisk(modelsDir, entry, format) {
|
|
73624
|
-
const modelPath = getModelFilePath(modelsDir, entry, format);
|
|
73625
|
-
if (!modelPath || !fs.existsSync(modelPath)) return false;
|
|
73626
|
-
const formatEntry = entry.formats[format];
|
|
73627
|
-
if (formatEntry?.isDirectory) fs.rmSync(modelPath, {
|
|
73628
|
-
recursive: true,
|
|
73629
|
-
force: true
|
|
73630
|
-
});
|
|
73631
|
-
else {
|
|
73632
|
-
fs.unlinkSync(modelPath);
|
|
73633
|
-
if (formatEntry) for (const sibling of siblingFilesFor(formatEntry)) {
|
|
73634
|
-
const sibPath = path$1.join(modelsDir, sibling);
|
|
73635
|
-
if (fs.existsSync(sibPath)) fs.unlinkSync(sibPath);
|
|
73636
|
-
}
|
|
73637
|
-
}
|
|
73638
|
-
return true;
|
|
73639
|
-
}
|
|
73640
|
-
promisify(brotliCompress);
|
|
73641
|
-
promisify(gzip);
|
|
73642
|
-
//#endregion
|
|
73643
73627
|
//#region src/runtime/model-ops.ts
|
|
73644
73628
|
/**
|
|
73645
73629
|
* Default `RuntimeModelOps` — the ONLY place the reused object-detection model
|
|
@@ -73675,14 +73659,14 @@ function planFiles(modelsDir, entry) {
|
|
|
73675
73659
|
const filename = formatEntry.url.split("/").pop() ?? `${entry.id}.${GGUF}`;
|
|
73676
73660
|
out.push({
|
|
73677
73661
|
url: formatEntry.url,
|
|
73678
|
-
destPath: path
|
|
73662
|
+
destPath: path.join(modelsDir, filename),
|
|
73679
73663
|
filename,
|
|
73680
73664
|
expectedBytes: formatEntry.sizeMB * BYTES_PER_MB
|
|
73681
73665
|
});
|
|
73682
73666
|
}
|
|
73683
73667
|
for (const extra of entry.extraFiles ?? []) out.push({
|
|
73684
73668
|
url: extra.url,
|
|
73685
|
-
destPath: path
|
|
73669
|
+
destPath: path.join(modelsDir, extra.filename),
|
|
73686
73670
|
filename: extra.filename,
|
|
73687
73671
|
expectedBytes: extra.sizeMB * BYTES_PER_MB
|
|
73688
73672
|
});
|
|
@@ -73727,7 +73711,7 @@ function createDefaultModelOps(modelsDir) {
|
|
|
73727
73711
|
delete: async (entry) => {
|
|
73728
73712
|
deleteModelFromDisk(modelsDir, entry, GGUF);
|
|
73729
73713
|
},
|
|
73730
|
-
extraFilePath: (_entry, filename) => path
|
|
73714
|
+
extraFilePath: (_entry, filename) => path.join(modelsDir, filename)
|
|
73731
73715
|
};
|
|
73732
73716
|
}
|
|
73733
73717
|
//#endregion
|
|
@@ -74437,7 +74421,7 @@ function createLlmRuntimeProvider(deps) {
|
|
|
74437
74421
|
deleteModel: async ({ file }) => {
|
|
74438
74422
|
const loaded = deps.supervisor.status().modelPath;
|
|
74439
74423
|
if (loaded !== void 0 && basename(loaded) === file) throw new Error(`cannot delete ${file}: loaded by the running runtime`);
|
|
74440
|
-
await fsp.rm(path
|
|
74424
|
+
await fsp.rm(path.join(deps.modelsDir, file), { force: true });
|
|
74441
74425
|
},
|
|
74442
74426
|
listLocalModels: async () => {
|
|
74443
74427
|
return (await listGgufFiles(deps.modelsDir)).map((f) => {
|
|
@@ -74445,7 +74429,7 @@ function createLlmRuntimeProvider(deps) {
|
|
|
74445
74429
|
return {
|
|
74446
74430
|
file: f.file,
|
|
74447
74431
|
sizeBytes: f.sizeBytes,
|
|
74448
|
-
path: path
|
|
74432
|
+
path: path.join(deps.modelsDir, f.file),
|
|
74449
74433
|
...catalogId !== void 0 ? { catalogId } : {}
|
|
74450
74434
|
};
|
|
74451
74435
|
});
|
|
@@ -74470,7 +74454,7 @@ async function listGgufFiles(dir) {
|
|
|
74470
74454
|
for (const name of names) {
|
|
74471
74455
|
if (!name.endsWith(".gguf")) continue;
|
|
74472
74456
|
try {
|
|
74473
|
-
const stat = await fsp.stat(path
|
|
74457
|
+
const stat = await fsp.stat(path.join(dir, name));
|
|
74474
74458
|
out.push({
|
|
74475
74459
|
file: name,
|
|
74476
74460
|
sizeBytes: stat.size
|
|
@@ -75804,7 +75788,7 @@ var AiAddon = class extends BaseAddon {
|
|
|
75804
75788
|
this.supervisor = supervisor;
|
|
75805
75789
|
const settingsPort = api !== void 0 ? createApiSettingsStorePort(api) : createMemorySettingsStorePort();
|
|
75806
75790
|
if (api === void 0) logger.warn("addon-ai: no ctx.api — profiles are in-memory only");
|
|
75807
|
-
const binDir = path
|
|
75791
|
+
const binDir = path.join(ctx.nodeDataDir, "bin");
|
|
75808
75792
|
const { ensureLlamaServer } = await import("./ensure-llama-server-D_uzfSep.mjs").then((n) => n.r);
|
|
75809
75793
|
const assembly = await assembleAi({
|
|
75810
75794
|
nodeId: ownNodeId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/addon-ai",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.31",
|
|
4
4
|
"description": "AI addon for CamStack — the `llm` collection provider (cloud, LAN, and camstack-managed local llama.cpp profiles) plus the per-node `llm-runtime` managed executor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"camstack",
|