@ariacompute/engine-ts 1.19.1 → 1.20.0
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/index.d.ts +6 -1
- package/dist/index.js +31 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -43,8 +43,13 @@ export declare const INTL_UPGRADE = "https://github.com/ariacompute";
|
|
|
43
43
|
export declare const CN_SITE = "https://ariacompute.cn";
|
|
44
44
|
export declare const CN_UPGRADE = "https://gitee.com/ariacompute";
|
|
45
45
|
export interface SetupConfig {
|
|
46
|
+
/** Local (router registration) */
|
|
46
47
|
router: string;
|
|
47
48
|
router_api_key: string;
|
|
49
|
+
/** OAuth (Aria Compute) */
|
|
50
|
+
serve_site: string;
|
|
51
|
+
serve_api_key: string;
|
|
52
|
+
/** Hub / compute */
|
|
48
53
|
site_url: string;
|
|
49
54
|
upgrade_url: string;
|
|
50
55
|
compute: string;
|
|
@@ -74,7 +79,7 @@ export declare function cachedFfiPath(platform?: string): string | undefined;
|
|
|
74
79
|
export declare function ffiAssetOs(platform?: string, arch?: string): string;
|
|
75
80
|
export declare function selectLatestStable(releases: Array<Record<string, unknown>>): string;
|
|
76
81
|
export declare function extractFfiArchive(archive: string, destDir: string, want?: string): string;
|
|
77
|
-
/** Return a path to
|
|
82
|
+
/** Return a path to libaria-engine_ffi, downloading the latest stable Release if needed. */
|
|
78
83
|
export declare function ensureFfiLib(site?: string): Promise<string>;
|
|
79
84
|
export declare function isLocalRef(modelRef: string): boolean;
|
|
80
85
|
export declare class Engine {
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,8 @@ function defaultSetupConfig() {
|
|
|
67
67
|
return {
|
|
68
68
|
router: "",
|
|
69
69
|
router_api_key: "",
|
|
70
|
+
serve_site: "",
|
|
71
|
+
serve_api_key: "",
|
|
70
72
|
site_url: "",
|
|
71
73
|
upgrade_url: "",
|
|
72
74
|
compute: "auto",
|
|
@@ -97,6 +99,25 @@ function fillSetupUrls(cfg) {
|
|
|
97
99
|
out.upgrade_url = upgrade;
|
|
98
100
|
return out;
|
|
99
101
|
}
|
|
102
|
+
function validateRouterApiKey(key) {
|
|
103
|
+
const t = (key || "").trim();
|
|
104
|
+
if (!t)
|
|
105
|
+
return;
|
|
106
|
+
if (t.startsWith("bfvk-")) {
|
|
107
|
+
throw new Error("OAuth key detected (bfvk-); use serve_api_key / [2/2] OAuth (Aria Compute)");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function validateServeApiKey(key) {
|
|
111
|
+
const t = (key || "").trim();
|
|
112
|
+
if (!t)
|
|
113
|
+
return;
|
|
114
|
+
if (t.startsWith("sk-aria_")) {
|
|
115
|
+
throw new Error("Local router key detected (sk-aria_); use router_api_key / [1/2] Local");
|
|
116
|
+
}
|
|
117
|
+
if (!t.startsWith("bfvk-")) {
|
|
118
|
+
throw new Error("serve_api_key must start with bfvk-");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
100
121
|
function applySetup(existing, updates) {
|
|
101
122
|
const out = { ...existing };
|
|
102
123
|
for (const [k, v] of Object.entries(updates)) {
|
|
@@ -107,6 +128,8 @@ function applySetup(existing, updates) {
|
|
|
107
128
|
if (!["auto", "cpu", "cuda"].includes(out.compute)) {
|
|
108
129
|
throw new Error(`invalid compute: ${out.compute}`);
|
|
109
130
|
}
|
|
131
|
+
validateRouterApiKey(out.router_api_key);
|
|
132
|
+
validateServeApiKey(out.serve_api_key);
|
|
110
133
|
return fillSetupUrls(out);
|
|
111
134
|
}
|
|
112
135
|
const DEFAULT_SDK = "v1.0";
|
|
@@ -350,10 +373,10 @@ async function downloadModel(model, tokenOrOpts, site = DEFAULT_SITE) {
|
|
|
350
373
|
const SDK_UA = "aria-engine-sdk/0.1.0";
|
|
351
374
|
function ffiLibName(platform = process.platform) {
|
|
352
375
|
if (platform === "win32" || platform.toLowerCase().startsWith("win"))
|
|
353
|
-
return "
|
|
376
|
+
return "aria-engine_ffi.dll";
|
|
354
377
|
if (platform === "darwin")
|
|
355
|
-
return "
|
|
356
|
-
return "
|
|
378
|
+
return "libaria-engine_ffi.dylib";
|
|
379
|
+
return "libaria-engine_ffi.so";
|
|
357
380
|
}
|
|
358
381
|
function libDir() {
|
|
359
382
|
return path.join(ariaHome(), "lib");
|
|
@@ -378,7 +401,7 @@ function ffiAssetOs(platform = process.platform, arch = process.arch) {
|
|
|
378
401
|
if ((p === "win32" || p.startsWith("win")) && (a === "x64" || a === "x86_64" || a === "amd64")) {
|
|
379
402
|
return "windows_x86_64";
|
|
380
403
|
}
|
|
381
|
-
throw new Error(`unsupported platform ${platform}/${arch} for
|
|
404
|
+
throw new Error(`unsupported platform ${platform}/${arch} for libaria-engine_ffi`);
|
|
382
405
|
}
|
|
383
406
|
function stripV(tag) {
|
|
384
407
|
const t = tag.trim();
|
|
@@ -413,7 +436,7 @@ function selectLatestStable(releases) {
|
|
|
413
436
|
}
|
|
414
437
|
}
|
|
415
438
|
if (!bestTag)
|
|
416
|
-
throw new Error("no stable release found for
|
|
439
|
+
throw new Error("no stable release found for libaria-engine_ffi");
|
|
417
440
|
return stripV(bestTag);
|
|
418
441
|
}
|
|
419
442
|
function upgradeOrg(site) {
|
|
@@ -491,7 +514,7 @@ function installFfiFromReleases(raw, archiveBytes) {
|
|
|
491
514
|
if (!Array.isArray(releases))
|
|
492
515
|
throw new Error("unexpected releases payload");
|
|
493
516
|
const ver = selectLatestStable(releases);
|
|
494
|
-
const assetName = `
|
|
517
|
+
const assetName = `libaria-engine_ffi_${ver}_${ffiAssetOs()}.tar.gz`;
|
|
495
518
|
let url;
|
|
496
519
|
for (const rel of releases) {
|
|
497
520
|
const tag = String(rel.tag_name || rel.tag || "");
|
|
@@ -521,7 +544,7 @@ function installFfiFromReleases(raw, archiveBytes) {
|
|
|
521
544
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
522
545
|
}
|
|
523
546
|
}
|
|
524
|
-
/** Return a path to
|
|
547
|
+
/** Return a path to libaria-engine_ffi, downloading the latest stable Release if needed. */
|
|
525
548
|
async function ensureFfiLib(site) {
|
|
526
549
|
const env = process.env.ARIA_FFI_LIB;
|
|
527
550
|
if (env && fs.existsSync(env))
|
|
@@ -557,7 +580,7 @@ function loadLib(ffiLib, site) {
|
|
|
557
580
|
cachedFfiPath() ||
|
|
558
581
|
ensureFfiLibSync(site);
|
|
559
582
|
if (!libPath)
|
|
560
|
-
throw new Error("Cannot locate
|
|
583
|
+
throw new Error("Cannot locate libaria-engine_ffi");
|
|
561
584
|
const koffiNS = require("koffi");
|
|
562
585
|
return koffiNS.load(libPath);
|
|
563
586
|
}
|