@atomic-chat/core 0.18.4 → 0.19.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/app-daemon.js +5 -0
- package/dist/app-daemon.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +5 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/client/control-client.d.ts +18 -1
- package/dist/client/control-client.js +27 -0
- package/dist/client/control-client.js.map +1 -1
- package/dist/cloud/registry.js +1 -0
- package/dist/cloud/registry.js.map +1 -1
- package/dist/config/paths.d.ts +4 -0
- package/dist/config/paths.js +13 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/contracts/control-api.d.ts +9 -0
- package/dist/contracts/diffusion.d.ts +17 -7
- package/dist/contracts/diffusion.js.map +1 -1
- package/dist/contracts/engine-builds.d.ts +1 -1
- package/dist/contracts/engine-builds.js +1 -1
- package/dist/contracts/engine-builds.js.map +1 -1
- package/dist/contracts/engines.d.ts +1 -1
- package/dist/contracts/engines.js +2 -0
- package/dist/contracts/engines.js.map +1 -1
- package/dist/contracts/errors.d.ts +9 -1
- package/dist/contracts/errors.js.map +1 -1
- package/dist/contracts/events.d.ts +3 -0
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/litert-lm.d.ts +97 -0
- package/dist/contracts/litert-lm.js +17 -0
- package/dist/contracts/litert-lm.js.map +1 -0
- package/dist/contracts/model-yml.d.ts +31 -0
- package/dist/contracts/model-yml.js +5 -0
- package/dist/contracts/model-yml.js.map +1 -1
- package/dist/contracts/session.d.ts +5 -1
- package/dist/contracts/session.js.map +1 -1
- package/dist/contracts/settings.d.ts +10 -1
- package/dist/contracts/settings.js.map +1 -1
- package/dist/core/atomic-core.d.ts +6 -1
- package/dist/core/atomic-core.js +6 -0
- package/dist/core/atomic-core.js.map +1 -1
- package/dist/core/create.js +141 -20
- package/dist/core/create.js.map +1 -1
- package/dist/diffusion/args.d.ts +8 -0
- package/dist/diffusion/args.js +10 -0
- package/dist/diffusion/args.js.map +1 -1
- package/dist/diffusion/compat.d.ts +3 -3
- package/dist/diffusion/compat.js +15 -10
- package/dist/diffusion/compat.js.map +1 -1
- package/dist/diffusion/recipe.d.ts +19 -2
- package/dist/diffusion/recipe.js +43 -20
- package/dist/diffusion/recipe.js.map +1 -1
- package/dist/diffusion/remote-job.js +6 -7
- package/dist/diffusion/remote-job.js.map +1 -1
- package/dist/diffusion/service.d.ts +1 -0
- package/dist/diffusion/service.js +4 -2
- package/dist/diffusion/service.js.map +1 -1
- package/dist/diffusion/video-history.js +3 -2
- package/dist/diffusion/video-history.js.map +1 -1
- package/dist/diffusion/video-recipe.d.ts +4 -1
- package/dist/diffusion/video-recipe.js +15 -11
- package/dist/diffusion/video-recipe.js.map +1 -1
- package/dist/diffusion/workflow.d.ts +2 -1
- package/dist/diffusion/workflow.js +3 -1
- package/dist/diffusion/workflow.js.map +1 -1
- package/dist/downloads/archive.d.ts +2 -1
- package/dist/downloads/archive.js +3 -2
- package/dist/downloads/archive.js.map +1 -1
- package/dist/engine-builds/engines.d.ts +22 -5
- package/dist/engine-builds/engines.js +44 -7
- package/dist/engine-builds/engines.js.map +1 -1
- package/dist/engine-builds/litert-lm.d.ts +29 -0
- package/dist/engine-builds/litert-lm.js +119 -0
- package/dist/engine-builds/litert-lm.js.map +1 -0
- package/dist/engine-builds/manifest.d.ts +55 -1
- package/dist/engine-builds/manifest.js +114 -1
- package/dist/engine-builds/manifest.js.map +1 -1
- package/dist/engine-builds/order.d.ts +2 -1
- package/dist/engine-builds/order.js +3 -1
- package/dist/engine-builds/order.js.map +1 -1
- package/dist/engine-builds/select.d.ts +19 -1
- package/dist/engine-builds/select.js +45 -0
- package/dist/engine-builds/select.js.map +1 -1
- package/dist/engine-builds/service.d.ts +8 -5
- package/dist/engine-builds/service.js +11 -4
- package/dist/engine-builds/service.js.map +1 -1
- package/dist/engines/service.d.ts +3 -1
- package/dist/engines/service.js +4 -1
- package/dist/engines/service.js.map +1 -1
- package/dist/host/recipes/executor-io-windows.d.ts +10 -1
- package/dist/host/recipes/executor-io-windows.js +9 -3
- package/dist/host/recipes/executor-io-windows.js.map +1 -1
- package/dist/router/resolve.d.ts +25 -4
- package/dist/router/resolve.js +34 -3
- package/dist/router/resolve.js.map +1 -1
- package/dist/runtime/environment/host-exec.d.ts +2 -0
- package/dist/runtime/environment/host-exec.js +15 -4
- package/dist/runtime/environment/host-exec.js.map +1 -1
- package/dist/runtime/litert-lm/accelerators.d.ts +54 -0
- package/dist/runtime/litert-lm/accelerators.js +176 -0
- package/dist/runtime/litert-lm/accelerators.js.map +1 -0
- package/dist/runtime/litert-lm/check.d.ts +44 -0
- package/dist/runtime/litert-lm/check.js +113 -0
- package/dist/runtime/litert-lm/check.js.map +1 -0
- package/dist/runtime/litert-lm/host/args.d.ts +47 -0
- package/dist/runtime/litert-lm/host/args.js +108 -0
- package/dist/runtime/litert-lm/host/args.js.map +1 -0
- package/dist/runtime/litert-lm/host/ffi-bun.d.ts +16 -0
- package/dist/runtime/litert-lm/host/ffi-bun.js +535 -0
- package/dist/runtime/litert-lm/host/ffi-bun.js.map +1 -0
- package/dist/runtime/litert-lm/host/library.d.ts +113 -0
- package/dist/runtime/litert-lm/host/library.js +38 -0
- package/dist/runtime/litert-lm/host/library.js.map +1 -0
- package/dist/runtime/litert-lm/host/openai.d.ts +97 -0
- package/dist/runtime/litert-lm/host/openai.js +355 -0
- package/dist/runtime/litert-lm/host/openai.js.map +1 -0
- package/dist/runtime/litert-lm/host/pool.d.ts +51 -0
- package/dist/runtime/litert-lm/host/pool.js +114 -0
- package/dist/runtime/litert-lm/host/pool.js.map +1 -0
- package/dist/runtime/litert-lm/host/run.d.ts +48 -0
- package/dist/runtime/litert-lm/host/run.js +169 -0
- package/dist/runtime/litert-lm/host/run.js.map +1 -0
- package/dist/runtime/litert-lm/host/server.d.ts +28 -0
- package/dist/runtime/litert-lm/host/server.js +242 -0
- package/dist/runtime/litert-lm/host/server.js.map +1 -0
- package/dist/runtime/litert-lm/host-process.d.ts +44 -0
- package/dist/runtime/litert-lm/host-process.js +99 -0
- package/dist/runtime/litert-lm/host-process.js.map +1 -0
- package/dist/runtime/litert-lm/index.d.ts +10 -0
- package/dist/runtime/litert-lm/index.js +11 -0
- package/dist/runtime/litert-lm/index.js.map +1 -0
- package/dist/runtime/litert-lm/litert-host.d.ts +17 -0
- package/dist/runtime/litert-lm/litert-host.js +22 -0
- package/dist/runtime/litert-lm/litert-host.js.map +1 -0
- package/dist/runtime/litert-lm/model-yml.d.ts +8 -0
- package/dist/runtime/litert-lm/model-yml.js +67 -0
- package/dist/runtime/litert-lm/model-yml.js.map +1 -0
- package/dist/runtime/litert-lm/npu.d.ts +11 -0
- package/dist/runtime/litert-lm/npu.js +24 -0
- package/dist/runtime/litert-lm/npu.js.map +1 -0
- package/dist/runtime/litert-lm/runtime.d.ts +99 -0
- package/dist/runtime/litert-lm/runtime.js +354 -0
- package/dist/runtime/litert-lm/runtime.js.map +1 -0
- package/dist/runtime/shared/external-sessions.js +1 -0
- package/dist/runtime/shared/external-sessions.js.map +1 -1
- package/dist/server/control/router.js +2 -0
- package/dist/server/control/router.js.map +1 -1
- package/dist/server/control/routes/litert-lm.d.ts +11 -0
- package/dist/server/control/routes/litert-lm.js +33 -0
- package/dist/server/control/routes/litert-lm.js.map +1 -0
- package/dist/server/control/routes/public-server.js +22 -0
- package/dist/server/control/routes/public-server.js.map +1 -1
- package/dist/server/control/types.d.ts +16 -1
- package/dist/server/control/types.js.map +1 -1
- package/dist/server/http.js +3 -0
- package/dist/server/http.js.map +1 -1
- package/dist/server/public/errors.d.ts +17 -0
- package/dist/server/public/errors.js +28 -0
- package/dist/server/public/errors.js.map +1 -1
- package/dist/server/public/forward.d.ts +20 -1
- package/dist/server/public/forward.js +64 -14
- package/dist/server/public/forward.js.map +1 -1
- package/dist/server/public/listing.d.ts +6 -0
- package/dist/server/public/listing.js +25 -3
- package/dist/server/public/listing.js.map +1 -1
- package/dist/server/public/responses.js +21 -10
- package/dist/server/public/responses.js.map +1 -1
- package/dist/server/public/subscription.js +2 -2
- package/dist/server/public/subscription.js.map +1 -1
- package/dist/server/public/types.d.ts +5 -0
- package/dist/server/public/videos-params.js +6 -1
- package/dist/server/public/videos-params.js.map +1 -1
- package/dist/settings/schema/litert-lm.json +37 -0
- package/dist/settings/schema.js +9 -0
- package/dist/settings/schema.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
package/dist/router/resolve.d.ts
CHANGED
|
@@ -21,22 +21,25 @@ export interface RemoteProvider {
|
|
|
21
21
|
/** The image and video models enabled for this provider; never part of chat routing. */
|
|
22
22
|
media?: CloudProviderMedia;
|
|
23
23
|
}
|
|
24
|
-
export type LocalProvider = 'llamacpp' | 'llamacpp-upstream' | 'mlx' | 'tensorrt-llm' | 'atomic-prism' | 'vllm' | 'sglang' | 'foundry-local';
|
|
24
|
+
export type LocalProvider = 'llamacpp' | 'llamacpp-upstream' | 'mlx' | 'tensorrt-llm' | 'atomic-prism' | 'vllm' | 'sglang' | 'foundry-local' | 'litert-lm';
|
|
25
25
|
/**
|
|
26
26
|
* The order local providers are searched in when a request names only a model. The same model id
|
|
27
27
|
* loaded under two engines resolves to the first; changing the order would silently move traffic.
|
|
28
28
|
* `tensorrt-llm`, `atomic-prism`, `vllm` and `sglang` come last, in the order they were added, for
|
|
29
29
|
* exactly that reason: adding a provider moves nothing that already resolved (`vllm` after
|
|
30
30
|
* `atomic-prism`, which core 0.10.0 already shipped; change `add-vllm-runtime`, D11; `sglang` after
|
|
31
|
-
* `vllm`, change `add-sglang-runtime`, D8; `foundry-local` after `sglang`, change `add-foundry-local`, D5
|
|
31
|
+
* `vllm`, change `add-sglang-runtime`, D8; `foundry-local` after `sglang`, change `add-foundry-local`, D5;
|
|
32
|
+
* `litert-lm` after `foundry-local`, change `add-litert-lm-runtime`, task 6.1). A Prism-only file never loads
|
|
32
33
|
* under another engine (the compatibility gate), so its sessions are found here even near the end of
|
|
33
34
|
* the list; one store model is never loaded in two managed providers at once, so their order never
|
|
34
35
|
* decides between two live sessions of one id.
|
|
35
36
|
*/
|
|
36
37
|
export declare const LOCAL_SEARCH_ORDER: readonly LocalProvider[];
|
|
37
38
|
/**
|
|
38
|
-
* The remote provider that owns `modelId`, if any.
|
|
39
|
-
*
|
|
39
|
+
* The remote provider that owns `modelId`, if any. For an id the app selected no provider for
|
|
40
|
+
* (`resolveSelectedRoute`), remote wins over local — a model id the user enabled for a cloud
|
|
41
|
+
* provider is never served by a local session of the same name. An id with a selection goes to the
|
|
42
|
+
* selected provider only (ADR 2026-10-21-route-a-selected-model-id-to-its-selected-provider-only).
|
|
40
43
|
*
|
|
41
44
|
* Three rules, in order, exactly as the proxy applies them:
|
|
42
45
|
* 1. a provider that lists the model id;
|
|
@@ -44,6 +47,24 @@ export declare const LOCAL_SEARCH_ORDER: readonly LocalProvider[];
|
|
|
44
47
|
* 3. the whole id is a provider key.
|
|
45
48
|
*/
|
|
46
49
|
export declare function resolveRemoteProvider(modelId: string, providers: ReadonlyMap<string, RemoteProvider>): RemoteProvider | undefined;
|
|
50
|
+
/** Where a model id the app selected a provider for is served. */
|
|
51
|
+
export type SelectedRoute = {
|
|
52
|
+
kind: 'remote';
|
|
53
|
+
provider: RemoteProvider;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'local';
|
|
56
|
+
provider: LocalProvider;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The provider the app selected to serve `modelId` (`PUT /atomic/v1/server/selection`), when this
|
|
60
|
+
* core can route to it: a registered remote provider, or a local engine. The id is matched with the
|
|
61
|
+
* proxy's `.`/`_` rule. `undefined` — no selection, or one naming a provider this core does not know
|
|
62
|
+
* (an unregistered cloud provider, Apple Foundation Models) — leaves the id to the rules without one.
|
|
63
|
+
* A selected remote provider is strict. A selected local engine means "local": the caller asks that
|
|
64
|
+
* engine first, then any other local session of the id (the app and the core may name the engine
|
|
65
|
+
* differently), and refuses the request rather than send it to a remote provider that lists it.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveSelectedRoute(modelId: string, selection: ReadonlyMap<string, string>, providers: ReadonlyMap<string, RemoteProvider>): SelectedRoute | undefined;
|
|
47
68
|
/**
|
|
48
69
|
* The proxy's model-id comparison: `.` and `_` are the same character, because clients and
|
|
49
70
|
* filesystems substitute one for the other (`Qwen3_5-9B` is `Qwen3.5-9B`). Nothing else is folded.
|
package/dist/router/resolve.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* `tensorrt-llm`, `atomic-prism`, `vllm` and `sglang` come last, in the order they were added, for
|
|
12
12
|
* exactly that reason: adding a provider moves nothing that already resolved (`vllm` after
|
|
13
13
|
* `atomic-prism`, which core 0.10.0 already shipped; change `add-vllm-runtime`, D11; `sglang` after
|
|
14
|
-
* `vllm`, change `add-sglang-runtime`, D8; `foundry-local` after `sglang`, change `add-foundry-local`, D5
|
|
14
|
+
* `vllm`, change `add-sglang-runtime`, D8; `foundry-local` after `sglang`, change `add-foundry-local`, D5;
|
|
15
|
+
* `litert-lm` after `foundry-local`, change `add-litert-lm-runtime`, task 6.1). A Prism-only file never loads
|
|
15
16
|
* under another engine (the compatibility gate), so its sessions are found here even near the end of
|
|
16
17
|
* the list; one store model is never loaded in two managed providers at once, so their order never
|
|
17
18
|
* decides between two live sessions of one id.
|
|
@@ -25,10 +26,13 @@ export const LOCAL_SEARCH_ORDER = [
|
|
|
25
26
|
'vllm',
|
|
26
27
|
'sglang',
|
|
27
28
|
'foundry-local',
|
|
29
|
+
'litert-lm',
|
|
28
30
|
];
|
|
29
31
|
/**
|
|
30
|
-
* The remote provider that owns `modelId`, if any.
|
|
31
|
-
*
|
|
32
|
+
* The remote provider that owns `modelId`, if any. For an id the app selected no provider for
|
|
33
|
+
* (`resolveSelectedRoute`), remote wins over local — a model id the user enabled for a cloud
|
|
34
|
+
* provider is never served by a local session of the same name. An id with a selection goes to the
|
|
35
|
+
* selected provider only (ADR 2026-10-21-route-a-selected-model-id-to-its-selected-provider-only).
|
|
32
36
|
*
|
|
33
37
|
* Three rules, in order, exactly as the proxy applies them:
|
|
34
38
|
* 1. a provider that lists the model id;
|
|
@@ -48,6 +52,33 @@ export function resolveRemoteProvider(modelId, providers) {
|
|
|
48
52
|
}
|
|
49
53
|
return providers.get(modelId);
|
|
50
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* The provider the app selected to serve `modelId` (`PUT /atomic/v1/server/selection`), when this
|
|
57
|
+
* core can route to it: a registered remote provider, or a local engine. The id is matched with the
|
|
58
|
+
* proxy's `.`/`_` rule. `undefined` — no selection, or one naming a provider this core does not know
|
|
59
|
+
* (an unregistered cloud provider, Apple Foundation Models) — leaves the id to the rules without one.
|
|
60
|
+
* A selected remote provider is strict. A selected local engine means "local": the caller asks that
|
|
61
|
+
* engine first, then any other local session of the id (the app and the core may name the engine
|
|
62
|
+
* differently), and refuses the request rather than send it to a remote provider that lists it.
|
|
63
|
+
*/
|
|
64
|
+
export function resolveSelectedRoute(modelId, selection, providers) {
|
|
65
|
+
let selected = selection.get(modelId);
|
|
66
|
+
if (selected === undefined) {
|
|
67
|
+
for (const [id, provider] of selection) {
|
|
68
|
+
if (modelIdsMatch(id, modelId)) {
|
|
69
|
+
selected = provider;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (selected === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
const remote = providers.get(selected);
|
|
77
|
+
if (remote)
|
|
78
|
+
return { kind: 'remote', provider: remote };
|
|
79
|
+
const local = LOCAL_SEARCH_ORDER.find((provider) => provider === selected);
|
|
80
|
+
return local === undefined ? undefined : { kind: 'local', provider: local };
|
|
81
|
+
}
|
|
51
82
|
/**
|
|
52
83
|
* The proxy's model-id comparison: `.` and `_` are the same character, because clients and
|
|
53
84
|
* filesystems substitute one for the other (`Qwen3_5-9B` is `Qwen3.5-9B`). Nothing else is folded.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/router/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/router/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA4BH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6B;IAC1D,UAAU;IACV,mBAAmB;IACnB,KAAK;IACL,cAAc;IACd,cAAc;IACd,MAAM;IACN,QAAQ;IACR,eAAe;IACf,WAAW;CACZ,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,SAA8C;IAE9C,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACxC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,MAAM,CAAA;IACpD,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAClC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QACvD,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAA;IAC/B,CAAC;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAMD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,SAAsC,EACtC,SAA8C;IAE9C,IAAI,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACrC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,EAAE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OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,IAAe,EACf,SAA8C;IAE9C,MAAM,KAAK,GAAG,CAAC,MAAsB,EAAE,EAAU,EAAW,EAAE,CAC5D,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,KAAK,CAAA;IACvF,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAClC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QACpD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;QACrC,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;YAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;IACnF,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE;QACrC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;YAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IAClF,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -33,6 +33,8 @@ export interface HostExecOptions {
|
|
|
33
33
|
terminateGraceMs?: number;
|
|
34
34
|
/** Tests only: stands in for `child_process.spawn`. */
|
|
35
35
|
spawnProcess?: typeof spawn;
|
|
36
|
+
/** Tests only: whose rules for environment names apply (case-insensitive on `win32`). */
|
|
37
|
+
platform?: NodeJS.Platform;
|
|
36
38
|
}
|
|
37
39
|
export type HostExec = (command: string, args: string[], env?: Record<string, string | undefined>) => Promise<CommandOutput>;
|
|
38
40
|
export declare function hostExec(options?: HostExecOptions): HostExec;
|
|
@@ -31,13 +31,22 @@ const KILL_SETTLE_MS = 5_000;
|
|
|
31
31
|
* strips it, and every other key of `base` passes through untouched. This is the "merge, not
|
|
32
32
|
* replace" semantics `LinuxProbeDeps.exec`'s own `env` parameter documents (round 2, item 10): a
|
|
33
33
|
* caller stripping `DOCKER_HOST` for one call must not also lose `PATH` for it.
|
|
34
|
+
*
|
|
35
|
+
* On Windows a name means the same in any case, so an overlaid key replaces or strips the base's
|
|
36
|
+
* key in every case. Otherwise `spawn` would get both, and Node passes on only the first of them in
|
|
37
|
+
* sorted order — `PSMODULEPATH` before `PSModulePath`, the inherited one over the caller's.
|
|
34
38
|
*/
|
|
35
|
-
function overlayEnv(base, overlay) {
|
|
39
|
+
function overlayEnv(base, overlay, windows) {
|
|
36
40
|
const merged = { ...base };
|
|
37
41
|
for (const [key, value] of Object.entries(overlay)) {
|
|
38
|
-
if (
|
|
39
|
-
|
|
42
|
+
if (windows) {
|
|
43
|
+
for (const name of Object.keys(merged))
|
|
44
|
+
if (name.toUpperCase() === key.toUpperCase())
|
|
45
|
+
delete merged[name];
|
|
46
|
+
}
|
|
40
47
|
else
|
|
48
|
+
delete merged[key];
|
|
49
|
+
if (value !== undefined)
|
|
41
50
|
merged[key] = value;
|
|
42
51
|
}
|
|
43
52
|
return merged;
|
|
@@ -95,7 +104,9 @@ export function hostExec(options = {}) {
|
|
|
95
104
|
};
|
|
96
105
|
// No overlay for this call and no configured base: `spawn` gets no `env` key at all, which is
|
|
97
106
|
// how Node inherits `process.env` on its own — the same as before this parameter existed.
|
|
98
|
-
const spawnEnv = envOverlay === undefined
|
|
107
|
+
const spawnEnv = envOverlay === undefined
|
|
108
|
+
? options.env
|
|
109
|
+
: overlayEnv(options.env ?? process.env, envOverlay, (options.platform ?? process.platform) === 'win32');
|
|
99
110
|
try {
|
|
100
111
|
child = (options.spawnProcess ?? spawn)(command, args, {
|
|
101
112
|
shell: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-exec.js","sourceRoot":"","sources":["../../../src/runtime/environment/host-exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"host-exec.js","sourceRoot":"","sources":["../../../src/runtime/environment/host-exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAsB1C,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,wBAAwB,GAAG,IAAI,GAAG,IAAI,CAAA;AAC5C;;;GAGG;AACH,MAAM,cAAc,GAAG,KAAK,CAAA;AAC5B,4FAA4F;AAC5F,MAAM,cAAc,GAAG,KAAK,CAAA;AAQ5B;;;;;;;;;GASG;AACH,SAAS,UAAU,CACjB,IAAuB,EACvB,OAA2C,EAC3C,OAAgB;IAEhB,MAAM,MAAM,GAAsB,EAAE,GAAG,IAAI,EAAE,CAAA;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;gBACpC,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE;oBAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;QACrE,CAAC;;YAAM,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IAC9C,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OAAO,EAAE,CAAC,CAAC,CAAA;QACvF,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;YACpB,IAAI,QAAQ;gBAAE,UAAU,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,KAAK,EAAE,CAAA;QAClE,CAAC,CAAC,CAAA;QACF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,QAAQ,EAAE,CAAC;gBACb,cAAc,EAAE,CAAA;gBAChB,OAAM;YACR,CAAC;YACD,MAAM,CAAC;gBACL,IAAI;gBACJ,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAC9C,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;aAC/C,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteRT-LM's one accelerator, `openvino` (openspec change `add-litert-lm-runtime`, task 6.4, design
|
|
3
|
+
* D3): the Intel libraries an NPU variant needs on Windows, from the `openvino` wheel the active
|
|
4
|
+
* release pins in conf's manifest. Offered only on a machine whose Intel NPU generation LiteRT-LM has
|
|
5
|
+
* files for; prepared only when a client orders it — one prepare at a time, each step published as
|
|
6
|
+
* `litert-lm:accelerators`.
|
|
7
|
+
*
|
|
8
|
+
* A prepare downloads the wheel with its sha256 and size checked, keeps only `openvino/libs/**` and
|
|
9
|
+
* puts it at `<data>/litert-lm/accelerators/openvino/<version>/`, marked last: a folder without the
|
|
10
|
+
* marker is not prepared. A second prepare of the same version downloads nothing.
|
|
11
|
+
*/
|
|
12
|
+
import type { CoreEvents, LiteRtLmAccelerators, LiteRtLmNpu, LiteRtLmPrepareRequest, LiteRtLmPrepareResult, ProxyConfig } from '../../contracts/index.js';
|
|
13
|
+
import type { LiteRtLmRelease } from '../../engine-builds/manifest.js';
|
|
14
|
+
export declare const OPENVINO = "openvino";
|
|
15
|
+
export interface LiteRtLmAcceleratorDeps {
|
|
16
|
+
/** `<data>/litert-lm/accelerators`. */
|
|
17
|
+
acceleratorsDir: string;
|
|
18
|
+
/** `<data>/litert-lm/tmp`: the download and the unpacked wheel, gone after. */
|
|
19
|
+
tmpDir: string;
|
|
20
|
+
resolveBuild: () => Promise<{
|
|
21
|
+
dir: string;
|
|
22
|
+
version: string;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
/** The manifest's release of a LiteRT-LM version (a cached manifest is fine); `null` when unknown. */
|
|
25
|
+
release: (version: string) => Promise<LiteRtLmRelease | null>;
|
|
26
|
+
/** This machine's Intel NPU generation LiteRT-LM files target, or `null`. */
|
|
27
|
+
npuGeneration: () => Promise<LiteRtLmNpu | null>;
|
|
28
|
+
/** Download one file with its sha256 and size checked; `onFraction` 0…1 as it goes. */
|
|
29
|
+
download: (taskId: string, item: {
|
|
30
|
+
url: string;
|
|
31
|
+
save_path: string;
|
|
32
|
+
sha256: string;
|
|
33
|
+
size: number;
|
|
34
|
+
proxy?: ProxyConfig | null;
|
|
35
|
+
}, onFraction: (fraction: number) => void) => Promise<void>;
|
|
36
|
+
emit: (name: 'litert-lm:accelerators', payload: CoreEvents['litert-lm:accelerators']) => void;
|
|
37
|
+
now?: () => number;
|
|
38
|
+
}
|
|
39
|
+
export declare class LiteRtLmAcceleratorService {
|
|
40
|
+
private readonly deps;
|
|
41
|
+
private preparing;
|
|
42
|
+
/** The reason the last failed prepare of each version gave. */
|
|
43
|
+
private readonly failures;
|
|
44
|
+
private readonly now;
|
|
45
|
+
constructor(deps: LiteRtLmAcceleratorDeps);
|
|
46
|
+
private dirOf;
|
|
47
|
+
/** What this machine is offered: OpenVINO of the active release, on an Intel NPU it targets. */
|
|
48
|
+
private offered;
|
|
49
|
+
list(): Promise<LiteRtLmAccelerators>;
|
|
50
|
+
/** The prepared OpenVINO libraries of the active release: what an NPU load passes the host. */
|
|
51
|
+
libsDir(): Promise<string | undefined>;
|
|
52
|
+
prepare(request: LiteRtLmPrepareRequest): Promise<LiteRtLmPrepareResult>;
|
|
53
|
+
private prepareOpenVino;
|
|
54
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteRT-LM's one accelerator, `openvino` (openspec change `add-litert-lm-runtime`, task 6.4, design
|
|
3
|
+
* D3): the Intel libraries an NPU variant needs on Windows, from the `openvino` wheel the active
|
|
4
|
+
* release pins in conf's manifest. Offered only on a machine whose Intel NPU generation LiteRT-LM has
|
|
5
|
+
* files for; prepared only when a client orders it — one prepare at a time, each step published as
|
|
6
|
+
* `litert-lm:accelerators`.
|
|
7
|
+
*
|
|
8
|
+
* A prepare downloads the wheel with its sha256 and size checked, keeps only `openvino/libs/**` and
|
|
9
|
+
* puts it at `<data>/litert-lm/accelerators/openvino/<version>/`, marked last: a folder without the
|
|
10
|
+
* marker is not prepared. A second prepare of the same version downloads nothing.
|
|
11
|
+
*/
|
|
12
|
+
import { mkdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { AtomicCoreError } from '../../contracts/index.js';
|
|
15
|
+
import { OWNER_MARKER } from '../../diffusion/install.js';
|
|
16
|
+
import { extractArchive } from '../../downloads/index.js';
|
|
17
|
+
export const OPENVINO = 'openvino';
|
|
18
|
+
const exists = (path) => stat(path).then(() => true, () => false);
|
|
19
|
+
export class LiteRtLmAcceleratorService {
|
|
20
|
+
deps;
|
|
21
|
+
preparing = false;
|
|
22
|
+
/** The reason the last failed prepare of each version gave. */
|
|
23
|
+
failures = new Map();
|
|
24
|
+
now;
|
|
25
|
+
constructor(deps) {
|
|
26
|
+
this.deps = deps;
|
|
27
|
+
this.now = deps.now ?? Date.now;
|
|
28
|
+
}
|
|
29
|
+
dirOf(version) {
|
|
30
|
+
return join(this.deps.acceleratorsDir, OPENVINO, version);
|
|
31
|
+
}
|
|
32
|
+
/** What this machine is offered: OpenVINO of the active release, on an Intel NPU it targets. */
|
|
33
|
+
async offered() {
|
|
34
|
+
const build = await this.deps.resolveBuild();
|
|
35
|
+
if (!build)
|
|
36
|
+
return {
|
|
37
|
+
answer: { installed: false, build: null, npu: null, accelerators: [], error: null },
|
|
38
|
+
accelerator: null,
|
|
39
|
+
};
|
|
40
|
+
const name = `${build.version}/${build.dir.split(/[\\/]/).at(-1) ?? ''}`;
|
|
41
|
+
const npu = await this.deps.npuGeneration();
|
|
42
|
+
if (!npu)
|
|
43
|
+
return {
|
|
44
|
+
answer: { installed: true, build: name, npu: null, accelerators: [], error: null },
|
|
45
|
+
accelerator: null,
|
|
46
|
+
};
|
|
47
|
+
const release = await this.deps.release(build.version);
|
|
48
|
+
const accelerator = release?.accelerators.find((candidate) => candidate.id === OPENVINO) ?? null;
|
|
49
|
+
if (!accelerator)
|
|
50
|
+
return {
|
|
51
|
+
answer: {
|
|
52
|
+
installed: true,
|
|
53
|
+
build: name,
|
|
54
|
+
npu,
|
|
55
|
+
accelerators: [],
|
|
56
|
+
error: release
|
|
57
|
+
? `LiteRT-LM ${build.version} pins no OpenVINO.`
|
|
58
|
+
: `The LiteRT-LM manifest has no release ${build.version}; it lists the accelerator.`,
|
|
59
|
+
},
|
|
60
|
+
accelerator: null,
|
|
61
|
+
};
|
|
62
|
+
const failure = this.failures.get(accelerator.version);
|
|
63
|
+
return {
|
|
64
|
+
answer: {
|
|
65
|
+
installed: true,
|
|
66
|
+
build: name,
|
|
67
|
+
npu,
|
|
68
|
+
accelerators: [
|
|
69
|
+
{
|
|
70
|
+
name: OPENVINO,
|
|
71
|
+
device: 'npu',
|
|
72
|
+
version: accelerator.version,
|
|
73
|
+
size_bytes: accelerator.size,
|
|
74
|
+
prepared: await exists(join(this.dirOf(accelerator.version), OWNER_MARKER)),
|
|
75
|
+
...(failure ? { reason: failure } : {}),
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
error: null,
|
|
79
|
+
},
|
|
80
|
+
accelerator,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async list() {
|
|
84
|
+
return (await this.offered()).answer;
|
|
85
|
+
}
|
|
86
|
+
/** The prepared OpenVINO libraries of the active release: what an NPU load passes the host. */
|
|
87
|
+
async libsDir() {
|
|
88
|
+
const { accelerator } = await this.offered();
|
|
89
|
+
if (!accelerator)
|
|
90
|
+
return undefined;
|
|
91
|
+
const dir = this.dirOf(accelerator.version);
|
|
92
|
+
return (await exists(join(dir, OWNER_MARKER))) ? dir : undefined;
|
|
93
|
+
}
|
|
94
|
+
async prepare(request) {
|
|
95
|
+
if (this.preparing)
|
|
96
|
+
throw new AtomicCoreError('ENGINE_INSTALL_IN_PROGRESS', 'The LiteRT-LM accelerator is already being prepared; wait for that to finish.');
|
|
97
|
+
this.preparing = true;
|
|
98
|
+
try {
|
|
99
|
+
const { answer, accelerator } = await this.offered();
|
|
100
|
+
const wanted = request.accelerators && request.accelerators.length > 0 ? request.accelerators : [OPENVINO];
|
|
101
|
+
const summary = [];
|
|
102
|
+
for (const name of wanted) {
|
|
103
|
+
if (name !== OPENVINO) {
|
|
104
|
+
summary.push({ name, prepared: false, reason: `LiteRT-LM has no ${name} accelerator.` });
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (!accelerator) {
|
|
108
|
+
summary.push({
|
|
109
|
+
name,
|
|
110
|
+
prepared: false,
|
|
111
|
+
reason: answer.error ?? 'This computer has no Intel NPU LiteRT-LM has models for.',
|
|
112
|
+
});
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
summary.push(await this.prepareOpenVino(accelerator, request.proxy ?? null));
|
|
116
|
+
}
|
|
117
|
+
return { accelerators: summary };
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
this.preparing = false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async prepareOpenVino(accelerator, proxy) {
|
|
124
|
+
const emit = (stage, fraction, reason) => this.deps.emit('litert-lm:accelerators', {
|
|
125
|
+
accelerator: OPENVINO,
|
|
126
|
+
stage,
|
|
127
|
+
fraction,
|
|
128
|
+
...(reason !== undefined ? { reason } : {}),
|
|
129
|
+
});
|
|
130
|
+
const target = this.dirOf(accelerator.version);
|
|
131
|
+
if (await exists(join(target, OWNER_MARKER))) {
|
|
132
|
+
emit('done', 1);
|
|
133
|
+
return { name: OPENVINO, prepared: true };
|
|
134
|
+
}
|
|
135
|
+
const stamp = this.now();
|
|
136
|
+
const work = join(this.deps.tmpDir, `openvino-${accelerator.version}-${stamp}`);
|
|
137
|
+
const staging = `${target}.incoming-${stamp}`;
|
|
138
|
+
try {
|
|
139
|
+
emit('started', 0);
|
|
140
|
+
await mkdir(work, { recursive: true });
|
|
141
|
+
const wheel = join(work, accelerator.name);
|
|
142
|
+
await this.deps.download(`litert-lm-${OPENVINO}-${accelerator.version}`, {
|
|
143
|
+
url: accelerator.url,
|
|
144
|
+
save_path: wheel,
|
|
145
|
+
sha256: accelerator.sha256,
|
|
146
|
+
size: accelerator.size,
|
|
147
|
+
...(proxy ? { proxy } : {}),
|
|
148
|
+
}, (fraction) => emit('downloading', fraction));
|
|
149
|
+
const unpacked = join(work, 'unpacked');
|
|
150
|
+
await extractArchive(wheel, unpacked);
|
|
151
|
+
const libs = join(unpacked, 'openvino', 'libs');
|
|
152
|
+
if (!(await exists(libs)))
|
|
153
|
+
throw new Error('the OpenVINO wheel has no openvino/libs');
|
|
154
|
+
await rm(staging, { recursive: true, force: true });
|
|
155
|
+
await mkdir(join(staging, '..'), { recursive: true });
|
|
156
|
+
await rename(libs, staging);
|
|
157
|
+
await writeFile(join(staging, OWNER_MARKER), 'atomic-chat\n');
|
|
158
|
+
await rm(target, { recursive: true, force: true });
|
|
159
|
+
await rename(staging, target);
|
|
160
|
+
this.failures.delete(accelerator.version);
|
|
161
|
+
emit('done', 1);
|
|
162
|
+
return { name: OPENVINO, prepared: true };
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
166
|
+
this.failures.set(accelerator.version, reason);
|
|
167
|
+
await rm(staging, { recursive: true, force: true }).catch(() => { });
|
|
168
|
+
emit('failed', null, reason);
|
|
169
|
+
return { name: OPENVINO, prepared: false, reason };
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
await rm(work, { recursive: true, force: true }).catch(() => { });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=accelerators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accelerators.js","sourceRoot":"","sources":["../../../src/runtime/litert-lm/accelerators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAS1D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAMzD,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAA;AAsBlC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAoB,EAAE,CAChD,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CACb,GAAG,EAAE,CAAC,IAAI,EACV,GAAG,EAAE,CAAC,KAAK,CACZ,CAAA;AAEH,MAAM,OAAO,0BAA0B;IAMR;IALrB,SAAS,GAAG,KAAK,CAAA;IACzB,+DAA+D;IAC9C,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IACpC,GAAG,CAAc;IAElC,YAA6B,IAA6B;QAA7B,SAAI,GAAJ,IAAI,CAAyB;QACxD,IAAI,CAAC,GAAG,GAA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MAAM,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YACzC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;YACf,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACrE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YAC9C,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YACnE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;YAC5B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;QACpD,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `POST /models/litert-lm/check` (openspec change `add-litert-lm-runtime`, task 6.5): whether a
|
|
3
|
+
* variant would run here. Before a download, from what core already knows — the platform, this
|
|
4
|
+
* machine's Intel NPU generation, the active build, whether OpenVINO is prepared — never the network.
|
|
5
|
+
* For a file on disk, also from the file itself (`litert-host inspect`), whose facts come back in the
|
|
6
|
+
* answer for the client to write into `model.yml`.
|
|
7
|
+
*/
|
|
8
|
+
import type { LiteRtLmCheckRequest, LiteRtLmCheckResult, LiteRtLmFileMetadata, LiteRtLmNpu } from '../../contracts/index.js';
|
|
9
|
+
import type { LiteRtLmPlatform } from '../../engine-builds/manifest.js';
|
|
10
|
+
import type { ModelRegistry } from '../../models/index.js';
|
|
11
|
+
export interface LiteRtLmCheckFacts {
|
|
12
|
+
platform: LiteRtLmPlatform;
|
|
13
|
+
build: {
|
|
14
|
+
dir: string;
|
|
15
|
+
version: string;
|
|
16
|
+
} | null;
|
|
17
|
+
npu: LiteRtLmNpu | null;
|
|
18
|
+
openVinoPrepared: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The verdict for a variant (`backend`, `npu`, `min_runtime_version`), and for a file its facts. */
|
|
21
|
+
export declare function liteRtLmVerdict(facts: LiteRtLmCheckFacts, request: Pick<LiteRtLmCheckRequest, 'backend' | 'npu' | 'min_runtime_version'>, file: LiteRtLmFileMetadata | null): LiteRtLmCheckResult;
|
|
22
|
+
/** The request body, strictly: a variant, a path with its backend, or a model id. */
|
|
23
|
+
export declare function parseLiteRtLmCheckRequest(body: unknown): LiteRtLmCheckRequest;
|
|
24
|
+
export interface LiteRtLmCheckDeps {
|
|
25
|
+
platform: LiteRtLmPlatform;
|
|
26
|
+
/** `<data>/litert-lm/models`: the only place a checked path may be. */
|
|
27
|
+
modelsDir: string;
|
|
28
|
+
registry: ModelRegistry;
|
|
29
|
+
resolveBuild: () => Promise<{
|
|
30
|
+
dir: string;
|
|
31
|
+
version: string;
|
|
32
|
+
} | undefined>;
|
|
33
|
+
npuGeneration: () => Promise<LiteRtLmNpu | null>;
|
|
34
|
+
openVinoLibs: () => Promise<string | undefined>;
|
|
35
|
+
/** The runtime's cached `inspect` (by path, mtime and build). */
|
|
36
|
+
inspect: (buildDir: string, file: string) => Promise<LiteRtLmFileMetadata>;
|
|
37
|
+
}
|
|
38
|
+
export declare class LiteRtLmCheckService {
|
|
39
|
+
private readonly deps;
|
|
40
|
+
constructor(deps: LiteRtLmCheckDeps);
|
|
41
|
+
/** A path inside the models root, links resolved, or `INVALID_ARGUMENT`. */
|
|
42
|
+
private inRoot;
|
|
43
|
+
check(request: LiteRtLmCheckRequest): Promise<LiteRtLmCheckResult>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `POST /models/litert-lm/check` (openspec change `add-litert-lm-runtime`, task 6.5): whether a
|
|
3
|
+
* variant would run here. Before a download, from what core already knows — the platform, this
|
|
4
|
+
* machine's Intel NPU generation, the active build, whether OpenVINO is prepared — never the network.
|
|
5
|
+
* For a file on disk, also from the file itself (`litert-host inspect`), whose facts come back in the
|
|
6
|
+
* answer for the client to write into `model.yml`.
|
|
7
|
+
*/
|
|
8
|
+
import { realpath } from 'node:fs/promises';
|
|
9
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
10
|
+
import { AtomicCoreError, LITERT_LM_BACKENDS, LITERT_LM_NPUS } from '../../contracts/index.js';
|
|
11
|
+
import { compareVersions } from '../../backend/index.js';
|
|
12
|
+
import { readLiteRtLmBlock } from './model-yml.js';
|
|
13
|
+
import { backendRunsOn } from './runtime.js';
|
|
14
|
+
const verdict = (v, reason, metadata) => ({ verdict: v, reason, ...(metadata ? { metadata } : {}) });
|
|
15
|
+
/** The verdict for a variant (`backend`, `npu`, `min_runtime_version`), and for a file its facts. */
|
|
16
|
+
export function liteRtLmVerdict(facts, request, file) {
|
|
17
|
+
const backend = request.backend ?? '';
|
|
18
|
+
if (!LITERT_LM_BACKENDS.some((known) => known === backend))
|
|
19
|
+
return verdict('platform-unsupported', `This core runs no LiteRT-LM variant on the "${backend}" backend.`, file);
|
|
20
|
+
if (!backendRunsOn(facts.platform, backend))
|
|
21
|
+
return verdict('platform-unsupported', `LiteRT-LM runs ${backend.toUpperCase()} variants on Windows x64 only.`, file);
|
|
22
|
+
if (backend === 'npu') {
|
|
23
|
+
if (!LITERT_LM_NPUS.some((known) => known === request.npu))
|
|
24
|
+
return verdict('platform-unsupported', `This core runs no LiteRT-LM variant for the "${request.npu ?? ''}" NPU.`, file);
|
|
25
|
+
if (facts.npu === null)
|
|
26
|
+
return verdict('accelerator-unavailable', 'This computer has no Intel NPU LiteRT-LM has models for.', file);
|
|
27
|
+
if (facts.npu !== request.npu)
|
|
28
|
+
return verdict('accelerator-unavailable', `This variant is built for the ${request.npu} NPU; this computer has ${facts.npu}.`, file);
|
|
29
|
+
}
|
|
30
|
+
if (!facts.build)
|
|
31
|
+
return verdict('engine-not-installed', 'LiteRT-LM is not installed on this computer.', file);
|
|
32
|
+
if (file && !file.backends.includes(backend))
|
|
33
|
+
return verdict('platform-unsupported', `This file runs on ${file.backends.join(', ') || 'no backend'}, not ${backend}.`, file);
|
|
34
|
+
const needs = file?.min_runtime_version ?? request.min_runtime_version ?? null;
|
|
35
|
+
if (needs && compareVersions(needs, facts.build.version) > 0)
|
|
36
|
+
return verdict('requires-newer-engine', `This model needs LiteRT-LM ${needs}; the installed one is ${facts.build.version}.`, file);
|
|
37
|
+
if (backend === 'npu' && !facts.openVinoPrepared)
|
|
38
|
+
return verdict('accelerator-not-prepared', 'OpenVINO is not prepared yet; prepare it on the LiteRT-LM page.', file);
|
|
39
|
+
return verdict('ok', null, file);
|
|
40
|
+
}
|
|
41
|
+
const VERSION_RE = /^\d+\.\d+(\.\d+)?$/;
|
|
42
|
+
const FIELDS = ['backend', 'npu', 'min_runtime_version', 'path', 'model_id'];
|
|
43
|
+
/** The request body, strictly: a variant, a path with its backend, or a model id. */
|
|
44
|
+
export function parseLiteRtLmCheckRequest(body) {
|
|
45
|
+
const invalid = (why) => {
|
|
46
|
+
throw new AtomicCoreError('INVALID_ARGUMENT', why);
|
|
47
|
+
};
|
|
48
|
+
if (typeof body !== 'object' || body === null || Array.isArray(body))
|
|
49
|
+
return invalid('The request body must be a JSON object.');
|
|
50
|
+
const record = body;
|
|
51
|
+
const extra = Object.keys(record).filter((key) => !FIELDS.some((field) => field === key));
|
|
52
|
+
if (extra.length > 0)
|
|
53
|
+
invalid(`The request has fields this core does not know: ${extra.sort().join(', ')}.`);
|
|
54
|
+
const out = {};
|
|
55
|
+
for (const key of FIELDS) {
|
|
56
|
+
const value = record[key];
|
|
57
|
+
if (value === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
if (typeof value !== 'string' || value === '')
|
|
60
|
+
invalid(`${key} must be text.`);
|
|
61
|
+
out[key] = value;
|
|
62
|
+
}
|
|
63
|
+
if (out.min_runtime_version !== undefined && !VERSION_RE.test(out.min_runtime_version))
|
|
64
|
+
invalid('min_runtime_version must be X.Y or X.Y.Z.');
|
|
65
|
+
if (out.model_id !== undefined) {
|
|
66
|
+
if (Object.keys(out).length > 1)
|
|
67
|
+
invalid('model_id is checked alone: its variant comes from model.yml.');
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
if (out.backend === undefined)
|
|
71
|
+
invalid('backend is required for a variant or a file.');
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
export class LiteRtLmCheckService {
|
|
75
|
+
deps;
|
|
76
|
+
constructor(deps) {
|
|
77
|
+
this.deps = deps;
|
|
78
|
+
}
|
|
79
|
+
/** A path inside the models root, links resolved, or `INVALID_ARGUMENT`. */
|
|
80
|
+
async inRoot(path) {
|
|
81
|
+
const refuse = () => new AtomicCoreError('INVALID_ARGUMENT', 'path must be a file inside the LiteRT-LM models folder.');
|
|
82
|
+
if (!isAbsolute(path))
|
|
83
|
+
throw new AtomicCoreError('INVALID_ARGUMENT', 'path must be absolute.');
|
|
84
|
+
const root = await realpath(this.deps.modelsDir).catch(() => resolve(this.deps.modelsDir));
|
|
85
|
+
// A file that is not there yet is judged by its spelling; one that is, by where its links lead.
|
|
86
|
+
const full = await realpath(path).catch(() => resolve(path));
|
|
87
|
+
const rel = relative(root, full);
|
|
88
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel))
|
|
89
|
+
throw refuse();
|
|
90
|
+
return resolve(path);
|
|
91
|
+
}
|
|
92
|
+
async check(request) {
|
|
93
|
+
let variant = request;
|
|
94
|
+
let file = request.path !== undefined ? await this.inRoot(request.path) : null;
|
|
95
|
+
if (request.model_id !== undefined) {
|
|
96
|
+
const yml = await this.deps.registry.read(request.model_id);
|
|
97
|
+
const block = readLiteRtLmBlock(yml);
|
|
98
|
+
variant = { backend: block.backend, ...(block.npu ? { npu: block.npu } : {}) };
|
|
99
|
+
// The registry's own path: an installed model may be a link, which the runtime loads as it is.
|
|
100
|
+
file = this.deps.registry.resolvePaths(yml).modelPath;
|
|
101
|
+
}
|
|
102
|
+
const build = (await this.deps.resolveBuild()) ?? null;
|
|
103
|
+
const facts = {
|
|
104
|
+
platform: this.deps.platform,
|
|
105
|
+
build,
|
|
106
|
+
npu: await this.deps.npuGeneration(),
|
|
107
|
+
openVinoPrepared: (await this.deps.openVinoLibs()) !== undefined,
|
|
108
|
+
};
|
|
109
|
+
const metadata = file && build ? await this.deps.inspect(build.dir, file) : null;
|
|
110
|
+
return liteRtLmVerdict(facts, variant, metadata);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/runtime/litert-lm/check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAS9F,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE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