@ariacompute/engine-ts 1.16.0 → 1.17.1

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 CHANGED
@@ -24,12 +24,12 @@ and then loads it. Dashboard is not used. A Dashboard `sk-` / `bfvk-` token is
24
24
  ignored for hub auth. Token is optional for public models. A valid cached bundle
25
25
  is reused without re-downloading.
26
26
 
27
- Gated files: call `eng.auth({ hf_token })` (`.com`) or `eng.auth({ modelscope_api_token, site_url })` (`.cn`) **before** `open`. Same keys as `aria-engine auth`. Instance-only; does not write `config.yml`. If omitted, the SDK reads `~/.ariacompute/config.yml`.
27
+ Gated files: call `eng.setup({ hf_token })` (`.com`) or `eng.setup({ modelscope_api_token, site_url })` (`.cn`) **before** `open`. Same keys as `aria-engine setup`. Instance-only; does not write `engine.yml`. If omitted, the SDK reads `~/.ariacompute/engine.yml`.
28
28
 
29
29
  ```ts
30
30
  const eng = await Engine.open("gemma-4-e2b-it_q4");
31
31
 
32
32
  const gated = new Engine();
33
- gated.auth({ hf_token: "hf_..." });
33
+ gated.setup({ hf_token: "hf_..." });
34
34
  await gated.open("gemma-4-e2b-it_q4");
35
35
  ```
package/dist/index.d.ts CHANGED
@@ -29,43 +29,30 @@ export interface CompleteResult {
29
29
  export interface OpenOptions {
30
30
  /** Legacy generic hub token. Dashboard sk-/bfvk- keys are ignored. */
31
31
  token?: string;
32
- /** Hugging Face hub token (`.com`). Same field as `aria-engine auth` `hf_token`. */
32
+ /** Hugging Face hub token (`.com`). Same field as `aria-engine setup` `hf_token`. */
33
33
  hfToken?: string;
34
- /** ModelScope hub token (`.cn`). Same field as `aria-engine auth` `modelscope_api_token`. */
34
+ /** ModelScope hub token (`.cn`). Same field as `aria-engine setup` `modelscope_api_token`. */
35
35
  modelscopeApiToken?: string;
36
36
  /** Site used to pick the regional hub. Defaults to https://ariacompute.com (.com → HF, .cn → ModelScope). */
37
37
  site?: string;
38
38
  /** Explicit path to the FFI library. */
39
39
  ffiLib?: string;
40
40
  }
41
- export declare const INTL_CLOUD = "https://gateway.ariacompute.com";
42
41
  export declare const INTL_SITE = "https://ariacompute.com";
43
42
  export declare const INTL_UPGRADE = "https://github.com/ariacompute";
44
- export declare const CN_CLOUD = "https://gateway.ariacompute.cn";
45
43
  export declare const CN_SITE = "https://ariacompute.cn";
46
44
  export declare const CN_UPGRADE = "https://gitee.com/ariacompute";
47
- export interface AuthConfig {
48
- cloud_api_key: string;
49
- cloud_url: string;
45
+ export interface SetupConfig {
46
+ router: string;
50
47
  site_url: string;
51
48
  upgrade_url: string;
52
- hybrid_mode: string;
53
- hybrid_execution: string;
54
- hybrid_semantic: boolean;
55
- hybrid_semantic_timeout_ms: number;
56
- hybrid_semantic_cache_size: number;
57
49
  compute: string;
58
50
  hf_token: string;
59
51
  modelscope_api_token: string;
60
52
  }
61
- export declare function defaultAuthConfig(): AuthConfig;
62
- export declare function fillAuthUrls(cfg: AuthConfig): AuthConfig;
63
- /** Replace `authHooks.probeDashboard` in tests to avoid a real Dashboard probe. */
64
- export declare const authHooks: {
65
- probeDashboard: (siteUrl: string, apiKey: string) => boolean;
66
- };
67
- export declare function detectGatewayPair(apiKey: string): [string, string, string];
68
- export declare function applyAuth(existing: AuthConfig, updates: Partial<AuthConfig>): AuthConfig;
53
+ export declare function defaultSetupConfig(): SetupConfig;
54
+ export declare function fillSetupUrls(cfg: SetupConfig): SetupConfig;
55
+ export declare function applySetup(existing: SetupConfig, updates: Partial<SetupConfig>): SetupConfig;
69
56
  /** Parse `slug`/`quant` from a model name such as `gemma-4-e2b-it_q4`. */
70
57
  export declare function parseBundleName(model: string): {
71
58
  slug: string;
@@ -102,13 +89,13 @@ export declare class Engine {
102
89
  private opts;
103
90
  /** Empty construct, or a local bundle directory. */
104
91
  constructor(bundle?: string, opts?: OpenOptions);
105
- /** Set Config / Run fields on this instance only. Does not write config.yml. */
106
- auth(updates: Partial<AuthConfig>): this;
107
- authStatus(): AuthConfig;
108
- /** Reset instance defaults. Does not delete ~/.ariacompute/config.yml. */
109
- authClear(): this;
92
+ /** Set Config / Run fields on this instance only. Does not write engine.yml. */
93
+ setup(updates: Partial<SetupConfig>): this;
94
+ setupStatus(): SetupConfig;
95
+ /** Reset instance defaults. Does not delete ~/.ariacompute/engine.yml. */
96
+ setupClear(): this;
110
97
  private bindAndInit;
111
- /** Download (if needed) and load a model using instance auth. */
98
+ /** Download (if needed) and load a model using instance setup. */
112
99
  open(modelRef: string): Promise<this>;
113
100
  /** Auto-detect: a value containing a separator or already on disk is a local
114
101
  * path; otherwise it is a model name downloaded from the regional public hub. */
package/dist/index.js CHANGED
@@ -33,11 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports._internal = exports.Engine = exports.authHooks = exports.CN_UPGRADE = exports.CN_SITE = exports.CN_CLOUD = exports.INTL_UPGRADE = exports.INTL_SITE = exports.INTL_CLOUD = void 0;
37
- exports.defaultAuthConfig = defaultAuthConfig;
38
- exports.fillAuthUrls = fillAuthUrls;
39
- exports.detectGatewayPair = detectGatewayPair;
40
- exports.applyAuth = applyAuth;
36
+ exports._internal = exports.Engine = exports.CN_UPGRADE = exports.CN_SITE = exports.INTL_UPGRADE = exports.INTL_SITE = void 0;
37
+ exports.defaultSetupConfig = defaultSetupConfig;
38
+ exports.fillSetupUrls = fillSetupUrls;
39
+ exports.applySetup = applySetup;
41
40
  exports.parseBundleName = parseBundleName;
42
41
  exports.preferredPublicHub = preferredPublicHub;
43
42
  exports.hubBearer = hubBearer;
@@ -60,23 +59,15 @@ const promises_1 = require("node:stream/promises");
60
59
  const node_stream_1 = require("node:stream");
61
60
  const zlib = __importStar(require("node:zlib"));
62
61
  const DEFAULT_SITE = "https://ariacompute.com";
63
- exports.INTL_CLOUD = "https://gateway.ariacompute.com";
64
62
  exports.INTL_SITE = "https://ariacompute.com";
65
63
  exports.INTL_UPGRADE = "https://github.com/ariacompute";
66
- exports.CN_CLOUD = "https://gateway.ariacompute.cn";
67
64
  exports.CN_SITE = "https://ariacompute.cn";
68
65
  exports.CN_UPGRADE = "https://gitee.com/ariacompute";
69
- function defaultAuthConfig() {
66
+ function defaultSetupConfig() {
70
67
  return {
71
- cloud_api_key: "",
72
- cloud_url: "",
68
+ router: "",
73
69
  site_url: "",
74
70
  upgrade_url: "",
75
- hybrid_mode: "balance",
76
- hybrid_execution: "hybrid",
77
- hybrid_semantic: true,
78
- hybrid_semantic_timeout_ms: 800,
79
- hybrid_semantic_cache_size: 512,
80
71
  compute: "auto",
81
72
  hf_token: "",
82
73
  modelscope_api_token: "",
@@ -91,95 +82,31 @@ function gatewayRegion(url) {
91
82
  return undefined;
92
83
  }
93
84
  function pairUrls(region) {
94
- return region === "cn" ? [exports.CN_CLOUD, exports.CN_SITE, exports.CN_UPGRADE] : [exports.INTL_CLOUD, exports.INTL_SITE, exports.INTL_UPGRADE];
85
+ return region === "cn" ? [exports.CN_SITE, exports.CN_UPGRADE] : [exports.INTL_SITE, exports.INTL_UPGRADE];
95
86
  }
96
- function fillAuthUrls(cfg) {
87
+ function fillSetupUrls(cfg) {
97
88
  const out = { ...cfg };
98
- const region = gatewayRegion(out.site_url) || gatewayRegion(out.cloud_url) || gatewayRegion(out.upgrade_url);
89
+ const region = gatewayRegion(out.site_url) || gatewayRegion(out.upgrade_url);
99
90
  if (!region)
100
91
  return out;
101
- const [cloud, site, upgrade] = pairUrls(region);
102
- if (!out.cloud_url)
103
- out.cloud_url = cloud;
92
+ const [site, upgrade] = pairUrls(region);
104
93
  if (!out.site_url)
105
94
  out.site_url = site;
106
95
  if (!out.upgrade_url)
107
96
  out.upgrade_url = upgrade;
108
97
  return out;
109
98
  }
110
- function localePrefersCn() {
111
- const lang = `${process.env.LANG || ""}${process.env.LC_ALL || ""}`.toLowerCase();
112
- return lang.includes("zh") || lang.includes(".cn") || lang.startsWith("cn");
113
- }
114
- function defaultProbeDashboard(siteUrl, apiKey) {
115
- const url = `${(siteUrl || "").replace(/\/$/, "")}/api/dashboard/models`;
116
- const script = 'fetch(process.env.ARIA_PROBE_URL,{headers:{"User-Agent":"aria-engine-sdk/0.1.0","Authorization":"Bearer "+process.env.ARIA_PROBE_KEY},redirect:"follow"}).then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))';
117
- const r = (0, node_child_process_1.spawnSync)(process.execPath, ["-e", script], {
118
- env: { ...process.env, ARIA_PROBE_URL: url, ARIA_PROBE_KEY: apiKey },
119
- timeout: 10000,
120
- });
121
- return r.status === 0;
122
- }
123
- /** Replace `authHooks.probeDashboard` in tests to avoid a real Dashboard probe. */
124
- exports.authHooks = {
125
- probeDashboard: defaultProbeDashboard,
126
- };
127
- function detectGatewayPair(apiKey) {
128
- const key = (apiKey || "").trim();
129
- const first = localePrefersCn() ? "cn" : "intl";
130
- const second = first === "cn" ? "intl" : "cn";
131
- for (const region of [first, second]) {
132
- const [cloud, site, upgrade] = pairUrls(region);
133
- if (key && exports.authHooks.probeDashboard(site, key))
134
- return [cloud, site, upgrade];
135
- }
136
- return pairUrls(first);
137
- }
138
- function applyAuth(existing, updates) {
99
+ function applySetup(existing, updates) {
139
100
  const out = { ...existing };
140
101
  for (const [k, v] of Object.entries(updates)) {
141
102
  if (v === undefined)
142
103
  continue;
143
104
  out[k] = v;
144
105
  }
145
- if (!["cost", "balance", "intelligence"].includes(out.hybrid_mode)) {
146
- throw new Error(`invalid hybrid_mode: ${out.hybrid_mode}`);
147
- }
148
- if (!["hybrid", "device", "cloud"].includes(out.hybrid_execution)) {
149
- throw new Error(`invalid hybrid_execution: ${out.hybrid_execution}`);
150
- }
151
106
  if (!["auto", "cpu", "cuda"].includes(out.compute)) {
152
107
  throw new Error(`invalid compute: ${out.compute}`);
153
108
  }
154
- const timeout = Number(out.hybrid_semantic_timeout_ms);
155
- const cache = Number(out.hybrid_semantic_cache_size);
156
- if (!Number.isInteger(timeout) || !Number.isInteger(cache) || timeout <= 0 || cache <= 0) {
157
- throw new Error("hybrid_semantic_timeout_ms / cache_size must be positive integers");
158
- }
159
- out.hybrid_semantic = Boolean(out.hybrid_semantic);
160
- out.hybrid_semantic_timeout_ms = timeout;
161
- out.hybrid_semantic_cache_size = cache;
162
- for (const key of [
163
- "cloud_api_key",
164
- "cloud_url",
165
- "site_url",
166
- "upgrade_url",
167
- "hf_token",
168
- "modelscope_api_token",
169
- ]) {
170
- out[key] = out[key] == null ? "" : String(out[key]);
171
- }
172
- const filled = fillAuthUrls(out);
173
- if (filled.cloud_api_key && !(filled.cloud_url && filled.site_url && filled.upgrade_url)) {
174
- const [cloud, site, upgrade] = detectGatewayPair(filled.cloud_api_key);
175
- if (!filled.cloud_url)
176
- filled.cloud_url = cloud;
177
- if (!filled.site_url)
178
- filled.site_url = site;
179
- if (!filled.upgrade_url)
180
- filled.upgrade_url = upgrade;
181
- }
182
- return filled;
109
+ return fillSetupUrls(out);
183
110
  }
184
111
  const DEFAULT_SDK = "v1.0";
185
112
  const HUB_REQUIRED = ["config.json", "weight.bin"];
@@ -257,23 +184,27 @@ function unquoteYaml(v) {
257
184
  return t;
258
185
  }
259
186
  function configYmlScalar(key) {
260
- try {
261
- const raw = fs.readFileSync(path.join(ariaHome(), "config.yml"), "utf8");
262
- for (const line of raw.split("\n")) {
263
- if (line.startsWith(" ") || line.startsWith("\t"))
264
- continue;
265
- const s = line.trim();
266
- if (!s || s.startsWith("#") || !s.includes(":"))
267
- continue;
268
- const idx = s.indexOf(":");
269
- if (s.slice(0, idx).trim() !== key)
270
- continue;
271
- const v = unquoteYaml(s.slice(idx + 1));
272
- return v || undefined;
187
+ const home = ariaHome();
188
+ for (const name of ["engine.yml", "config.yml"]) {
189
+ try {
190
+ const raw = fs.readFileSync(path.join(home, name), "utf8");
191
+ for (const line of raw.split("\n")) {
192
+ if (line.startsWith(" ") || line.startsWith("\t"))
193
+ continue;
194
+ const s = line.trim();
195
+ if (!s || s.startsWith("#") || !s.includes(":"))
196
+ continue;
197
+ const idx = s.indexOf(":");
198
+ if (s.slice(0, idx).trim() !== key)
199
+ continue;
200
+ const v = unquoteYaml(s.slice(idx + 1));
201
+ if (v)
202
+ return v;
203
+ }
204
+ }
205
+ catch {
206
+ continue;
273
207
  }
274
- }
275
- catch {
276
- return undefined;
277
208
  }
278
209
  return undefined;
279
210
  }
@@ -361,7 +292,7 @@ async function fetchHubFile(source, model, file, dest, token, required) {
361
292
  last = e;
362
293
  if (e instanceof HubHttpError && (e.status === 401 || e.status === 403)) {
363
294
  const field = source === "modelscope" ? "modelscope_api_token" : "hf_token";
364
- throw new Error(`auth failed HTTP ${e.status}; set ${field} via aria-engine auth (do not pass a Dashboard sk-/bfvk- key as the hub token)`);
295
+ throw new Error(`auth failed HTTP ${e.status}; set ${field} via aria-engine setup (do not pass a Dashboard sk-/bfvk- key as the hub token)`);
365
296
  }
366
297
  }
367
298
  }
@@ -637,11 +568,11 @@ class Engine {
637
568
  constructor(bundle, opts = {}) {
638
569
  this.lib = null;
639
570
  this.handle = null;
640
- this.cfg = defaultAuthConfig();
571
+ this.cfg = defaultSetupConfig();
641
572
  this.opts = {};
642
573
  this.opts = opts;
643
574
  if (opts.site || opts.hfToken || opts.modelscopeApiToken) {
644
- this.auth({
575
+ this.setup({
645
576
  site_url: opts.site,
646
577
  hf_token: opts.hfToken,
647
578
  modelscope_api_token: opts.modelscopeApiToken,
@@ -650,17 +581,17 @@ class Engine {
650
581
  if (bundle)
651
582
  this.bindAndInit(bundle, opts.ffiLib);
652
583
  }
653
- /** Set Config / Run fields on this instance only. Does not write config.yml. */
654
- auth(updates) {
655
- this.cfg = applyAuth(this.cfg, updates);
584
+ /** Set Config / Run fields on this instance only. Does not write engine.yml. */
585
+ setup(updates) {
586
+ this.cfg = applySetup(this.cfg, updates);
656
587
  return this;
657
588
  }
658
- authStatus() {
589
+ setupStatus() {
659
590
  return { ...this.cfg };
660
591
  }
661
- /** Reset instance defaults. Does not delete ~/.ariacompute/config.yml. */
662
- authClear() {
663
- this.cfg = defaultAuthConfig();
592
+ /** Reset instance defaults. Does not delete ~/.ariacompute/engine.yml. */
593
+ setupClear() {
594
+ this.cfg = defaultSetupConfig();
664
595
  return this;
665
596
  }
666
597
  bindAndInit(bundle, ffiLib) {
@@ -677,7 +608,7 @@ class Engine {
677
608
  throw new Error(err || "init failed");
678
609
  }
679
610
  }
680
- /** Download (if needed) and load a model using instance auth. */
611
+ /** Download (if needed) and load a model using instance setup. */
681
612
  async open(modelRef) {
682
613
  await ensureFfiLib(this.cfg.site_url || this.opts.site);
683
614
  const openOpts = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariacompute/engine-ts",
3
- "version": "1.16.0",
3
+ "version": "1.17.1",
4
4
  "description": "TypeScript/Node SDK for Aria Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",