@ariacompute/engine-rn 1.16.0 → 1.17.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/README.md +3 -3
- package/package.json +2 -2
- package/src/index.js +26 -23
- package/src/setup.js +60 -0
- package/test/setup.test.cjs +77 -0
- package/src/auth.js +0 -115
- package/test/auth.test.cjs +0 -106
package/README.md
CHANGED
|
@@ -20,13 +20,13 @@ ModelScope; `site` defaults to `https://ariacompute.com`) into
|
|
|
20
20
|
`~/.ariacompute/models/{model}` and then loads it. Dashboard is not used. A
|
|
21
21
|
Dashboard `sk-` / `bfvk-` token is ignored for hub auth. Token is optional for
|
|
22
22
|
public models. Gated files: pass `hfToken` / `modelscopeApiToken` (same as
|
|
23
|
-
`aria-engine
|
|
24
|
-
`
|
|
23
|
+
`aria-engine setup`); if omitted, reads `~/.ariacompute/engine.yml`. Instance
|
|
24
|
+
`setup` is in-memory only (does not write that file). A valid cached bundle is
|
|
25
25
|
reused without re-downloading.
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
28
|
const eng = await AriaEngine.open("gemma-4-e2b-it_q4");
|
|
29
29
|
const gated = new AriaEngine();
|
|
30
|
-
gated.
|
|
30
|
+
gated.setup({ hf_token: "hf_..." });
|
|
31
31
|
await gated.open("gemma-4-e2b-it_q4");
|
|
32
32
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ariacompute/engine-rn",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "React Native binding for Aria Engine",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,6 +8,6 @@
|
|
|
8
8
|
"react-native": ">=0.72.0"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "node --test test/
|
|
11
|
+
"test": "node --test test/setup.test.cjs"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/src/index.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { NativeModules } from 'react-native';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from './
|
|
12
|
+
defaultSetupConfig,
|
|
13
|
+
applySetup,
|
|
14
|
+
} from './setup.js';
|
|
15
15
|
|
|
16
16
|
const AriaEngineModule = NativeModules.AriaEngine;
|
|
17
17
|
|
|
@@ -91,19 +91,22 @@ function unquoteYaml(v) {
|
|
|
91
91
|
function configYmlScalar(key) {
|
|
92
92
|
const fs = require('fs');
|
|
93
93
|
const path = require('path');
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
94
|
+
const home = ariaHome();
|
|
95
|
+
for (const name of ['engine.yml', 'config.yml']) {
|
|
96
|
+
try {
|
|
97
|
+
const raw = fs.readFileSync(path.join(home, name), 'utf8');
|
|
98
|
+
for (const line of raw.split('\n')) {
|
|
99
|
+
if (line.startsWith(' ') || line.startsWith('\t')) continue;
|
|
100
|
+
const s = line.trim();
|
|
101
|
+
if (!s || s.startsWith('#') || !s.includes(':')) continue;
|
|
102
|
+
const idx = s.indexOf(':');
|
|
103
|
+
if (s.slice(0, idx).trim() !== key) continue;
|
|
104
|
+
const v = unquoteYaml(s.slice(idx + 1));
|
|
105
|
+
if (v) return v;
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
continue;
|
|
104
109
|
}
|
|
105
|
-
} catch {
|
|
106
|
-
return undefined;
|
|
107
110
|
}
|
|
108
111
|
return undefined;
|
|
109
112
|
}
|
|
@@ -213,7 +216,7 @@ async function fetchHubFile(source, model, file, dest, token, required) {
|
|
|
213
216
|
if (e && (e.status === 401 || e.status === 403)) {
|
|
214
217
|
const field = source === 'modelscope' ? 'modelscope_api_token' : 'hf_token';
|
|
215
218
|
throw new Error(
|
|
216
|
-
`auth failed HTTP ${e.status}; set ${field} via aria-engine
|
|
219
|
+
`auth failed HTTP ${e.status}; set ${field} via aria-engine setup (do not pass a Dashboard sk-/bfvk- key as the hub token)`,
|
|
217
220
|
);
|
|
218
221
|
}
|
|
219
222
|
}
|
|
@@ -425,22 +428,22 @@ async function ensureFfiLib(site) {
|
|
|
425
428
|
export class AriaEngine {
|
|
426
429
|
constructor(bundlePath) {
|
|
427
430
|
this.bundlePath = bundlePath;
|
|
428
|
-
this.cfg =
|
|
431
|
+
this.cfg = defaultSetupConfig();
|
|
429
432
|
this.opts = {};
|
|
430
433
|
// NativeModules.AriaEngine.init(bundlePath) when linked.
|
|
431
434
|
}
|
|
432
435
|
|
|
433
|
-
|
|
434
|
-
this.cfg =
|
|
436
|
+
setup(updates) {
|
|
437
|
+
this.cfg = applySetup(this.cfg, updates);
|
|
435
438
|
return this;
|
|
436
439
|
}
|
|
437
440
|
|
|
438
|
-
|
|
441
|
+
setupStatus() {
|
|
439
442
|
return { ...this.cfg };
|
|
440
443
|
}
|
|
441
444
|
|
|
442
|
-
|
|
443
|
-
this.cfg =
|
|
445
|
+
setupClear() {
|
|
446
|
+
this.cfg = defaultSetupConfig();
|
|
444
447
|
return this;
|
|
445
448
|
}
|
|
446
449
|
|
|
@@ -460,7 +463,7 @@ export class AriaEngine {
|
|
|
460
463
|
const eng = new AriaEngine();
|
|
461
464
|
eng.opts = opts;
|
|
462
465
|
if (opts.site || opts.hfToken || opts.modelscopeApiToken) {
|
|
463
|
-
eng.
|
|
466
|
+
eng.setup({
|
|
464
467
|
site_url: opts.site,
|
|
465
468
|
hf_token: opts.hfToken,
|
|
466
469
|
modelscope_api_token: opts.modelscopeApiToken,
|
package/src/setup.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Instance-level Engine setup (in-memory; does not write engine.yml). */
|
|
2
|
+
|
|
3
|
+
const INTL_SITE = 'https://ariacompute.com';
|
|
4
|
+
const INTL_UPGRADE = 'https://github.com/ariacompute';
|
|
5
|
+
const CN_SITE = 'https://ariacompute.cn';
|
|
6
|
+
const CN_UPGRADE = 'https://gitee.com/ariacompute';
|
|
7
|
+
|
|
8
|
+
function defaultSetupConfig() {
|
|
9
|
+
return {
|
|
10
|
+
router: '',
|
|
11
|
+
site_url: '',
|
|
12
|
+
upgrade_url: '',
|
|
13
|
+
compute: 'auto',
|
|
14
|
+
hf_token: '',
|
|
15
|
+
modelscope_api_token: '',
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function gatewayRegion(url) {
|
|
20
|
+
const lower = (url || '').toLowerCase();
|
|
21
|
+
if (lower.includes('ariacompute.cn') || lower.includes('gitee.com/ariacompute')) return 'cn';
|
|
22
|
+
if (lower.includes('ariacompute.com') || lower.includes('github.com/ariacompute')) return 'intl';
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function pairUrls(region) {
|
|
27
|
+
return region === 'cn' ? [CN_SITE, CN_UPGRADE] : [INTL_SITE, INTL_UPGRADE];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fillSetupUrls(cfg) {
|
|
31
|
+
const out = { ...cfg };
|
|
32
|
+
const region = gatewayRegion(out.site_url) || gatewayRegion(out.upgrade_url);
|
|
33
|
+
if (!region) return out;
|
|
34
|
+
const [site, upgrade] = pairUrls(region);
|
|
35
|
+
if (!out.site_url) out.site_url = site;
|
|
36
|
+
if (!out.upgrade_url) out.upgrade_url = upgrade;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function applySetup(existing, updates) {
|
|
41
|
+
const out = { ...existing };
|
|
42
|
+
for (const [k, v] of Object.entries(updates || {})) {
|
|
43
|
+
if (v === undefined) continue;
|
|
44
|
+
out[k] = v;
|
|
45
|
+
}
|
|
46
|
+
if (!['auto', 'cpu', 'cuda'].includes(out.compute)) {
|
|
47
|
+
throw new Error(`invalid compute: ${out.compute}`);
|
|
48
|
+
}
|
|
49
|
+
return fillSetupUrls(out);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
INTL_SITE,
|
|
54
|
+
INTL_UPGRADE,
|
|
55
|
+
CN_SITE,
|
|
56
|
+
CN_UPGRADE,
|
|
57
|
+
defaultSetupConfig,
|
|
58
|
+
fillSetupUrls,
|
|
59
|
+
applySetup,
|
|
60
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const {
|
|
7
|
+
applySetup,
|
|
8
|
+
defaultSetupConfig,
|
|
9
|
+
fillSetupUrls,
|
|
10
|
+
CN_SITE,
|
|
11
|
+
CN_UPGRADE,
|
|
12
|
+
} = require('../src/setup.js');
|
|
13
|
+
|
|
14
|
+
test('setup defaults', () => {
|
|
15
|
+
const cfg = defaultSetupConfig();
|
|
16
|
+
assert.equal(cfg.compute, 'auto');
|
|
17
|
+
assert.equal(cfg.router, '');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('setup invalid enum', () => {
|
|
21
|
+
assert.throws(() => applySetup(defaultSetupConfig(), { compute: 'gpu' }));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('setup fills urls from cn site', () => {
|
|
25
|
+
const got = fillSetupUrls({ site_url: CN_SITE, upgrade_url: '' });
|
|
26
|
+
assert.equal(got.upgrade_url, CN_UPGRADE);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('setup instance all fields via applySetup', () => {
|
|
30
|
+
const st = applySetup(defaultSetupConfig(), {
|
|
31
|
+
router: 'http://127.0.0.1:8080',
|
|
32
|
+
site_url: CN_SITE,
|
|
33
|
+
upgrade_url: CN_UPGRADE,
|
|
34
|
+
compute: 'cpu',
|
|
35
|
+
hf_token: 'hf_abc',
|
|
36
|
+
modelscope_api_token: 'ms_xyz',
|
|
37
|
+
});
|
|
38
|
+
assert.equal(st.router, 'http://127.0.0.1:8080');
|
|
39
|
+
assert.equal(st.hf_token, 'hf_abc');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('setup partial merge', () => {
|
|
43
|
+
const once = applySetup(defaultSetupConfig(), { hf_token: 'hf_one', router: 'http://127.0.0.1:1' });
|
|
44
|
+
const st = applySetup(once, { compute: 'cuda' });
|
|
45
|
+
assert.equal(st.hf_token, 'hf_one');
|
|
46
|
+
assert.equal(st.router, 'http://127.0.0.1:1');
|
|
47
|
+
assert.equal(st.compute, 'cuda');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('setup invalid enum leaves state', () => {
|
|
51
|
+
const once = applySetup(defaultSetupConfig(), { compute: 'cpu' });
|
|
52
|
+
assert.throws(() => applySetup(once, { compute: 'gpu' }));
|
|
53
|
+
assert.equal(once.compute, 'cpu');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('setup fills urls from site tld', () => {
|
|
57
|
+
const st = applySetup(defaultSetupConfig(), { site_url: 'https://ariacompute.cn' });
|
|
58
|
+
assert.equal(st.upgrade_url, CN_UPGRADE);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('setup does not write engine.yml', () => {
|
|
62
|
+
const prev = process.env.ARIA_COMPUTE_HOME;
|
|
63
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'aria-rn-setup-'));
|
|
64
|
+
process.env.ARIA_COMPUTE_HOME = home;
|
|
65
|
+
try {
|
|
66
|
+
applySetup(defaultSetupConfig(), {
|
|
67
|
+
router: 'http://127.0.0.1:8080',
|
|
68
|
+
site_url: 'https://ariacompute.com',
|
|
69
|
+
hf_token: 'hf_x',
|
|
70
|
+
});
|
|
71
|
+
assert.equal(fs.existsSync(path.join(home, 'engine.yml')), false);
|
|
72
|
+
assert.equal(fs.existsSync(path.join(home, 'config.yml')), false);
|
|
73
|
+
} finally {
|
|
74
|
+
if (prev === undefined) delete process.env.ARIA_COMPUTE_HOME;
|
|
75
|
+
else process.env.ARIA_COMPUTE_HOME = prev;
|
|
76
|
+
}
|
|
77
|
+
});
|
package/src/auth.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/** Instance-level Engine auth (in-memory; does not write config.yml). */
|
|
2
|
-
|
|
3
|
-
const INTL_CLOUD = 'https://gateway.ariacompute.com';
|
|
4
|
-
const INTL_SITE = 'https://ariacompute.com';
|
|
5
|
-
const INTL_UPGRADE = 'https://github.com/ariacompute';
|
|
6
|
-
const CN_CLOUD = 'https://gateway.ariacompute.cn';
|
|
7
|
-
const CN_SITE = 'https://ariacompute.cn';
|
|
8
|
-
const CN_UPGRADE = 'https://gitee.com/ariacompute';
|
|
9
|
-
|
|
10
|
-
function defaultAuthConfig() {
|
|
11
|
-
return {
|
|
12
|
-
cloud_api_key: '',
|
|
13
|
-
cloud_url: '',
|
|
14
|
-
site_url: '',
|
|
15
|
-
upgrade_url: '',
|
|
16
|
-
hybrid_mode: 'balance',
|
|
17
|
-
hybrid_execution: 'hybrid',
|
|
18
|
-
hybrid_semantic: true,
|
|
19
|
-
hybrid_semantic_timeout_ms: 800,
|
|
20
|
-
hybrid_semantic_cache_size: 512,
|
|
21
|
-
compute: 'auto',
|
|
22
|
-
hf_token: '',
|
|
23
|
-
modelscope_api_token: '',
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function gatewayRegion(url) {
|
|
28
|
-
const lower = (url || '').toLowerCase();
|
|
29
|
-
if (lower.includes('ariacompute.cn') || lower.includes('gitee.com/ariacompute')) return 'cn';
|
|
30
|
-
if (lower.includes('ariacompute.com') || lower.includes('github.com/ariacompute')) return 'intl';
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function pairUrls(region) {
|
|
35
|
-
return region === 'cn' ? [CN_CLOUD, CN_SITE, CN_UPGRADE] : [INTL_CLOUD, INTL_SITE, INTL_UPGRADE];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function fillAuthUrls(cfg) {
|
|
39
|
-
const out = { ...cfg };
|
|
40
|
-
const region =
|
|
41
|
-
gatewayRegion(out.site_url) || gatewayRegion(out.cloud_url) || gatewayRegion(out.upgrade_url);
|
|
42
|
-
if (!region) return out;
|
|
43
|
-
const [cloud, site, upgrade] = pairUrls(region);
|
|
44
|
-
if (!out.cloud_url) out.cloud_url = cloud;
|
|
45
|
-
if (!out.site_url) out.site_url = site;
|
|
46
|
-
if (!out.upgrade_url) out.upgrade_url = upgrade;
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function localePrefersCn() {
|
|
51
|
-
const lang = `${process.env.LANG || ''}${process.env.LC_ALL || ''}`.toLowerCase();
|
|
52
|
-
return lang.includes('zh') || lang.includes('.cn') || lang.startsWith('cn');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const authHooks = {
|
|
56
|
-
probeDashboard: () => false,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function detectGatewayPair(apiKey) {
|
|
60
|
-
const key = (apiKey || '').trim();
|
|
61
|
-
const first = localePrefersCn() ? 'cn' : 'intl';
|
|
62
|
-
const second = first === 'cn' ? 'intl' : 'cn';
|
|
63
|
-
for (const region of [first, second]) {
|
|
64
|
-
const [cloud, site, upgrade] = pairUrls(region);
|
|
65
|
-
if (key && authHooks.probeDashboard(site, key)) return [cloud, site, upgrade];
|
|
66
|
-
}
|
|
67
|
-
return pairUrls(first);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function applyAuth(existing, updates) {
|
|
71
|
-
const out = { ...existing };
|
|
72
|
-
for (const [k, v] of Object.entries(updates || {})) {
|
|
73
|
-
if (v === undefined) continue;
|
|
74
|
-
out[k] = v;
|
|
75
|
-
}
|
|
76
|
-
if (!['cost', 'balance', 'intelligence'].includes(out.hybrid_mode)) {
|
|
77
|
-
throw new Error(`invalid hybrid_mode: ${out.hybrid_mode}`);
|
|
78
|
-
}
|
|
79
|
-
if (!['hybrid', 'device', 'cloud'].includes(out.hybrid_execution)) {
|
|
80
|
-
throw new Error(`invalid hybrid_execution: ${out.hybrid_execution}`);
|
|
81
|
-
}
|
|
82
|
-
if (!['auto', 'cpu', 'cuda'].includes(out.compute)) {
|
|
83
|
-
throw new Error(`invalid compute: ${out.compute}`);
|
|
84
|
-
}
|
|
85
|
-
const timeout = Number(out.hybrid_semantic_timeout_ms);
|
|
86
|
-
const cache = Number(out.hybrid_semantic_cache_size);
|
|
87
|
-
if (!Number.isInteger(timeout) || !Number.isInteger(cache) || timeout <= 0 || cache <= 0) {
|
|
88
|
-
throw new Error('hybrid_semantic_timeout_ms / cache_size must be positive integers');
|
|
89
|
-
}
|
|
90
|
-
out.hybrid_semantic = Boolean(out.hybrid_semantic);
|
|
91
|
-
out.hybrid_semantic_timeout_ms = timeout;
|
|
92
|
-
out.hybrid_semantic_cache_size = cache;
|
|
93
|
-
const filled = fillAuthUrls(out);
|
|
94
|
-
if (filled.cloud_api_key && !(filled.cloud_url && filled.site_url && filled.upgrade_url)) {
|
|
95
|
-
const [cloud, site, upgrade] = detectGatewayPair(filled.cloud_api_key);
|
|
96
|
-
if (!filled.cloud_url) filled.cloud_url = cloud;
|
|
97
|
-
if (!filled.site_url) filled.site_url = site;
|
|
98
|
-
if (!filled.upgrade_url) filled.upgrade_url = upgrade;
|
|
99
|
-
}
|
|
100
|
-
return filled;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
module.exports = {
|
|
104
|
-
INTL_CLOUD,
|
|
105
|
-
INTL_SITE,
|
|
106
|
-
INTL_UPGRADE,
|
|
107
|
-
CN_CLOUD,
|
|
108
|
-
CN_SITE,
|
|
109
|
-
CN_UPGRADE,
|
|
110
|
-
defaultAuthConfig,
|
|
111
|
-
fillAuthUrls,
|
|
112
|
-
applyAuth,
|
|
113
|
-
authHooks,
|
|
114
|
-
detectGatewayPair,
|
|
115
|
-
};
|
package/test/auth.test.cjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
const test = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const os = require('node:os');
|
|
5
|
-
const path = require('node:path');
|
|
6
|
-
const {
|
|
7
|
-
applyAuth,
|
|
8
|
-
defaultAuthConfig,
|
|
9
|
-
fillAuthUrls,
|
|
10
|
-
authHooks,
|
|
11
|
-
CN_CLOUD,
|
|
12
|
-
CN_SITE,
|
|
13
|
-
CN_UPGRADE,
|
|
14
|
-
} = require('../src/auth.js');
|
|
15
|
-
|
|
16
|
-
test('auth defaults', () => {
|
|
17
|
-
const cfg = defaultAuthConfig();
|
|
18
|
-
assert.equal(cfg.hybrid_mode, 'balance');
|
|
19
|
-
assert.equal(cfg.hybrid_execution, 'hybrid');
|
|
20
|
-
assert.equal(cfg.hybrid_semantic, true);
|
|
21
|
-
assert.equal(cfg.hybrid_semantic_timeout_ms, 800);
|
|
22
|
-
assert.equal(cfg.hybrid_semantic_cache_size, 512);
|
|
23
|
-
assert.equal(cfg.compute, 'auto');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('auth invalid enum', () => {
|
|
27
|
-
assert.throws(() => applyAuth(defaultAuthConfig(), { hybrid_mode: 'fast' }));
|
|
28
|
-
assert.throws(() => applyAuth(defaultAuthConfig(), { hybrid_execution: 'local' }));
|
|
29
|
-
assert.throws(() => applyAuth(defaultAuthConfig(), { compute: 'gpu' }));
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('auth fills urls from cn site', () => {
|
|
33
|
-
const got = fillAuthUrls({ site_url: CN_SITE, cloud_url: '', upgrade_url: '' });
|
|
34
|
-
assert.equal(got.cloud_url, CN_CLOUD);
|
|
35
|
-
assert.equal(got.upgrade_url, CN_UPGRADE);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('auth instance all fields via applyAuth', () => {
|
|
39
|
-
const st = applyAuth(defaultAuthConfig(), {
|
|
40
|
-
cloud_api_key: 'sk-test',
|
|
41
|
-
cloud_url: CN_CLOUD,
|
|
42
|
-
site_url: CN_SITE,
|
|
43
|
-
upgrade_url: CN_UPGRADE,
|
|
44
|
-
hybrid_mode: 'cost',
|
|
45
|
-
hybrid_execution: 'device',
|
|
46
|
-
hybrid_semantic: false,
|
|
47
|
-
hybrid_semantic_timeout_ms: 250,
|
|
48
|
-
hybrid_semantic_cache_size: 16,
|
|
49
|
-
compute: 'cpu',
|
|
50
|
-
hf_token: 'hf_abc',
|
|
51
|
-
modelscope_api_token: 'ms_xyz',
|
|
52
|
-
});
|
|
53
|
-
assert.equal(st.cloud_api_key, 'sk-test');
|
|
54
|
-
assert.equal(st.hybrid_mode, 'cost');
|
|
55
|
-
assert.equal(st.hf_token, 'hf_abc');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('auth partial merge', () => {
|
|
59
|
-
const once = applyAuth(defaultAuthConfig(), { hf_token: 'hf_one', hybrid_mode: 'intelligence' });
|
|
60
|
-
const st = applyAuth(once, { compute: 'cuda' });
|
|
61
|
-
assert.equal(st.hf_token, 'hf_one');
|
|
62
|
-
assert.equal(st.hybrid_mode, 'intelligence');
|
|
63
|
-
assert.equal(st.compute, 'cuda');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('auth invalid enum leaves state', () => {
|
|
67
|
-
const once = applyAuth(defaultAuthConfig(), { hybrid_mode: 'cost' });
|
|
68
|
-
assert.throws(() => applyAuth(once, { hybrid_mode: 'nope' }));
|
|
69
|
-
assert.equal(once.hybrid_mode, 'cost');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('auth fills urls from site tld', () => {
|
|
73
|
-
const st = applyAuth(defaultAuthConfig(), { site_url: 'https://ariacompute.cn' });
|
|
74
|
-
assert.equal(st.cloud_url, CN_CLOUD);
|
|
75
|
-
assert.equal(st.upgrade_url, CN_UPGRADE);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('auth does not write config.yml', () => {
|
|
79
|
-
const prev = process.env.ARIA_COMPUTE_HOME;
|
|
80
|
-
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'aria-rn-auth-'));
|
|
81
|
-
process.env.ARIA_COMPUTE_HOME = home;
|
|
82
|
-
try {
|
|
83
|
-
applyAuth(defaultAuthConfig(), {
|
|
84
|
-
cloud_api_key: 'sk-test',
|
|
85
|
-
site_url: 'https://ariacompute.com',
|
|
86
|
-
hf_token: 'hf_x',
|
|
87
|
-
});
|
|
88
|
-
assert.equal(fs.existsSync(path.join(home, 'config.yml')), false);
|
|
89
|
-
} finally {
|
|
90
|
-
if (prev === undefined) delete process.env.ARIA_COMPUTE_HOME;
|
|
91
|
-
else process.env.ARIA_COMPUTE_HOME = prev;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('auth detect urls from key mocked', () => {
|
|
96
|
-
const prev = authHooks.probeDashboard;
|
|
97
|
-
authHooks.probeDashboard = (site) => String(site).includes('ariacompute.cn');
|
|
98
|
-
try {
|
|
99
|
-
const st = applyAuth(defaultAuthConfig(), { cloud_api_key: 'sk-region' });
|
|
100
|
-
assert.equal(st.site_url, CN_SITE);
|
|
101
|
-
assert.equal(st.cloud_url, CN_CLOUD);
|
|
102
|
-
assert.equal(st.upgrade_url, CN_UPGRADE);
|
|
103
|
-
} finally {
|
|
104
|
-
authHooks.probeDashboard = prev;
|
|
105
|
-
}
|
|
106
|
-
});
|