dsh-plugin-local-infer 0.1.2 → 0.1.3

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.
Files changed (100) hide show
  1. package/README.md +10 -2
  2. package/docs/zh/README.md +10 -2
  3. package/dsh/client.js +669 -191
  4. package/package.json +6 -1
  5. package/packages/core/lib/adapter.d.ts +44 -2
  6. package/packages/core/lib/deps.d.ts +4 -3
  7. package/packages/core/lib/index.d.ts +1 -1
  8. package/packages/core/lib/registrar.d.ts +5 -5
  9. package/packages/core/lib/registrar.js +3 -3
  10. package/packages/core/package.json +1 -1
  11. package/packages/providers/lib/acquire.d.ts +5 -3
  12. package/packages/providers/lib/acquire.js +30 -9
  13. package/packages/providers/lib/adapters.d.ts +19 -209
  14. package/packages/providers/lib/adapters.js +13 -886
  15. package/packages/providers/lib/deps.d.ts +24 -2
  16. package/packages/providers/lib/deps.js +23 -4
  17. package/packages/providers/lib/engines/hyperqwenAdapter.d.ts +38 -0
  18. package/packages/providers/lib/engines/hyperqwenAdapter.js +105 -0
  19. package/packages/providers/lib/{infernix.js → engines/infernix.js} +1 -1
  20. package/packages/providers/lib/engines/infernixAdapter.d.ts +53 -0
  21. package/packages/providers/lib/engines/infernixAdapter.js +202 -0
  22. package/packages/providers/lib/engines/llamacppAdapter.d.ts +51 -0
  23. package/packages/providers/lib/engines/llamacppAdapter.js +232 -0
  24. package/packages/providers/lib/{ninfer.js → engines/ninfer.js} +1 -1
  25. package/packages/providers/lib/engines/ninferAdapter.d.ts +82 -0
  26. package/packages/providers/lib/engines/ninferAdapter.js +324 -0
  27. package/packages/providers/lib/engines/strata.d.ts +53 -0
  28. package/packages/providers/lib/engines/strata.js +197 -0
  29. package/packages/providers/lib/engines/strataAdapter.d.ts +98 -0
  30. package/packages/providers/lib/engines/strataAdapter.js +427 -0
  31. package/packages/providers/lib/engines.d.ts +5 -4
  32. package/packages/providers/lib/engines.js +10 -10
  33. package/packages/providers/lib/guidelines.js +1 -1
  34. package/packages/providers/lib/index.d.ts +14 -9
  35. package/packages/providers/lib/index.js +17 -7
  36. package/packages/providers/lib/model-defaults.d.ts +5 -4
  37. package/packages/providers/lib/model-defaults.js +22 -4
  38. package/packages/providers/lib/platform.js +7 -1
  39. package/packages/providers/package.json +1 -1
  40. package/packages/service/lib/index.d.ts +13 -4
  41. package/packages/service/lib/index.js +79 -5
  42. package/packages/service/lib/types.d.ts +5 -4
  43. package/packages/service/package.json +1 -1
  44. package/packages/tool/package.json +1 -1
  45. package/packages/ui/lib/config.d.ts +79 -0
  46. package/packages/ui/lib/config.js +235 -0
  47. package/packages/ui/lib/deps.d.ts +3 -3
  48. package/packages/ui/lib/ops/engine.d.ts +108 -0
  49. package/packages/ui/lib/ops/engine.js +493 -0
  50. package/packages/ui/lib/ops/hf.d.ts +27 -0
  51. package/packages/ui/lib/ops/hf.js +60 -0
  52. package/packages/ui/lib/ops/logs.d.ts +23 -0
  53. package/packages/ui/lib/ops/logs.js +58 -0
  54. package/packages/ui/lib/ops/model.d.ts +79 -0
  55. package/packages/ui/lib/ops/model.js +130 -0
  56. package/packages/ui/lib/request.d.ts +106 -0
  57. package/packages/ui/lib/request.js +80 -0
  58. package/packages/ui/lib/route.d.ts +88 -420
  59. package/packages/ui/lib/route.js +111 -1843
  60. package/packages/ui/lib/routes/chat-template.d.ts +14 -0
  61. package/packages/ui/lib/routes/chat-template.js +37 -0
  62. package/packages/ui/lib/routes/deps.d.ts +16 -0
  63. package/packages/ui/lib/routes/deps.js +27 -0
  64. package/packages/ui/lib/routes/download.d.ts +16 -0
  65. package/packages/ui/lib/routes/download.js +48 -0
  66. package/packages/ui/lib/routes/get.d.ts +18 -0
  67. package/packages/ui/lib/routes/get.js +57 -0
  68. package/packages/ui/lib/routes/install.d.ts +16 -0
  69. package/packages/ui/lib/routes/install.js +36 -0
  70. package/packages/ui/lib/routes/launch.d.ts +18 -0
  71. package/packages/ui/lib/routes/launch.js +50 -0
  72. package/packages/ui/lib/routes/provider-delete.d.ts +15 -0
  73. package/packages/ui/lib/routes/provider-delete.js +37 -0
  74. package/packages/ui/lib/routes/register.d.ts +16 -0
  75. package/packages/ui/lib/routes/register.js +28 -0
  76. package/packages/ui/lib/routes/save.d.ts +18 -0
  77. package/packages/ui/lib/routes/save.js +139 -0
  78. package/packages/ui/lib/routes/stop.d.ts +16 -0
  79. package/packages/ui/lib/routes/stop.js +29 -0
  80. package/packages/ui/lib/routes/summary.d.ts +15 -0
  81. package/packages/ui/lib/routes/summary.js +26 -0
  82. package/packages/ui/lib/routes/unregister.d.ts +14 -0
  83. package/packages/ui/lib/routes/unregister.js +26 -0
  84. package/packages/ui/lib/viewmodels/deps.d.ts +31 -0
  85. package/packages/ui/lib/viewmodels/deps.js +89 -0
  86. package/packages/ui/lib/viewmodels/depsHelpers.d.ts +28 -0
  87. package/packages/ui/lib/viewmodels/depsHelpers.js +33 -0
  88. package/packages/ui/lib/viewmodels/summary.d.ts +140 -0
  89. package/packages/ui/lib/viewmodels/summary.js +225 -0
  90. package/packages/ui/lib/viewmodels/summaryHelpers.d.ts +30 -0
  91. package/packages/ui/lib/viewmodels/summaryHelpers.js +42 -0
  92. package/packages/ui/package.json +1 -1
  93. package/packages/providers/lib/strata.d.ts +0 -15
  94. package/packages/providers/lib/strata.js +0 -14
  95. /package/packages/providers/lib/{hyperqwen.d.ts → engines/hyperqwen.d.ts} +0 -0
  96. /package/packages/providers/lib/{hyperqwen.js → engines/hyperqwen.js} +0 -0
  97. /package/packages/providers/lib/{infernix.d.ts → engines/infernix.d.ts} +0 -0
  98. /package/packages/providers/lib/{llamacpp.d.ts → engines/llamacpp.d.ts} +0 -0
  99. /package/packages/providers/lib/{llamacpp.js → engines/llamacpp.js} +0 -0
  100. /package/packages/providers/lib/{ninfer.d.ts → engines/ninfer.d.ts} +0 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The POST /local-infer/stop route: it renders the same plan the launch
3
+ * rendered and runs the service's stop entry point, so the stop targets the
4
+ * exact container or process the launch started. The stop then clears the
5
+ * target entry's launch record, so a recycled pid cannot re-link an engine
6
+ * the user just stopped.
7
+ * @module dsh-plugin-local-infer/ui/routes/stop
8
+ */
9
+ import { stopEngine } from "../ops/engine.js";
10
+ import { defineRoute } from "../route.js";
11
+ import { launchRequestFromBody } from "../request.js";
12
+ /**
13
+ * stopRoute builds the POST /local-infer/stop route definition the register
14
+ * step holds by an effect.
15
+ */
16
+ export function stopRoute(localInfer) {
17
+ return defineRoute({
18
+ name: 'local-infer-stop',
19
+ path: '/local-infer/stop',
20
+ method: 'POST',
21
+ failStatus: 500,
22
+ tooLargeMessage: 'stop payload too large',
23
+ run: async ({ body }, res) => {
24
+ await stopEngine(localInfer, launchRequestFromBody(body));
25
+ res.json(200, { stopped: true });
26
+ },
27
+ });
28
+ }
29
+ //# sourceMappingURL=stop.js.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The GET /local-infer/summary route: the card's read model. The handler
3
+ * parses the engine and config query params (an absent engine or a broken
4
+ * config falls back to the stored config) and answers with the summary the
5
+ * card renders.
6
+ * @module dsh-plugin-local-infer/ui/routes/summary
7
+ */
8
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
9
+ import type { LocalInferRoute } from '../route.ts';
10
+ /**
11
+ * summaryRoute builds the GET /local-infer/summary route definition the
12
+ * register step holds by an effect.
13
+ */
14
+ export declare function summaryRoute(localInfer: LocalInferService): LocalInferRoute;
15
+ //# sourceMappingURL=summary.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The GET /local-infer/summary route: the card's read model. The handler
3
+ * parses the engine and config query params (an absent engine or a broken
4
+ * config falls back to the stored config) and answers with the summary the
5
+ * card renders.
6
+ * @module dsh-plugin-local-infer/ui/routes/summary
7
+ */
8
+ import { defineRoute } from "../route.js";
9
+ import { depsRequestFromUrl } from "../request.js";
10
+ import { buildSummary } from "../viewmodels/summary.js";
11
+ /**
12
+ * summaryRoute builds the GET /local-infer/summary route definition the
13
+ * register step holds by an effect.
14
+ */
15
+ export function summaryRoute(localInfer) {
16
+ return defineRoute({
17
+ name: 'local-infer-config',
18
+ path: '/local-infer/summary',
19
+ method: 'GET',
20
+ failStatus: 500,
21
+ run: async ({ url }, res) => {
22
+ res.json(200, await buildSummary(localInfer, depsRequestFromUrl(url)));
23
+ },
24
+ });
25
+ }
26
+ //# sourceMappingURL=summary.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The POST /local-infer/unregister route: it runs the service's removeModel
3
+ * entry point for the engine's provider and the model row the register step
4
+ * resolved, so the removal targets the exact entry the registration wrote.
5
+ * @module dsh-plugin-local-infer/ui/routes/unregister
6
+ */
7
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
8
+ import type { LocalInferRoute } from '../route.ts';
9
+ /**
10
+ * unregisterRoute builds the POST /local-infer/unregister route definition
11
+ * the register step holds by an effect.
12
+ */
13
+ export declare function unregisterRoute(localInfer: LocalInferService): LocalInferRoute;
14
+ //# sourceMappingURL=unregister.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The POST /local-infer/unregister route: it runs the service's removeModel
3
+ * entry point for the engine's provider and the model row the register step
4
+ * resolved, so the removal targets the exact entry the registration wrote.
5
+ * @module dsh-plugin-local-infer/ui/routes/unregister
6
+ */
7
+ import { unregisterFor } from "../ops/model.js";
8
+ import { defineRoute } from "../route.js";
9
+ import { registerRequestFromBody } from "../request.js";
10
+ /**
11
+ * unregisterRoute builds the POST /local-infer/unregister route definition
12
+ * the register step holds by an effect.
13
+ */
14
+ export function unregisterRoute(localInfer) {
15
+ return defineRoute({
16
+ name: 'local-infer-unregister',
17
+ path: '/local-infer/unregister',
18
+ method: 'POST',
19
+ failStatus: 500,
20
+ tooLargeMessage: 'unregister payload too large',
21
+ run: async ({ body }, res) => {
22
+ res.json(200, await unregisterFor(localInfer, registerRequestFromBody(body)));
23
+ },
24
+ });
25
+ }
26
+ //# sourceMappingURL=unregister.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The deps panel view model: the detected hardware (with its package
3
+ * manager), the dep plan the service resolves, the per-dep statuses, the
4
+ * copy/paste install string, and the Play/Run trust gate the stored config
5
+ * carries. resolveBuildMode picks the deploy mode the plan prices, the same
6
+ * value the docker-not-installed guideline reads, so the panel and the
7
+ * warning never disagree about the mode.
8
+ * @module dsh-plugin-local-infer/ui/viewmodels/deps
9
+ */
10
+ import type { Config } from 'dsh-plugin-local-infer/core';
11
+ import type { BuildMode } from '../../../core/lib/index.js';
12
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
13
+ import type { EngineInfo } from '../../../providers/lib/index.js';
14
+ import type { DepsModel } from '../deps.ts';
15
+ import type { DepsRequest } from '../request.ts';
16
+ /**
17
+ * resolveBuildMode picks the deploy mode the dep plan prices: the config's
18
+ * buildMode when the selected engine supports it, else the engine's default
19
+ * (local when the engine can build locally, docker when it cannot). The
20
+ * docker-not-installed guideline reads this same value, so the panel and the
21
+ * warning never disagree about the mode.
22
+ */
23
+ export declare function resolveBuildMode(engine: EngineInfo, config: Config): BuildMode;
24
+ /**
25
+ * buildDeps assembles the deps panel read model for one engine and config:
26
+ * the detected hardware (with its package manager), the dep plan the service
27
+ * resolves, the per-dep statuses, the copy/paste install string, and the
28
+ * Play/Run trust gate the stored config carries.
29
+ */
30
+ export declare function buildDeps(localInfer: LocalInferService, request?: DepsRequest): Promise<DepsModel>;
31
+ //# sourceMappingURL=deps.d.ts.map
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The deps panel view model: the detected hardware (with its package
3
+ * manager), the dep plan the service resolves, the per-dep statuses, the
4
+ * copy/paste install string, and the Play/Run trust gate the stored config
5
+ * carries. resolveBuildMode picks the deploy mode the plan prices, the same
6
+ * value the docker-not-installed guideline reads, so the panel and the
7
+ * warning never disagree about the mode.
8
+ * @module dsh-plugin-local-infer/ui/viewmodels/deps
9
+ */
10
+ import { existsSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import { CHAT_TEMPLATE_FILE, checkDeps, hfChatTemplateCommand, renderInstallString, } from '../../../core/lib/index.js';
13
+ import { ENGINES } from '../../../providers/lib/index.js';
14
+ import { readConfig } from "../config.js";
15
+ import { renderDeps } from "../deps.js";
16
+ import { isHfRepoReference } from "./summaryHelpers.js";
17
+ /**
18
+ * resolveBuildMode picks the deploy mode the dep plan prices: the config's
19
+ * buildMode when the selected engine supports it, else the engine's default
20
+ * (local when the engine can build locally, docker when it cannot). The
21
+ * docker-not-installed guideline reads this same value, so the panel and the
22
+ * warning never disagree about the mode.
23
+ */
24
+ export function resolveBuildMode(engine, config) {
25
+ // The default is the engine's easiest non-docker mode: the binary install
26
+ // when the engine ships one (the Strata one-line path), else the source
27
+ // build, else docker.
28
+ const defaultMode = engine.supports.binary === true
29
+ ? 'binary'
30
+ : engine.supports.local
31
+ ? 'local'
32
+ : 'docker';
33
+ const requested = typeof config.buildMode === 'string' ? config.buildMode : undefined;
34
+ if ((requested === 'docker' || requested === 'local' || requested === 'binary') &&
35
+ engine.supports[requested]) {
36
+ return requested;
37
+ }
38
+ return defaultMode;
39
+ }
40
+ /**
41
+ * buildDeps assembles the deps panel read model for one engine and config:
42
+ * the detected hardware (with its package manager), the dep plan the service
43
+ * resolves, the per-dep statuses, the copy/paste install string, and the
44
+ * Play/Run trust gate the stored config carries.
45
+ */
46
+ export async function buildDeps(localInfer, request) {
47
+ const stored = readConfig();
48
+ const engineId = request?.engine ?? stored.engine;
49
+ const config = request?.config ?? stored.config;
50
+ // ENGINES is a known non-empty constant, so the fallback is always defined.
51
+ const engine = ENGINES.find((entry) => entry.id === engineId) ?? ENGINES[0];
52
+ const buildMode = resolveBuildMode(engine, config);
53
+ const hardware = await localInfer.detectHardware();
54
+ const deps = await localInfer.deps(engine.id, buildMode, hardware);
55
+ const checks = await checkDeps(deps, hardware);
56
+ // The chat-template row: when a selected template is an HF repo reference
57
+ // and its file is not in the model directory, the System dependencies box
58
+ // shows the download command (the auto-download's fallback when the CLI is
59
+ // missing or the fetch failed). A present template, a local path, or no
60
+ // template leaves the row off.
61
+ const modelDirectory = localInfer.defaultModelDirectory();
62
+ const rawModelDir = config.modelDirectory;
63
+ const modelDir = typeof rawModelDir === 'string' && rawModelDir.trim() !== '' ? rawModelDir : modelDirectory;
64
+ const chatTemplateValue = typeof config.chatTemplate === 'string' ? config.chatTemplate : '';
65
+ let chatTemplate;
66
+ if (isHfRepoReference(chatTemplateValue) && !existsSync(join(modelDir, CHAT_TEMPLATE_FILE))) {
67
+ chatTemplate = {
68
+ repo: chatTemplateValue,
69
+ present: false,
70
+ hfCli: (await localInfer.hfCliAvailable()) !== null,
71
+ downloadCommand: hfChatTemplateCommand(chatTemplateValue, modelDir),
72
+ };
73
+ }
74
+ // exactOptionalPropertyTypes: the chat-template row only lands while a
75
+ // selected template is missing, so the key is included conditionally.
76
+ const depsInput = {
77
+ engineId: engine.id,
78
+ buildMode,
79
+ packageManager: hardware.packageManager ?? null,
80
+ checks,
81
+ installString: renderInstallString(deps, hardware),
82
+ runAllowed: stored.allowRunDeps,
83
+ };
84
+ if (chatTemplate !== undefined) {
85
+ depsInput.chatTemplate = chatTemplate;
86
+ }
87
+ return renderDeps(depsInput);
88
+ }
89
+ //# sourceMappingURL=deps.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The Play/Run helper for the deps panel: runInstallFor refuses with a 409
3
+ * while the trust gate is off (the copy/paste path is always the fallback),
4
+ * runs the install through the service, and refreshes the deps model from the
5
+ * re-check, so the "Get" gate opens only after a re-check passes.
6
+ * @module dsh-plugin-local-infer/ui/viewmodels/depsHelpers
7
+ */
8
+ import type { InstallResult } from 'dsh-plugin-local-infer/core';
9
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
10
+ import type { DepsModel } from '../deps.ts';
11
+ import type { DepsRequest } from '../request.ts';
12
+ /**
13
+ * InstallResponse is the answer to a Play/Run: the install result and the
14
+ * refreshed deps model, so the card re-renders the gate from the same
15
+ * re-check the install ran.
16
+ */
17
+ export interface InstallResponse {
18
+ result: InstallResult;
19
+ deps: DepsModel;
20
+ }
21
+ /**
22
+ * runInstallFor is the Play/Run path: it refuses with a 409 while the
23
+ * trust gate is off (the copy/paste path is always the fallback), runs the
24
+ * install through the service, and refreshes the deps model from the
25
+ * re-check, so the "Get" gate opens only after a re-check passes.
26
+ */
27
+ export declare function runInstallFor(localInfer: LocalInferService, request: DepsRequest): Promise<InstallResponse>;
28
+ //# sourceMappingURL=depsHelpers.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The Play/Run helper for the deps panel: runInstallFor refuses with a 409
3
+ * while the trust gate is off (the copy/paste path is always the fallback),
4
+ * runs the install through the service, and refreshes the deps model from the
5
+ * re-check, so the "Get" gate opens only after a re-check passes.
6
+ * @module dsh-plugin-local-infer/ui/viewmodels/depsHelpers
7
+ */
8
+ import { readConfig } from "../config.js";
9
+ import { RouteError } from "../route.js";
10
+ import { buildDeps } from "./deps.js";
11
+ /**
12
+ * runInstallFor is the Play/Run path: it refuses with a 409 while the
13
+ * trust gate is off (the copy/paste path is always the fallback), runs the
14
+ * install through the service, and refreshes the deps model from the
15
+ * re-check, so the "Get" gate opens only after a re-check passes.
16
+ */
17
+ export async function runInstallFor(localInfer, request) {
18
+ if (readConfig().allowRunDeps !== true) {
19
+ throw new RouteError(409, 'one-click install is not allowed; copy the install string instead');
20
+ }
21
+ const model = await buildDeps(localInfer, request);
22
+ const hardware = await localInfer.detectHardware();
23
+ const result = await localInfer.runInstall(model.engineId, model.buildMode, hardware);
24
+ const deps = model.deps.map((dep) => {
25
+ const entry = result.results.find((entry) => entry.id === dep.id);
26
+ return entry === undefined ? dep : { ...dep, status: entry.status };
27
+ });
28
+ return {
29
+ result,
30
+ deps: { ...model, deps, allSatisfied: result.ok },
31
+ };
32
+ }
33
+ //# sourceMappingURL=depsHelpers.js.map
@@ -0,0 +1,140 @@
1
+ /**
2
+ * The summary view model: the JSON the card renders. buildSummary assembles
3
+ * the engine list, the detected hardware, the form model for the selected
4
+ * engine, the VRAM meter model for the current config, the verdict the banner
5
+ * renders, the guideline warning model the red banner and inline warnings
6
+ * render from, and the config the form edits. The estimate is the single
7
+ * source the meter and the verdict banner agree on, and the guideline results
8
+ * are the single source the red banner and the inline warnings agree on.
9
+ * @module dsh-plugin-local-infer/ui/viewmodels/summary
10
+ */
11
+ import type { Config, DefaultProvenance, HardwareProfile, ProviderStatus, VramVerdict } from 'dsh-plugin-local-infer/core';
12
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
13
+ import type { StoredPlatformConfig } from '../config.ts';
14
+ import type { FormModel } from '../form.ts';
15
+ import type { MeterModel } from '../meter.ts';
16
+ import type { WarningsModel } from '../warnings.ts';
17
+ /**
18
+ * LocalInferSummary is the JSON the card renders: the engine list, the model
19
+ * list, the detected hardware, the form model for the selected engine, the
20
+ * meter model for the current config, the verdict the banner renders, the
21
+ * guideline warning model the red banner and inline warnings render from,
22
+ * and the config the form edits. Every field is plain data, so it crosses
23
+ * the socket without a function left behind.
24
+ */
25
+ export interface LocalInferSummary {
26
+ engines: {
27
+ id: string;
28
+ label: string;
29
+ supports: {
30
+ docker: boolean;
31
+ local: boolean;
32
+ binary?: boolean;
33
+ };
34
+ defaultBuildCommand?: string;
35
+ defaultDockerTag?: string;
36
+ }[];
37
+ models: {
38
+ id: string;
39
+ source: string;
40
+ }[];
41
+ hardware: HardwareProfile;
42
+ engineId: string;
43
+ formModel: FormModel;
44
+ meterModel: MeterModel;
45
+ verdict: VramVerdict;
46
+ warningsModel: WarningsModel;
47
+ config: Config;
48
+ platformConfigs: Record<string, StoredPlatformConfig>;
49
+ defaults: DefaultsModel;
50
+ modelDirectory: string;
51
+ modelDefaults: ModelDefaultModel[];
52
+ modelStatus: ModelStatusModel | null;
53
+ chatTemplateStatus: ChatTemplateStatusModel | null;
54
+ modelFiles: string[];
55
+ showHelp: boolean;
56
+ providers: ProviderSummaryEntry[];
57
+ logPath: string;
58
+ lastLogs: string;
59
+ unsureBanner: {
60
+ message: string;
61
+ killCommands: string[];
62
+ } | null;
63
+ registered: boolean;
64
+ }
65
+ /**
66
+ * ProviderSummaryEntry is the card-facing view of one saved provider config:
67
+ * the stable id the card edits and deletes against, the engine and model the
68
+ * title renders ("NInfer: <model>"), the running-state the status dot paints,
69
+ * and the full config and platform the expanded form draws from.
70
+ */
71
+ export interface ProviderSummaryEntry {
72
+ id: string;
73
+ engine: string;
74
+ model: string;
75
+ status: ProviderStatus;
76
+ config: Config;
77
+ platform: StoredPlatformConfig;
78
+ }
79
+ /**
80
+ * ModelDefaultModel is the card-facing view of one default model entry: the
81
+ * registry key the config `model` field carries, the label the dropdown
82
+ * shows, and the Hugging Face URL the no-CLI row links to.
83
+ */
84
+ export interface ModelDefaultModel {
85
+ id: string;
86
+ label: string;
87
+ url: string;
88
+ }
89
+ /**
90
+ * ModelStatusModel is the model-status read model the card draws: whether the
91
+ * model is present in the model directory, whether the hf CLI is available,
92
+ * and the download command the Download button runs. The card shows the row
93
+ * only while the model is absent.
94
+ */
95
+ export interface ModelStatusModel {
96
+ modelId: string;
97
+ label: string;
98
+ url: string;
99
+ present: boolean;
100
+ hfCli: boolean;
101
+ downloadCommand: string;
102
+ }
103
+ /**
104
+ * ChatTemplateStatusModel is the answer to "is the selected chat template in
105
+ * the model directory": the repo reference, its display label, whether the
106
+ * template file is present, whether the hf CLI is available, and the download
107
+ * command the card runs (and the System dependencies box shows when the auto-
108
+ * download is unavailable).
109
+ */
110
+ export interface ChatTemplateStatusModel {
111
+ repo: string;
112
+ label: string;
113
+ present: boolean;
114
+ hfCli: boolean;
115
+ downloadCommand: string;
116
+ }
117
+ /**
118
+ * DefaultsModel is the resolved-defaults read model the card draws: the
119
+ * starting config the defaults resolver produced and the per-key provenance
120
+ * that names the source that supplied each value (a preset, the user, or a
121
+ * spec default).
122
+ */
123
+ export interface DefaultsModel {
124
+ config: Config;
125
+ provenance: DefaultProvenance[];
126
+ }
127
+ /**
128
+ * buildSummary assembles the card's read model for one engine and config: the
129
+ * static engine and model lists, the detected hardware, the form model the
130
+ * selected engine's parameter surface renders to, the meter model the
131
+ * service's estimate prices, and the warning model the service's guideline
132
+ * engine fires. The estimate is the single source the meter and the verdict
133
+ * banner agree on, and the guideline results are the single source the red
134
+ * banner and the inline warnings agree on.
135
+ */
136
+ export declare function buildSummary(localInfer: LocalInferService, request?: {
137
+ engine?: string;
138
+ config?: Config;
139
+ }): Promise<LocalInferSummary>;
140
+ //# sourceMappingURL=summary.d.ts.map
@@ -0,0 +1,225 @@
1
+ /**
2
+ * The summary view model: the JSON the card renders. buildSummary assembles
3
+ * the engine list, the detected hardware, the form model for the selected
4
+ * engine, the VRAM meter model for the current config, the verdict the banner
5
+ * renders, the guideline warning model the red banner and inline warnings
6
+ * render from, and the config the form edits. The estimate is the single
7
+ * source the meter and the verdict banner agree on, and the guideline results
8
+ * are the single source the red banner and the inline warnings agree on.
9
+ * @module dsh-plugin-local-infer/ui/viewmodels/summary
10
+ */
11
+ import { existsSync } from 'node:fs';
12
+ import { join } from 'node:path';
13
+ import { buildModelEntry, CHAT_TEMPLATE_FILE, hfChatTemplateCommand, hfDownloadCommand, modelArtifactPath, modelEntriesForEngine, } from '../../../core/lib/index.js';
14
+ import { defaultModelFor, defaultModelsForEngine, ENGINES, enginePlatformDefaults, } from '../../../providers/lib/index.js';
15
+ import { readConfig } from "../config.js";
16
+ import { renderForm } from "../form.js";
17
+ import { renderMeter } from "../meter.js";
18
+ import { renderWarnings } from "../warnings.js";
19
+ import { relinkStoredProviders, resolveAdapter } from "../ops/engine.js";
20
+ import { resolveModelRow } from "../ops/model.js";
21
+ import { chatTemplateLabel, isHfRepoReference, resolveModelRegistryId } from "./summaryHelpers.js";
22
+ /**
23
+ * buildSummary assembles the card's read model for one engine and config: the
24
+ * static engine and model lists, the detected hardware, the form model the
25
+ * selected engine's parameter surface renders to, the meter model the
26
+ * service's estimate prices, and the warning model the service's guideline
27
+ * engine fires. The estimate is the single source the meter and the verdict
28
+ * banner agree on, and the guideline results are the single source the red
29
+ * banner and the inline warnings agree on.
30
+ */
31
+ export async function buildSummary(localInfer, request) {
32
+ const stored = readConfig();
33
+ const engineId = request?.engine ?? stored.engine;
34
+ // ENGINES is a known non-empty constant, so the fallback is always defined.
35
+ const engine = ENGINES.find((entry) => entry.id === engineId) ?? ENGINES[0];
36
+ // The Model Directory field defaults to the plugin's model download
37
+ // directory (~/.dsh/models, created when absent), so the card always
38
+ // seeds a real path the deploy step can target. A stored or requested
39
+ // directory that is a non-blank string wins over the default.
40
+ const modelDirectory = localInfer.defaultModelDirectory();
41
+ const rawConfig = request?.config ?? stored.config;
42
+ const config = typeof rawConfig.modelDirectory === 'string' && rawConfig.modelDirectory.trim() !== ''
43
+ ? rawConfig
44
+ : { ...rawConfig, modelDirectory };
45
+ const modelDir = typeof config.modelDirectory === 'string' ? config.modelDirectory : modelDirectory;
46
+ const hardware = await localInfer.detectHardware();
47
+ // The model value the card carries maps onto the VramModel registry key the
48
+ // estimator prices: a default-model selection is already a registry key, a
49
+ // directory-scan selection is an artifact file name the default list maps
50
+ // to its registry key, and a missing value falls back to the engine's first
51
+ // default model. Pricing the resolved key is what keeps the meter from
52
+ // reading as not-measured (an empty chart) on a scanned model.
53
+ const modelId = resolveModelRegistryId(engine.id, config.model);
54
+ const pricedConfig = { ...config, model: modelId };
55
+ // Resolve the starting config over the registered presets and the engine's
56
+ // parameter surface, so the estimate and the model-aware guidelines price a
57
+ // sane budget (the preset's kvDtype and max-context) rather than a bare
58
+ // config that names no KV format. The resolved config carries the explicit
59
+ // values the user set over the preset defaults, and the engine's first
60
+ // default model when the user named none. The engine id rides into both
61
+ // entry points: the estimate's OS-reserve resolution runs the plugin-
62
+ // launched check against it, and the model-aware guidelines price the same
63
+ // usable budget the meter does.
64
+ const defaults = await localInfer.resolveDefaults(engine.id, modelId, hardware, pricedConfig);
65
+ const estimate = await localInfer.estimate(defaults.config, hardware, engine.id);
66
+ const guidelineResults = await localInfer.guidelines(defaults.config, hardware, engine.id);
67
+ // The directory scan lists the model files the selected engine can serve
68
+ // straight from the model directory, so the card's Model dropdown offers
69
+ // them beside the defaults. A missing directory reads as an empty list.
70
+ const modelFiles = modelEntriesForEngine(localInfer.listModelDirectory(modelDir), engine.id);
71
+ // The model status checks the selected model against the model directory
72
+ // and probes the hf CLI, so the card shows its Download row (or the URL
73
+ // row) only while the model is absent.
74
+ const entry = defaultModelFor(engine.id, modelId);
75
+ let modelStatus = null;
76
+ if (entry !== undefined) {
77
+ const present = existsSync(modelArtifactPath(entry, modelDir));
78
+ const hfCli = (await localInfer.hfCliAvailable()) !== null;
79
+ modelStatus = {
80
+ modelId: entry.modelId,
81
+ label: entry.label,
82
+ url: entry.url,
83
+ present,
84
+ hfCli,
85
+ downloadCommand: hfDownloadCommand(entry, modelDir),
86
+ };
87
+ }
88
+ // The chat-template status checks the selected template against the model
89
+ // directory and probes the hf CLI, so the card auto-downloads an absent
90
+ // template (and the System dependencies box shows the download command when
91
+ // the CLI is missing). Only HF repo references are downloadable; a local
92
+ // path or an empty template reads as null.
93
+ const chatTemplateValue = typeof config.chatTemplate === 'string' ? config.chatTemplate : '';
94
+ let chatTemplateStatus = null;
95
+ if (isHfRepoReference(chatTemplateValue)) {
96
+ const present = existsSync(join(modelDir, CHAT_TEMPLATE_FILE));
97
+ const hfCli = (await localInfer.hfCliAvailable()) !== null;
98
+ chatTemplateStatus = {
99
+ repo: chatTemplateValue,
100
+ label: chatTemplateLabel(chatTemplateValue),
101
+ present,
102
+ hfCli,
103
+ downloadCommand: hfChatTemplateCommand(chatTemplateValue, modelDir),
104
+ };
105
+ }
106
+ // The restart re-link: a provider entry whose launch record names a still-
107
+ // running engine (the DSH that launched it died, and the engine re-parented
108
+ // to init) is re-adopted as plugin-launched, so its status dot reads as
109
+ // running for its model and the OS-reserve resolver keeps the default. A
110
+ // record whose engine is dead is cleared (the previous-pid list with it),
111
+ // so a recycled pid cannot re-link to a config whose engine is down. The
112
+ // adopted engines also get a liveness watcher, so a later pkill settles the
113
+ // stored state without waiting for another summary read.
114
+ const linkedProviders = await relinkStoredProviders(localInfer, stored);
115
+ // The provider list the card renders as collapsed entries: each saved
116
+ // config's engine and model feed the detector, which resolves the running-
117
+ // state its status dot paints. A provider the detector cannot tie to a
118
+ // confirmed model reads as unsure, so the dot never overstates a live
119
+ // engine. The config rides into the detector so the signature prices the
120
+ // provider's own build mode and port, not the adapter's default-port guess.
121
+ const providerRefs = linkedProviders.map((provider) => {
122
+ const model = typeof provider.config.model === 'string' ? provider.config.model : undefined;
123
+ // exactOptionalPropertyTypes: include the model key only when it is a
124
+ // string, so a config that names no model never writes `undefined`.
125
+ return model !== undefined
126
+ ? { id: provider.id, engine: provider.engine, model, config: provider.config }
127
+ : { id: provider.id, engine: provider.engine, config: provider.config };
128
+ });
129
+ const providerStatuses = providerRefs.length > 0 ? await localInfer.providerStatuses(providerRefs) : {};
130
+ const providers = linkedProviders.map((provider) => ({
131
+ id: provider.id,
132
+ engine: provider.engine,
133
+ model: typeof provider.config.model === 'string' ? provider.config.model : '',
134
+ status: providerStatuses[provider.id] ?? 'unsure',
135
+ config: provider.config,
136
+ platform: provider.platform,
137
+ }));
138
+ // The "unsure" banner: shown when no provider is confirmed running but at
139
+ // least one reads as unsure (a foreign engine the detector saw but could
140
+ // not tie to a model, or a busy card). The banner offers bash kill commands
141
+ // for the engine processes the detector saw holding VRAM, so the user can
142
+ // stop a provider launched in another session.
143
+ const anyRunning = providers.some((p) => p.status === 'running');
144
+ const anyUnsure = providers.some((p) => p.status === 'unsure');
145
+ const unsureBanner = !anyRunning && anyUnsure
146
+ ? {
147
+ message: 'Unable to link to a provider (it may have been launched in another session). \n To stop, run:',
148
+ killCommands: await localInfer.unsureBannerKillCommands(),
149
+ }
150
+ : null;
151
+ // The registered flag tells the card whether the current config's provider
152
+ // and model are already in the DSH settings, so the Remove button shows
153
+ // only when there is something to remove. A profile without the settings
154
+ // seam (a host that predates the typert remote) or a host without the
155
+ // engine adapter registered reads as unregistered. The row resolves through
156
+ // the same discovery plus modelRef fall-through the register step uses, so
157
+ // the flag names the same entry the register step wrote while the engine
158
+ // answers, and a down engine (no discovery) reads as unregistered.
159
+ let registered = false;
160
+ try {
161
+ const regAdapter = resolveAdapter(localInfer, engine.id);
162
+ const regPlan = regAdapter.renderLaunch(config, hardware);
163
+ const regRow = await resolveModelRow(regAdapter, regPlan, config);
164
+ const regEntry = buildModelEntry(regPlan, regRow);
165
+ registered = await localInfer.modelIsRegistered(regEntry.providerId, regRow.id);
166
+ }
167
+ catch {
168
+ // A missing adapter, a missing settings seam, or a refused read all
169
+ // read as unregistered, which hides the Remove button (a no-op removal).
170
+ }
171
+ return {
172
+ engines: ENGINES.map((entry) => {
173
+ // The platform defaults ride the engine entry so the card's Engine
174
+ // platform section seeds the build-command and docker-tag placeholders
175
+ // from the same data the deploy step consumes.
176
+ const defaults = enginePlatformDefaults(entry.id);
177
+ return {
178
+ id: entry.id,
179
+ label: entry.label,
180
+ supports: entry.supports,
181
+ ...(defaults.defaultBuildCommand !== undefined
182
+ ? { defaultBuildCommand: defaults.defaultBuildCommand }
183
+ : {}),
184
+ ...(defaults.defaultDockerTag !== undefined
185
+ ? { defaultDockerTag: defaults.defaultDockerTag }
186
+ : {}),
187
+ };
188
+ }),
189
+ models: localInfer.registeredVramModels().map((model) => ({ id: model.id, source: model.source })),
190
+ hardware,
191
+ engineId: engine.id,
192
+ // The hardware profile prices the form's hardware-dependent controls (the
193
+ // host-KV slider cap), so the render model and the meter agree on the
194
+ // machine they run on.
195
+ formModel: renderForm(engine.parameters, config, hardware),
196
+ meterModel: renderMeter(estimate.breakdown, estimate.verdict, hardware.gpu?.vramGiB ?? 0, estimate.source, estimate.reserveSource,
197
+ // The "Unknown Engine(s)" readout shows the VRAM the detector's foreign
198
+ // engine programs are holding: the OS-reserve segment is the GPU's used
199
+ // VRAM when a foreign engine is detected, so the readout names the
200
+ // footprint a provider launched in another session is eating off the
201
+ // card. Absent when no provider reads as unsure.
202
+ anyUnsure ? { bytes: estimate.breakdown.reserve } : null),
203
+ verdict: estimate.verdict,
204
+ warningsModel: renderWarnings(guidelineResults),
205
+ config,
206
+ platformConfigs: stored.platform,
207
+ defaults: { config: defaults.config, provenance: defaults.provenance },
208
+ modelDirectory,
209
+ modelDefaults: defaultModelsForEngine(engine.id).map((entry) => ({
210
+ id: entry.modelId,
211
+ label: entry.label,
212
+ url: entry.url,
213
+ })),
214
+ modelStatus,
215
+ chatTemplateStatus,
216
+ modelFiles,
217
+ showHelp: stored.showHelp,
218
+ providers,
219
+ logPath: stored.logPath,
220
+ lastLogs: stored.lastLogs,
221
+ unsureBanner,
222
+ registered,
223
+ };
224
+ }
225
+ //# sourceMappingURL=summary.js.map