@ariacompute/engine-rn 1.15.1 → 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 +6 -3
- package/package.json +4 -1
- package/src/index.js +59 -17
- package/src/setup.js +60 -0
- package/test/setup.test.cjs +77 -0
package/README.md
CHANGED
|
@@ -20,10 +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
|
+
reused without re-downloading.
|
|
25
26
|
|
|
26
27
|
```js
|
|
27
28
|
const eng = await AriaEngine.open("gemma-4-e2b-it_q4");
|
|
28
|
-
const gated =
|
|
29
|
+
const gated = new AriaEngine();
|
|
30
|
+
gated.setup({ hf_token: "hf_..." });
|
|
31
|
+
await gated.open("gemma-4-e2b-it_q4");
|
|
29
32
|
```
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
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",
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react-native": ">=0.72.0"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test test/setup.test.cjs"
|
|
9
12
|
}
|
|
10
13
|
}
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* `~/.ariacompute/models/{model}`, then loads via native init.
|
|
9
9
|
*/
|
|
10
10
|
import { NativeModules } from 'react-native';
|
|
11
|
+
import {
|
|
12
|
+
defaultSetupConfig,
|
|
13
|
+
applySetup,
|
|
14
|
+
} from './setup.js';
|
|
11
15
|
|
|
12
16
|
const AriaEngineModule = NativeModules.AriaEngine;
|
|
13
17
|
|
|
@@ -87,19 +91,22 @@ function unquoteYaml(v) {
|
|
|
87
91
|
function configYmlScalar(key) {
|
|
88
92
|
const fs = require('fs');
|
|
89
93
|
const path = require('path');
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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;
|
|
100
109
|
}
|
|
101
|
-
} catch {
|
|
102
|
-
return undefined;
|
|
103
110
|
}
|
|
104
111
|
return undefined;
|
|
105
112
|
}
|
|
@@ -209,7 +216,7 @@ async function fetchHubFile(source, model, file, dest, token, required) {
|
|
|
209
216
|
if (e && (e.status === 401 || e.status === 403)) {
|
|
210
217
|
const field = source === 'modelscope' ? 'modelscope_api_token' : 'hf_token';
|
|
211
218
|
throw new Error(
|
|
212
|
-
`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)`,
|
|
213
220
|
);
|
|
214
221
|
}
|
|
215
222
|
}
|
|
@@ -421,14 +428,49 @@ async function ensureFfiLib(site) {
|
|
|
421
428
|
export class AriaEngine {
|
|
422
429
|
constructor(bundlePath) {
|
|
423
430
|
this.bundlePath = bundlePath;
|
|
431
|
+
this.cfg = defaultSetupConfig();
|
|
432
|
+
this.opts = {};
|
|
424
433
|
// NativeModules.AriaEngine.init(bundlePath) when linked.
|
|
425
434
|
}
|
|
426
435
|
|
|
427
|
-
|
|
436
|
+
setup(updates) {
|
|
437
|
+
this.cfg = applySetup(this.cfg, updates);
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
setupStatus() {
|
|
442
|
+
return { ...this.cfg };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
setupClear() {
|
|
446
|
+
this.cfg = defaultSetupConfig();
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async open(modelRef) {
|
|
451
|
+
const opts = {
|
|
452
|
+
...this.opts,
|
|
453
|
+
site: this.cfg.site_url || this.opts.site,
|
|
454
|
+
hfToken: this.cfg.hf_token || this.opts.hfToken,
|
|
455
|
+
modelscopeApiToken: this.cfg.modelscope_api_token || this.opts.modelscopeApiToken,
|
|
456
|
+
};
|
|
428
457
|
await ensureFfiLib(opts.site);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
458
|
+
this.bundlePath = isLocalRef(modelRef) ? modelRef : await downloadModel(modelRef, opts);
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
static async open(modelRef, opts = {}) {
|
|
463
|
+
const eng = new AriaEngine();
|
|
464
|
+
eng.opts = opts;
|
|
465
|
+
if (opts.site || opts.hfToken || opts.modelscopeApiToken) {
|
|
466
|
+
eng.setup({
|
|
467
|
+
site_url: opts.site,
|
|
468
|
+
hf_token: opts.hfToken,
|
|
469
|
+
modelscope_api_token: opts.modelscopeApiToken,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
await eng.open(modelRef);
|
|
473
|
+
return eng;
|
|
432
474
|
}
|
|
433
475
|
|
|
434
476
|
async complete(messages, options = { max_tokens: 16 }, tools = []) {
|
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
|
+
});
|