@gobing-ai/ts-laya-mlx 0.5.30 → 0.5.32

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
@@ -22,8 +22,9 @@ Part of the `@gobing-ai/ts-libs` monorepo and lockstep-versioned with it.
22
22
 
23
23
  1. **Platform:** macOS on Apple Silicon (`darwin arm64`). Unsupported platforms fail fast at construction time before any process is spawned.
24
24
  2. **Python (core `mlx-python` only):** Python 3.10+ carrying the `laya-mlx` runtime (resolvable via `pythonPath`, injected `env.LAYA_PYTHON`, or `python3` on `PATH`). Core `mlx-native` needs no Python.
25
- 3. **Supported runtime range:** `laya-mlx 0.1.x` (validated against upstream `0.1.0` @ `fc1df62828a3fedf4d8229fdac1cbd85f1cdf337`).
26
- 4. **Install command:**
25
+ 3. **Worker script (core `mlx-python` only):** the package ships `worker/laya_worker.py` and finds it relative to its own module. A host that **bundles** this package into a single file (e.g. `bun build`) relocates the module, so it must ship the script itself and point at it with the `workerScript` option or injected `env.LAYA_WORKER_SCRIPT`. A missing script fails the ask with `DecisionConfigError` (`variable: 'LAYA_WORKER_SCRIPT'`) naming the path it tried, which the decision hub maps to the declared fallback.
26
+ 4. **Supported runtime range:** `laya-mlx 0.1.x` (validated against upstream `0.1.0` @ `fc1df62828a3fedf4d8229fdac1cbd85f1cdf337`).
27
+ 5. **Install command:**
27
28
  ```sh
28
29
  pip install laya-mlx
29
30
  # or with uv:
@@ -19,7 +19,11 @@ export interface LayaWorkerClientOptions {
19
19
  pythonPath?: string;
20
20
  /** Runtime module the worker imports. Default: `'laya_mlx'`. */
21
21
  module?: string;
22
- /** Worker script path. Default: `worker/laya_worker.py` in this package. */
22
+ /**
23
+ * Worker script path. Default: `env.LAYA_WORKER_SCRIPT`, else `worker/laya_worker.py` in this
24
+ * package. Hosts that bundle this package into one file must ship the script and set one of these:
25
+ * the default resolves relative to the module, which a bundle relocates.
26
+ */
23
27
  workerScript?: string;
24
28
  /** Working directory for the spawn. Default: this package root. */
25
29
  cwd?: string;
@@ -87,6 +91,7 @@ export declare function resolvePythonPath(options: LayaWorkerClientOptions, pack
87
91
  export declare class LayaWorkerClient {
88
92
  private readonly pythonPath;
89
93
  private readonly args;
94
+ private readonly workerScript;
90
95
  private readonly cwd;
91
96
  private readonly startupTimeoutMs;
92
97
  private readonly requestTimeoutMs;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-client.d.ts","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAKH,KAAK,aAAa,EAGrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,KAAK,UAAU,EAKf,KAAK,eAAe,EACvB,MAAM,uBAAuB,CAAC;AAW/B,0DAA0D;AAC1D,MAAM,WAAW,uBAAuB;IACpC,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;IAC3C,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,G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7 @@ export function resolvePythonPath(options, packageRoot, cwd, fileSystem = nodeBu
349
349
  export class LayaWorkerClient {
350
350
  pythonPath;
351
351
  args;
352
+ workerScript;
352
353
  cwd;
353
354
  startupTimeoutMs;
354
355
  requestTimeoutMs;
@@ -366,7 +367,13 @@ export class LayaWorkerClient {
366
367
  this.requestTimeoutMs = options.requestTimeoutMs ?? 30_000;
367
368
  this.forwardedEnv = resolveForwardedEnv(options.env);
368
369
  this.executor = executor;
369
- this.args = [options.workerScript ?? joinPath(packageRoot, 'worker', 'laya_worker.py')];
370
+ const envScript = options.env?.LAYA_WORKER_SCRIPT;
371
+ this.workerScript =
372
+ options.workerScript ??
373
+ (envScript !== undefined && envScript.length > 0
374
+ ? envScript
375
+ : joinPath(packageRoot, 'worker', 'laya_worker.py'));
376
+ this.args = [this.workerScript];
370
377
  this.args.push('--module', options.module ?? 'laya_mlx');
371
378
  const resolvedModelPath = options.modelPath ?? options.env?.LAYA_MODEL_PATH;
372
379
  const resolvedCacheDir = options.cacheDir ?? options.env?.LAYA_CACHE_DIR;
@@ -445,6 +452,11 @@ export class LayaWorkerClient {
445
452
  return worker;
446
453
  }
447
454
  spawn() {
455
+ // Checked here, not in the constructor: a missing script must surface as a config error on
456
+ // the ask, the same channel as a missing interpreter, instead of an opaque worker exit.
457
+ if (!nodeBunFactory.createFileSystem().exists(this.workerScript)) {
458
+ throw new DecisionConfigError(`laya worker script '${this.workerScript}' not found; a bundled host must ship worker/laya_worker.py and pass workerScript or set LAYA_WORKER_SCRIPT`, 'LAYA_WORKER_SCRIPT');
459
+ }
448
460
  let proc;
449
461
  try {
450
462
  proc = this.executor.runStreaming({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-laya-mlx",
3
- "version": "0.5.30",
3
+ "version": "0.5.32",
4
4
  "description": "@gobing-ai/ts-laya-mlx — Local Laya decision backend driving the vendored MLX runtime over a process bridge.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -52,8 +52,8 @@
52
52
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-laya-mlx-v<version> && git push --tags' && exit 1"
53
53
  },
54
54
  "dependencies": {
55
- "@gobing-ai/ts-ai-runner": "^0.5.30",
56
- "@gobing-ai/ts-runtime": "^0.5.30",
55
+ "@gobing-ai/ts-ai-runner": "^0.5.32",
56
+ "@gobing-ai/ts-runtime": "^0.5.32",
57
57
  "@johnhenry/laya": "0.3.2"
58
58
  },
59
59
  "optionalDependencies": {
@@ -44,7 +44,11 @@ export interface LayaWorkerClientOptions {
44
44
  pythonPath?: string;
45
45
  /** Runtime module the worker imports. Default: `'laya_mlx'`. */
46
46
  module?: string;
47
- /** Worker script path. Default: `worker/laya_worker.py` in this package. */
47
+ /**
48
+ * Worker script path. Default: `env.LAYA_WORKER_SCRIPT`, else `worker/laya_worker.py` in this
49
+ * package. Hosts that bundle this package into one file must ship the script and set one of these:
50
+ * the default resolves relative to the module, which a bundle relocates.
51
+ */
48
52
  workerScript?: string;
49
53
  /** Working directory for the spawn. Default: this package root. */
50
54
  cwd?: string;
@@ -498,6 +502,7 @@ export function resolvePythonPath(
498
502
  export class LayaWorkerClient {
499
503
  private readonly pythonPath: string;
500
504
  private readonly args: string[];
505
+ private readonly workerScript: string;
501
506
  private readonly cwd: string;
502
507
  private readonly startupTimeoutMs: number;
503
508
  private readonly requestTimeoutMs: number;
@@ -519,7 +524,13 @@ export class LayaWorkerClient {
519
524
  this.requestTimeoutMs = options.requestTimeoutMs ?? 30_000;
520
525
  this.forwardedEnv = resolveForwardedEnv(options.env);
521
526
  this.executor = executor;
522
- this.args = [options.workerScript ?? joinPath(packageRoot, 'worker', 'laya_worker.py')];
527
+ const envScript = options.env?.LAYA_WORKER_SCRIPT;
528
+ this.workerScript =
529
+ options.workerScript ??
530
+ (envScript !== undefined && envScript.length > 0
531
+ ? envScript
532
+ : joinPath(packageRoot, 'worker', 'laya_worker.py'));
533
+ this.args = [this.workerScript];
523
534
  this.args.push('--module', options.module ?? 'laya_mlx');
524
535
  const resolvedModelPath = options.modelPath ?? options.env?.LAYA_MODEL_PATH;
525
536
  const resolvedCacheDir = options.cacheDir ?? options.env?.LAYA_CACHE_DIR;
@@ -602,6 +613,14 @@ export class LayaWorkerClient {
602
613
  }
603
614
 
604
615
  private spawn(): WorkerHandle {
616
+ // Checked here, not in the constructor: a missing script must surface as a config error on
617
+ // the ask, the same channel as a missing interpreter, instead of an opaque worker exit.
618
+ if (!nodeBunFactory.createFileSystem().exists(this.workerScript)) {
619
+ throw new DecisionConfigError(
620
+ `laya worker script '${this.workerScript}' not found; a bundled host must ship worker/laya_worker.py and pass workerScript or set LAYA_WORKER_SCRIPT`,
621
+ 'LAYA_WORKER_SCRIPT',
622
+ );
623
+ }
605
624
  let proc: PipeProcess;
606
625
  try {
607
626
  proc = this.executor.runStreaming({