dsh-plugin-local-infer 0.1.2 → 0.1.4
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 +32 -6
- package/cordis.patch.yml +7 -0
- package/docs/zh/README.md +24 -4
- package/dsh/client.js +4200 -4049
- package/package.json +33 -11
- package/packages/core/lib/adapter.d.ts +177 -11
- package/packages/core/lib/adapter.js +74 -1
- package/packages/core/lib/config.d.ts +1 -1
- package/packages/core/lib/config.js +1 -1
- package/packages/core/lib/debug.d.ts +1 -1
- package/packages/core/lib/debug.js +1 -1
- package/packages/core/lib/defaults.d.ts +1 -1
- package/packages/core/lib/defaults.js +1 -1
- package/packages/core/lib/deps.d.ts +48 -20
- package/packages/core/lib/deps.js +24 -8
- package/packages/core/lib/estimator.d.ts +1 -1
- package/packages/core/lib/estimator.js +1 -1
- package/packages/core/lib/guideline.d.ts +1 -1
- package/packages/core/lib/guideline.js +1 -1
- package/packages/core/lib/hardware.d.ts +1 -1
- package/packages/core/lib/hardware.js +1 -1
- package/packages/core/lib/hf-cache.d.ts +70 -0
- package/packages/core/lib/hf-cache.js +83 -0
- package/packages/core/lib/index.d.ts +16 -9
- package/packages/core/lib/index.js +10 -6
- package/packages/core/lib/infer-cache.d.ts +39 -0
- package/packages/core/lib/infer-cache.js +53 -0
- package/packages/core/lib/launch-command.d.ts +8 -4
- package/packages/core/lib/launch-command.js +13 -6
- package/packages/core/lib/launch-record.d.ts +1 -1
- package/packages/core/lib/launch-record.js +1 -1
- package/packages/core/lib/logs.d.ts +8 -1
- package/packages/core/lib/logs.js +12 -4
- package/packages/core/lib/models.d.ts +120 -14
- package/packages/core/lib/models.js +209 -17
- package/packages/core/lib/parameter.d.ts +31 -3
- package/packages/core/lib/parameter.js +1 -1
- package/packages/core/lib/progress.d.ts +54 -0
- package/packages/core/lib/progress.js +120 -0
- package/packages/core/lib/registrar.d.ts +25 -14
- package/packages/core/lib/registrar.js +30 -10
- package/packages/core/lib/reserve.d.ts +11 -3
- package/packages/core/lib/reserve.js +6 -4
- package/packages/core/lib/status.d.ts +12 -6
- package/packages/core/lib/status.js +21 -10
- package/packages/core/lib/sudo.d.ts +80 -0
- package/packages/core/lib/sudo.js +78 -0
- package/packages/core/package.json +1 -1
- package/packages/orchestrator/lib/config.d.ts +63 -0
- package/packages/orchestrator/lib/config.js +111 -0
- package/packages/orchestrator/lib/index.d.ts +51 -0
- package/packages/orchestrator/lib/index.js +73 -0
- package/packages/orchestrator/lib/route.d.ts +60 -0
- package/packages/orchestrator/lib/route.js +159 -0
- package/packages/orchestrator/locale/en.json +6 -0
- package/packages/orchestrator/package.json +39 -0
- package/packages/orchestrator/prompt.md +87 -0
- package/packages/providers/lib/acquire.d.ts +95 -15
- package/packages/providers/lib/acquire.js +239 -40
- package/packages/providers/lib/adapters.d.ts +155 -221
- package/packages/providers/lib/adapters.js +589 -935
- package/packages/providers/lib/debug.d.ts +1 -1
- package/packages/providers/lib/debug.js +1 -1
- package/packages/providers/lib/deps.d.ts +31 -212
- package/packages/providers/lib/deps.js +71 -205
- package/packages/providers/lib/engines/basalt/basalt.d.ts +130 -0
- package/packages/providers/lib/engines/basalt/basalt.js +304 -0
- package/packages/providers/lib/engines/basalt/basaltAdapter.d.ts +85 -0
- package/packages/providers/lib/engines/basalt/basaltAdapter.js +439 -0
- package/packages/providers/lib/engines/basalt/basaltLinux.d.ts +23 -0
- package/packages/providers/lib/engines/basalt/basaltLinux.js +47 -0
- package/packages/providers/lib/engines/basalt/basaltMacOS.d.ts +17 -0
- package/packages/providers/lib/engines/basalt/basaltMacOS.js +19 -0
- package/packages/providers/lib/engines/basalt/basaltWindows.d.ts +24 -0
- package/packages/providers/lib/engines/basalt/basaltWindows.js +49 -0
- package/packages/providers/lib/engines/engineOs.d.ts +24 -0
- package/packages/providers/lib/engines/engineOs.js +17 -0
- package/packages/providers/lib/{hyperqwen.d.ts → engines/hyperqwen/hyperqwen.d.ts} +2 -2
- package/packages/providers/lib/{hyperqwen.js → engines/hyperqwen/hyperqwen.js} +14 -2
- package/packages/providers/lib/engines/hyperqwen/hyperqwenAdapter.d.ts +38 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenAdapter.js +115 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenArch.d.ts +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenArch.js +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenDebian.d.ts +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenDebian.js +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenFedora.d.ts +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenFedora.js +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenLinux.d.ts +10 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenLinux.js +14 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenMacOS.d.ts +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenMacOS.js +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenWindows.d.ts +9 -0
- package/packages/providers/lib/engines/hyperqwen/hyperqwenWindows.js +9 -0
- package/packages/providers/lib/{infernix.d.ts → engines/infernix/infernix.d.ts} +7 -4
- package/packages/providers/lib/{infernix.js → engines/infernix/infernix.js} +53 -8
- package/packages/providers/lib/engines/infernix/infernixAdapter.d.ts +52 -0
- package/packages/providers/lib/engines/infernix/infernixAdapter.js +235 -0
- package/packages/providers/lib/engines/infernix/infernixArch.d.ts +9 -0
- package/packages/providers/lib/engines/infernix/infernixArch.js +9 -0
- package/packages/providers/lib/engines/infernix/infernixDebian.d.ts +9 -0
- package/packages/providers/lib/engines/infernix/infernixDebian.js +9 -0
- package/packages/providers/lib/engines/infernix/infernixFedora.d.ts +9 -0
- package/packages/providers/lib/engines/infernix/infernixFedora.js +9 -0
- package/packages/providers/lib/engines/infernix/infernixLinux.d.ts +17 -0
- package/packages/providers/lib/engines/infernix/infernixLinux.js +35 -0
- package/packages/providers/lib/engines/infernix/infernixMacOS.d.ts +16 -0
- package/packages/providers/lib/engines/infernix/infernixMacOS.js +18 -0
- package/packages/providers/lib/engines/infernix/infernixWindows.d.ts +16 -0
- package/packages/providers/lib/engines/infernix/infernixWindows.js +34 -0
- package/packages/providers/lib/{llamacpp.d.ts → engines/llamacpp/llamacpp.d.ts} +2 -2
- package/packages/providers/lib/{llamacpp.js → engines/llamacpp/llamacpp.js} +12 -2
- package/packages/providers/lib/engines/llamacpp/llamacppAdapter.d.ts +50 -0
- package/packages/providers/lib/engines/llamacpp/llamacppAdapter.js +274 -0
- package/packages/providers/lib/engines/llamacpp/llamacppArch.d.ts +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppArch.js +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppDebian.d.ts +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppDebian.js +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppFedora.d.ts +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppFedora.js +9 -0
- package/packages/providers/lib/engines/llamacpp/llamacppLinux.d.ts +17 -0
- package/packages/providers/lib/engines/llamacpp/llamacppLinux.js +28 -0
- package/packages/providers/lib/engines/llamacpp/llamacppMacOS.d.ts +15 -0
- package/packages/providers/lib/engines/llamacpp/llamacppMacOS.js +17 -0
- package/packages/providers/lib/engines/llamacpp/llamacppWindows.d.ts +15 -0
- package/packages/providers/lib/engines/llamacpp/llamacppWindows.js +26 -0
- package/packages/providers/lib/{ninfer.d.ts → engines/ninfer/ninfer.d.ts} +2 -2
- package/packages/providers/lib/{ninfer.js → engines/ninfer/ninfer.js} +25 -3
- package/packages/providers/lib/engines/ninfer/ninferAdapter.d.ts +81 -0
- package/packages/providers/lib/engines/ninfer/ninferAdapter.js +392 -0
- package/packages/providers/lib/engines/ninfer/ninferArch.d.ts +9 -0
- package/packages/providers/lib/engines/ninfer/ninferArch.js +9 -0
- package/packages/providers/lib/engines/ninfer/ninferDebian.d.ts +9 -0
- package/packages/providers/lib/engines/ninfer/ninferDebian.js +9 -0
- package/packages/providers/lib/engines/ninfer/ninferFedora.d.ts +9 -0
- package/packages/providers/lib/engines/ninfer/ninferFedora.js +9 -0
- package/packages/providers/lib/engines/ninfer/ninferLinux.d.ts +17 -0
- package/packages/providers/lib/engines/ninfer/ninferLinux.js +37 -0
- package/packages/providers/lib/engines/ninfer/ninferMacOS.d.ts +15 -0
- package/packages/providers/lib/engines/ninfer/ninferMacOS.js +17 -0
- package/packages/providers/lib/engines/ninfer/ninferWindows.d.ts +29 -0
- package/packages/providers/lib/engines/ninfer/ninferWindows.js +59 -0
- package/packages/providers/lib/engines/strata/strata.d.ts +1 -0
- package/packages/providers/lib/engines/strata/strata.js +264 -0
- package/packages/providers/lib/engines/strata/strataAdapter.d.ts +97 -0
- package/packages/providers/lib/engines/strata/strataAdapter.js +463 -0
- package/packages/providers/lib/engines/strata/strataArch.d.ts +9 -0
- package/packages/providers/lib/engines/strata/strataArch.js +9 -0
- package/packages/providers/lib/engines/strata/strataDebian.d.ts +9 -0
- package/packages/providers/lib/engines/strata/strataDebian.js +9 -0
- package/packages/providers/lib/engines/strata/strataFedora.d.ts +9 -0
- package/packages/providers/lib/engines/strata/strataFedora.js +9 -0
- package/packages/providers/lib/engines/strata/strataLinux.d.ts +21 -0
- package/packages/providers/lib/engines/strata/strataLinux.js +30 -0
- package/packages/providers/lib/engines/strata/strataMacOS.d.ts +16 -0
- package/packages/providers/lib/engines/strata/strataMacOS.js +17 -0
- package/packages/providers/lib/engines/strata/strataWindows.d.ts +27 -0
- package/packages/providers/lib/engines/strata/strataWindows.js +37 -0
- package/packages/providers/lib/engines.d.ts +8 -5
- package/packages/providers/lib/engines.js +22 -11
- package/packages/providers/lib/guidelines.d.ts +5 -4
- package/packages/providers/lib/guidelines.js +18 -5
- package/packages/providers/lib/index.d.ts +33 -24
- package/packages/providers/lib/index.js +46 -24
- package/packages/providers/lib/model-defaults.d.ts +10 -5
- package/packages/providers/lib/model-defaults.js +47 -5
- package/packages/providers/lib/platform.d.ts +8 -5
- package/packages/providers/lib/platform.js +27 -7
- package/packages/providers/lib/presets.d.ts +6 -4
- package/packages/providers/lib/presets.js +53 -5
- package/packages/providers/lib/systemDeps.d.ts +313 -0
- package/packages/providers/lib/systemDeps.js +284 -0
- package/packages/providers/lib/vram.d.ts +34 -8
- package/packages/providers/lib/vram.js +81 -8
- package/packages/providers/package.json +2 -2
- package/packages/service/lib/index.d.ts +187 -23
- package/packages/service/lib/index.js +667 -90
- package/packages/service/lib/launch-target.d.ts +19 -0
- package/packages/service/lib/launch-target.js +28 -0
- package/packages/service/lib/run-logs.d.ts +72 -0
- package/packages/service/lib/run-logs.js +125 -0
- package/packages/service/lib/types.d.ts +166 -8
- package/packages/service/lib/types.js +1 -1
- package/packages/service/package.json +2 -2
- package/packages/tool/lib/index.d.ts +1 -1
- package/packages/tool/lib/index.js +1 -1
- package/packages/tool/package.json +2 -2
- package/packages/ui/lib/config.d.ts +89 -0
- package/packages/ui/lib/config.js +251 -0
- package/packages/ui/lib/deps.d.ts +4 -4
- package/packages/ui/lib/deps.js +1 -1
- package/packages/ui/lib/form.d.ts +1 -1
- package/packages/ui/lib/form.js +1 -1
- package/packages/ui/lib/index.d.ts +7 -1
- package/packages/ui/lib/index.js +12 -2
- package/packages/ui/lib/meter.d.ts +1 -1
- package/packages/ui/lib/meter.js +1 -1
- package/packages/ui/lib/ops/engine.d.ts +216 -0
- package/packages/ui/lib/ops/engine.js +697 -0
- package/packages/ui/lib/ops/get-steps.d.ts +98 -0
- package/packages/ui/lib/ops/get-steps.js +359 -0
- package/packages/ui/lib/ops/hf.d.ts +42 -0
- package/packages/ui/lib/ops/hf.js +150 -0
- package/packages/ui/lib/ops/logs.d.ts +78 -0
- package/packages/ui/lib/ops/logs.js +119 -0
- package/packages/ui/lib/ops/model.d.ts +71 -0
- package/packages/ui/lib/ops/model.js +123 -0
- package/packages/ui/lib/request.d.ts +106 -0
- package/packages/ui/lib/request.js +80 -0
- package/packages/ui/lib/route.d.ts +106 -422
- package/packages/ui/lib/route.js +136 -1845
- package/packages/ui/lib/routes/chat-template.d.ts +1 -0
- package/packages/ui/lib/routes/chat-template.js +1 -0
- package/packages/ui/lib/routes/deps.d.ts +1 -0
- package/packages/ui/lib/routes/deps.js +1 -0
- package/packages/ui/lib/routes/download.d.ts +1 -0
- package/packages/ui/lib/routes/download.js +1 -0
- package/packages/ui/lib/routes/get.d.ts +1 -0
- package/packages/ui/lib/routes/get.js +106 -0
- package/packages/ui/lib/routes/install.d.ts +16 -0
- package/packages/ui/lib/routes/install.js +36 -0
- package/packages/ui/lib/routes/launch.d.ts +24 -0
- package/packages/ui/lib/routes/launch.js +74 -0
- package/packages/ui/lib/routes/logs.d.ts +57 -0
- package/packages/ui/lib/routes/logs.js +117 -0
- package/packages/ui/lib/routes/provider-delete.d.ts +15 -0
- package/packages/ui/lib/routes/provider-delete.js +37 -0
- package/packages/ui/lib/routes/register.d.ts +16 -0
- package/packages/ui/lib/routes/register.js +28 -0
- package/packages/ui/lib/routes/save.d.ts +18 -0
- package/packages/ui/lib/routes/save.js +159 -0
- package/packages/ui/lib/routes/stop.d.ts +19 -0
- package/packages/ui/lib/routes/stop.js +32 -0
- package/packages/ui/lib/routes/stream.d.ts +40 -0
- package/packages/ui/lib/routes/stream.js +68 -0
- package/packages/ui/lib/routes/summary.d.ts +15 -0
- package/packages/ui/lib/routes/summary.js +26 -0
- package/packages/ui/lib/routes/unregister.d.ts +14 -0
- package/packages/ui/lib/routes/unregister.js +26 -0
- package/packages/ui/lib/viewmodels/deps.d.ts +1 -0
- package/packages/ui/lib/viewmodels/deps.js +1 -0
- package/packages/ui/lib/viewmodels/depsHelpers.d.ts +1 -0
- package/packages/ui/lib/viewmodels/depsHelpers.js +94 -0
- package/packages/ui/lib/viewmodels/summary.d.ts +145 -0
- package/packages/ui/lib/viewmodels/summary.js +245 -0
- package/packages/ui/lib/viewmodels/summaryHelpers.d.ts +30 -0
- package/packages/ui/lib/viewmodels/summaryHelpers.js +42 -0
- package/packages/ui/lib/warnings.d.ts +1 -1
- package/packages/ui/lib/warnings.js +1 -1
- package/packages/ui/package.json +4 -4
- package/packages/providers/lib/strata.d.ts +0 -15
- package/packages/providers/lib/strata.js +0 -14
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last-run log persistence the card's process steps use: persistProcessLog
|
|
3
|
+
* appends one run's output (a Get's commands and output, a model download's
|
|
4
|
+
* result, a stop's failure note) to the stored last-run logs (the card's Logs
|
|
5
|
+
* section shows it after a reload) and writes the run to the configured log
|
|
6
|
+
* file, the same per-run file rule the launch step applies; captureRunBaseline
|
|
7
|
+
* and finishRunSection close a streamed run so its provisional mid-run notes
|
|
8
|
+
* and its final text persist once.
|
|
9
|
+
* @module dsh-plugin-local-infer/ui/ops/logs
|
|
10
|
+
*/
|
|
11
|
+
import type { StoredConfig } from '../config.ts';
|
|
12
|
+
/**
|
|
13
|
+
* The run seeds are the `--- <process>...` separator lines that lead each
|
|
14
|
+
* provider process's run: the persisted section and the live run-log buffer
|
|
15
|
+
* share the constant, so the streamed run reads like the persisted one. The
|
|
16
|
+
* launch, get, and download steps already wrote these lines; the live hub
|
|
17
|
+
* reuses them.
|
|
18
|
+
*/
|
|
19
|
+
export declare const GET_RUN_SEED = "--- Getting engine and model...\n";
|
|
20
|
+
export declare const LAUNCH_RUN_SEED = "--- Launching...\n";
|
|
21
|
+
export declare const DOWNLOAD_RUN_SEED = "--- Downloading...\n";
|
|
22
|
+
export declare const INSTALL_RUN_SEED = "--- Installing deps...\n";
|
|
23
|
+
export declare const STOP_RUN_SEED = "--- Stopping...\n";
|
|
24
|
+
/**
|
|
25
|
+
* CANCELED_LINE is the "Canceled" line a client-disconnect cancel appends to
|
|
26
|
+
* the persisted run, so the Logs section and the log file read the run as
|
|
27
|
+
* canceled, the same line the card writes to its Logs buffer on the Cancel.
|
|
28
|
+
* Every canceled run (Get, launch, download, chat template) writes it from
|
|
29
|
+
* here.
|
|
30
|
+
*/
|
|
31
|
+
export declare const CANCELED_LINE = "--- Canceled\n";
|
|
32
|
+
/**
|
|
33
|
+
* persistProcessLog appends one process run's output to the stored last-run
|
|
34
|
+
* logs (capped to the launch logs' tail, so a long build cannot grow the
|
|
35
|
+
* config without bound) and writes the run to the configured log file. A
|
|
36
|
+
* missing log location (the field is optional) skips the file, the same rule
|
|
37
|
+
* the launch step uses. An empty output is a no-op.
|
|
38
|
+
*/
|
|
39
|
+
export declare function persistProcessLog(output: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* captureRunBaseline reads the stored last-run logs at the start of a run.
|
|
42
|
+
* The route passes it to finishRunSection when the run settles, so the
|
|
43
|
+
* finished run replaces the run's own provisional mid-run appends instead of
|
|
44
|
+
* appending the same text a second time under the section (the sudo CLI note
|
|
45
|
+
* persists while the run hangs on the password prompt and then rides the
|
|
46
|
+
* collected run text too).
|
|
47
|
+
*/
|
|
48
|
+
export declare function captureRunBaseline(): string;
|
|
49
|
+
/**
|
|
50
|
+
* finishRunSection closes one settled run: the stored last-run logs become
|
|
51
|
+
* the run's baseline plus the finished run section, replacing (not stacking
|
|
52
|
+
* over) the run's provisional mid-run appends, so a line that both persisted
|
|
53
|
+
* mid-run and rides the collected section persists exactly once. Tradeoff,
|
|
54
|
+
* accepted on purpose: another writer's append that landed between the
|
|
55
|
+
* baseline and the close is overwritten; the run owns the card's control
|
|
56
|
+
* while it runs, and the launch path already overwrites the stored logs
|
|
57
|
+
* wholesale (ops/engine.ts persistLaunchLogs). The section lands in the
|
|
58
|
+
* configured log file under the same per-run file rule persistProcessLog
|
|
59
|
+
* uses. An empty section is a no-op.
|
|
60
|
+
*/
|
|
61
|
+
export declare function finishRunSection(baseline: string, section: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* capRunLogs keeps one stored run's text within the shared LOG_TAIL_BYTES
|
|
64
|
+
* tail, the same bound the live hub buffer and every lastLogs writer apply.
|
|
65
|
+
* joinRunLogs and the wholesale launch persisters (ops/engine.ts
|
|
66
|
+
* persistStoredLogs, persistLaunchLogs) share this one cap rule.
|
|
67
|
+
*/
|
|
68
|
+
export declare function capRunLogs(logs: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* writeRunFile writes one run's text to the configured log file named for
|
|
71
|
+
* its engine and model. The launch persisters pass the launch's own engine
|
|
72
|
+
* and config; the append paths pass the stored ones (the defaults). A
|
|
73
|
+
* missing log location (the field is optional) skips the file; a file that
|
|
74
|
+
* cannot be written must not fail the run, since the in-memory last-run logs
|
|
75
|
+
* still reach the card. Every run writer shares this one file rule.
|
|
76
|
+
*/
|
|
77
|
+
export declare function writeRunFile(stored: StoredConfig, output: string, engineId?: string, modelId?: string | undefined): void;
|
|
78
|
+
//# sourceMappingURL=logs.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last-run log persistence the card's process steps use: persistProcessLog
|
|
3
|
+
* appends one run's output (a Get's commands and output, a model download's
|
|
4
|
+
* result, a stop's failure note) to the stored last-run logs (the card's Logs
|
|
5
|
+
* section shows it after a reload) and writes the run to the configured log
|
|
6
|
+
* file, the same per-run file rule the launch step applies; captureRunBaseline
|
|
7
|
+
* and finishRunSection close a streamed run so its provisional mid-run notes
|
|
8
|
+
* and its final text persist once.
|
|
9
|
+
* @module dsh-plugin-local-infer/ui/ops/logs
|
|
10
|
+
*/
|
|
11
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { homedir } from 'node:os';
|
|
13
|
+
import { dirname } from 'node:path';
|
|
14
|
+
import { LOG_TAIL_BYTES, resolveLogPath } from '../../../core/lib/index.js';
|
|
15
|
+
import { readConfig, writeStored } from "../config.js";
|
|
16
|
+
/**
|
|
17
|
+
* The run seeds are the `--- <process>...` separator lines that lead each
|
|
18
|
+
* provider process's run: the persisted section and the live run-log buffer
|
|
19
|
+
* share the constant, so the streamed run reads like the persisted one. The
|
|
20
|
+
* launch, get, and download steps already wrote these lines; the live hub
|
|
21
|
+
* reuses them.
|
|
22
|
+
*/
|
|
23
|
+
export const GET_RUN_SEED = '--- Getting engine and model...\n';
|
|
24
|
+
export const LAUNCH_RUN_SEED = '--- Launching...\n';
|
|
25
|
+
export const DOWNLOAD_RUN_SEED = '--- Downloading...\n';
|
|
26
|
+
export const INSTALL_RUN_SEED = '--- Installing deps...\n';
|
|
27
|
+
export const STOP_RUN_SEED = '--- Stopping...\n';
|
|
28
|
+
/**
|
|
29
|
+
* CANCELED_LINE is the "Canceled" line a client-disconnect cancel appends to
|
|
30
|
+
* the persisted run, so the Logs section and the log file read the run as
|
|
31
|
+
* canceled, the same line the card writes to its Logs buffer on the Cancel.
|
|
32
|
+
* Every canceled run (Get, launch, download, chat template) writes it from
|
|
33
|
+
* here.
|
|
34
|
+
*/
|
|
35
|
+
export const CANCELED_LINE = '--- Canceled\n';
|
|
36
|
+
/**
|
|
37
|
+
* persistProcessLog appends one process run's output to the stored last-run
|
|
38
|
+
* logs (capped to the launch logs' tail, so a long build cannot grow the
|
|
39
|
+
* config without bound) and writes the run to the configured log file. A
|
|
40
|
+
* missing log location (the field is optional) skips the file, the same rule
|
|
41
|
+
* the launch step uses. An empty output is a no-op.
|
|
42
|
+
*/
|
|
43
|
+
export function persistProcessLog(output) {
|
|
44
|
+
if (output === '')
|
|
45
|
+
return;
|
|
46
|
+
const stored = readConfig();
|
|
47
|
+
writeStored(stored, { lastLogs: joinRunLogs(stored.lastLogs, output) });
|
|
48
|
+
writeRunFile(stored, output);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* captureRunBaseline reads the stored last-run logs at the start of a run.
|
|
52
|
+
* The route passes it to finishRunSection when the run settles, so the
|
|
53
|
+
* finished run replaces the run's own provisional mid-run appends instead of
|
|
54
|
+
* appending the same text a second time under the section (the sudo CLI note
|
|
55
|
+
* persists while the run hangs on the password prompt and then rides the
|
|
56
|
+
* collected run text too).
|
|
57
|
+
*/
|
|
58
|
+
export function captureRunBaseline() {
|
|
59
|
+
return readConfig().lastLogs;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* finishRunSection closes one settled run: the stored last-run logs become
|
|
63
|
+
* the run's baseline plus the finished run section, replacing (not stacking
|
|
64
|
+
* over) the run's provisional mid-run appends, so a line that both persisted
|
|
65
|
+
* mid-run and rides the collected section persists exactly once. Tradeoff,
|
|
66
|
+
* accepted on purpose: another writer's append that landed between the
|
|
67
|
+
* baseline and the close is overwritten; the run owns the card's control
|
|
68
|
+
* while it runs, and the launch path already overwrites the stored logs
|
|
69
|
+
* wholesale (ops/engine.ts persistLaunchLogs). The section lands in the
|
|
70
|
+
* configured log file under the same per-run file rule persistProcessLog
|
|
71
|
+
* uses. An empty section is a no-op.
|
|
72
|
+
*/
|
|
73
|
+
export function finishRunSection(baseline, section) {
|
|
74
|
+
if (section === '')
|
|
75
|
+
return;
|
|
76
|
+
const stored = readConfig();
|
|
77
|
+
writeStored(stored, { lastLogs: joinRunLogs(baseline, section) });
|
|
78
|
+
writeRunFile(stored, section);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* capRunLogs keeps one stored run's text within the shared LOG_TAIL_BYTES
|
|
82
|
+
* tail, the same bound the live hub buffer and every lastLogs writer apply.
|
|
83
|
+
* joinRunLogs and the wholesale launch persisters (ops/engine.ts
|
|
84
|
+
* persistStoredLogs, persistLaunchLogs) share this one cap rule.
|
|
85
|
+
*/
|
|
86
|
+
export function capRunLogs(logs) {
|
|
87
|
+
return logs.slice(-LOG_TAIL_BYTES);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* joinRunLogs appends one run's text under the stored last-run logs (or the
|
|
91
|
+
* finished run's baseline), newline-separated, capped to the launch logs'
|
|
92
|
+
* tail so a long build cannot grow the config without bound. persistProcessLog
|
|
93
|
+
* and finishRunSection share the join and cap rule.
|
|
94
|
+
*/
|
|
95
|
+
function joinRunLogs(base, output) {
|
|
96
|
+
return capRunLogs(`${base}${base === '' ? '' : '\n'}${output}`);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* writeRunFile writes one run's text to the configured log file named for
|
|
100
|
+
* its engine and model. The launch persisters pass the launch's own engine
|
|
101
|
+
* and config; the append paths pass the stored ones (the defaults). A
|
|
102
|
+
* missing log location (the field is optional) skips the file; a file that
|
|
103
|
+
* cannot be written must not fail the run, since the in-memory last-run logs
|
|
104
|
+
* still reach the card. Every run writer shares this one file rule.
|
|
105
|
+
*/
|
|
106
|
+
export function writeRunFile(stored, output, engineId = stored.engine, modelId = typeof stored.config.model === 'string' ? stored.config.model : undefined) {
|
|
107
|
+
if (stored.logPath === undefined || stored.logPath === '')
|
|
108
|
+
return;
|
|
109
|
+
const logPath = resolveLogPath(stored.logPath, engineId, modelId, new Date(), homedir());
|
|
110
|
+
try {
|
|
111
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
112
|
+
writeFileSync(logPath, output);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// A log file that cannot be written (a read-only dir, a bad path) must not
|
|
116
|
+
// fail the run; the in-memory last-run logs still reach the card.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=logs.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DSH model registration operations: registerFor upserts the provider
|
|
3
|
+
* and model through the settings seam, unregisterFor removes the exact entry
|
|
4
|
+
* the registration wrote, and syncRegisteredModel re-runs the registration on
|
|
5
|
+
* a save so the registered model's input types stay in step with the config.
|
|
6
|
+
* resolveModelRow and resolveContextWindow resolve the row and context window
|
|
7
|
+
* the registrar publishes.
|
|
8
|
+
* @module dsh-plugin-local-infer/ui/ops/model
|
|
9
|
+
*/
|
|
10
|
+
import type { Config, ModelRow, RegisterResult, VramModel } from 'dsh-plugin-local-infer/core';
|
|
11
|
+
import type { LocalInferService } from 'dsh-plugin-local-infer/service';
|
|
12
|
+
import type { RegisterRequest } from '../request.ts';
|
|
13
|
+
/**
|
|
14
|
+
* resolveContextWindow picks the context window the registrar publishes: the
|
|
15
|
+
* config's maxContext when it names one, else the native ceiling of the
|
|
16
|
+
* VramModel the config resolves to (the named model, or the single
|
|
17
|
+
* registered model), else the 32768 spec default. The DSH contextWindow must
|
|
18
|
+
* not promise a context the engine cannot serve, so the ceiling is the
|
|
19
|
+
* model's own, not an optimistic number.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveContextWindow(config: Config, models: readonly VramModel[]): number;
|
|
22
|
+
/**
|
|
23
|
+
* resolveModelRow picks the model row the registrar publishes for an engine
|
|
24
|
+
* and config: the adapter's discovered model (what the running engine
|
|
25
|
+
* advertises on its model endpoint, read live) when the adapter discovers
|
|
26
|
+
* one, else the adapter's static modelRef, else the plan's model id, else the
|
|
27
|
+
* engine id. The display name follows the same fall-through. The discovery
|
|
28
|
+
* step awaits a terminal query, so the row is resolved asynchronously; an
|
|
29
|
+
* engine that is down discovers nothing and falls back through modelRef, so
|
|
30
|
+
* register, save-sync, unregister, and the summary flag stay consistent with
|
|
31
|
+
* whatever the engine answers while it is up.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveModelRow(adapter: {
|
|
34
|
+
id: string;
|
|
35
|
+
modelRef?(config: Config): {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
} | undefined;
|
|
39
|
+
discoverModel?(config: Config): Promise<{
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
}, plan: {
|
|
44
|
+
modelId?: string;
|
|
45
|
+
}, config: Config): Promise<ModelRow>;
|
|
46
|
+
/**
|
|
47
|
+
* registerFor renders the plan through the registered adapter, resolves the
|
|
48
|
+
* model row and the context window, and runs the service's register entry
|
|
49
|
+
* point, which upserts the provider and model through the settings seam.
|
|
50
|
+
* The result carries the entry the registrar wrote, so the card names the
|
|
51
|
+
* model it published.
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerFor(localInfer: LocalInferService, request?: RegisterRequest): Promise<RegisterResult>;
|
|
54
|
+
/**
|
|
55
|
+
* syncRegisteredModel re-runs the registration for a saved config when the
|
|
56
|
+
* model is already registered in the DSH settings, so the registered model's
|
|
57
|
+
* input types (the vision flag) stay in step with the saved config. A model
|
|
58
|
+
* that is not registered (a fresh save) is a no-op, and a profile without the
|
|
59
|
+
* settings seam throws, which the save route catches and swallows so the save
|
|
60
|
+
* itself never fails on a sync that cannot run.
|
|
61
|
+
*/
|
|
62
|
+
export declare function syncRegisteredModel(localInfer: LocalInferService, engine: string, config: Config): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* unregisterFor runs the service's removeModel entry point for the engine's
|
|
65
|
+
* provider and the model row the register step resolved, so the removal
|
|
66
|
+
* targets the exact entry the registration wrote.
|
|
67
|
+
*/
|
|
68
|
+
export declare function unregisterFor(localInfer: LocalInferService, request?: RegisterRequest): Promise<{
|
|
69
|
+
removed: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DSH model registration operations: registerFor upserts the provider
|
|
3
|
+
* and model through the settings seam, unregisterFor removes the exact entry
|
|
4
|
+
* the registration wrote, and syncRegisteredModel re-runs the registration on
|
|
5
|
+
* a save so the registered model's input types stay in step with the config.
|
|
6
|
+
* resolveModelRow and resolveContextWindow resolve the row and context window
|
|
7
|
+
* the registrar publishes.
|
|
8
|
+
* @module dsh-plugin-local-infer/ui/ops/model
|
|
9
|
+
*/
|
|
10
|
+
import { buildModelEntry, providerIdFor } from '../../../core/lib/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* DEFAULT_CONTEXT_WINDOW is the context window the registrar publishes when
|
|
13
|
+
* neither the config nor the resolved VramModel names one: the 32K spec
|
|
14
|
+
* default, a context the engines can serve without a measured ceiling.
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_CONTEXT_WINDOW = 32_768;
|
|
17
|
+
import { readConfig } from "../config.js";
|
|
18
|
+
import { resolveAdapter } from "./engine.js";
|
|
19
|
+
/**
|
|
20
|
+
* resolveContextWindow picks the context window the registrar publishes: the
|
|
21
|
+
* config's maxContext when it names one, else the native ceiling of the
|
|
22
|
+
* VramModel the config resolves to (the named model, or the single
|
|
23
|
+
* registered model), else the 32768 spec default. The DSH contextWindow must
|
|
24
|
+
* not promise a context the engine cannot serve, so the ceiling is the
|
|
25
|
+
* model's own, not an optimistic number.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveContextWindow(config, models) {
|
|
28
|
+
const configured = config.maxContext;
|
|
29
|
+
if (typeof configured === 'number' && configured > 0) {
|
|
30
|
+
return configured;
|
|
31
|
+
}
|
|
32
|
+
let model;
|
|
33
|
+
if (typeof config.model === 'string') {
|
|
34
|
+
model = models.find((entry) => entry.id === config.model);
|
|
35
|
+
}
|
|
36
|
+
else if (models.length === 1) {
|
|
37
|
+
model = models[0];
|
|
38
|
+
}
|
|
39
|
+
return model?.nativeMaxContext ?? DEFAULT_CONTEXT_WINDOW;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* resolveModelRow picks the model row the registrar publishes for an engine
|
|
43
|
+
* and config: the adapter's discovered model (what the running engine
|
|
44
|
+
* advertises on its model endpoint, read live) when the adapter discovers
|
|
45
|
+
* one, else the adapter's static modelRef, else the plan's model id, else the
|
|
46
|
+
* engine id. The display name follows the same fall-through. The discovery
|
|
47
|
+
* step awaits a terminal query, so the row is resolved asynchronously; an
|
|
48
|
+
* engine that is down discovers nothing and falls back through modelRef, so
|
|
49
|
+
* register, save-sync, unregister, and the summary flag stay consistent with
|
|
50
|
+
* whatever the engine answers while it is up.
|
|
51
|
+
*/
|
|
52
|
+
export async function resolveModelRow(adapter, plan, config) {
|
|
53
|
+
const ref = (await adapter.discoverModel?.(config)) ?? adapter.modelRef?.(config);
|
|
54
|
+
const id = ref?.id ?? plan.modelId ?? adapter.id;
|
|
55
|
+
return { id, name: ref?.name ?? id, contextWindow: 0 };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* registerFor renders the plan through the registered adapter, resolves the
|
|
59
|
+
* model row and the context window, and runs the service's register entry
|
|
60
|
+
* point, which upserts the provider and model through the settings seam.
|
|
61
|
+
* The result carries the entry the registrar wrote, so the card names the
|
|
62
|
+
* model it published.
|
|
63
|
+
*/
|
|
64
|
+
export async function registerFor(localInfer, request) {
|
|
65
|
+
const stored = readConfig();
|
|
66
|
+
const engineId = request?.engine ?? stored.engine;
|
|
67
|
+
const config = request?.config ?? stored.config;
|
|
68
|
+
const adapter = resolveAdapter(localInfer, engineId);
|
|
69
|
+
const hardware = await localInfer.detectHardware();
|
|
70
|
+
const plan = adapter.renderLaunch(config, hardware);
|
|
71
|
+
const row = await resolveModelRow(adapter, plan, config);
|
|
72
|
+
row.contextWindow = resolveContextWindow(config, localInfer.registeredVramModels());
|
|
73
|
+
// The adapter's declared modalities publish the input types on the DSH
|
|
74
|
+
// model row (Strata's vision enum, on by default, declares ['text',
|
|
75
|
+
// 'image']); an adapter that declares none keeps the boolean vision flag: a
|
|
76
|
+
// vision engine advertises ['text', 'image'] and a text-only engine
|
|
77
|
+
// ['text']. The registrar copies it into the entry it writes.
|
|
78
|
+
row.input =
|
|
79
|
+
adapter.modelInput?.(config) ?? (config.vision === true ? ['text', 'image'] : ['text']);
|
|
80
|
+
const options = request?.agentDefault === true ? { agentDefault: true } : undefined;
|
|
81
|
+
return localInfer.registerModel(plan, row, options);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* syncRegisteredModel re-runs the registration for a saved config when the
|
|
85
|
+
* model is already registered in the DSH settings, so the registered model's
|
|
86
|
+
* input types (the vision flag) stay in step with the saved config. A model
|
|
87
|
+
* that is not registered (a fresh save) is a no-op, and a profile without the
|
|
88
|
+
* settings seam throws, which the save route catches and swallows so the save
|
|
89
|
+
* itself never fails on a sync that cannot run.
|
|
90
|
+
*/
|
|
91
|
+
export async function syncRegisteredModel(localInfer, engine, config) {
|
|
92
|
+
const adapter = resolveAdapter(localInfer, engine);
|
|
93
|
+
const hardware = await localInfer.detectHardware();
|
|
94
|
+
const plan = adapter.renderLaunch(config, hardware);
|
|
95
|
+
const row = await resolveModelRow(adapter, plan, config);
|
|
96
|
+
const buildMode = plan.kind === 'docker' ? 'docker' : 'local';
|
|
97
|
+
const providerId = providerIdFor(adapter.id, row.id, buildMode);
|
|
98
|
+
if (await localInfer.modelIsRegistered(providerId, row.id)) {
|
|
99
|
+
await registerFor(localInfer, { engine, config });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* unregisterFor runs the service's removeModel entry point for the engine's
|
|
104
|
+
* provider and the model row the register step resolved, so the removal
|
|
105
|
+
* targets the exact entry the registration wrote.
|
|
106
|
+
*/
|
|
107
|
+
export async function unregisterFor(localInfer, request) {
|
|
108
|
+
const stored = readConfig();
|
|
109
|
+
const engineId = request?.engine ?? stored.engine;
|
|
110
|
+
const config = request?.config ?? stored.config;
|
|
111
|
+
const adapter = resolveAdapter(localInfer, engineId);
|
|
112
|
+
const hardware = await localInfer.detectHardware();
|
|
113
|
+
const plan = adapter.renderLaunch(config, hardware);
|
|
114
|
+
const row = await resolveModelRow(adapter, plan, config);
|
|
115
|
+
// The removal must target the exact entry the register step wrote, so the
|
|
116
|
+
// provider id is computed through buildModelEntry (the same function the
|
|
117
|
+
// register step uses) rather than a parallel providerIdFor call, which
|
|
118
|
+
// could drift if plan.engineId and adapter.id ever diverge.
|
|
119
|
+
const entry = buildModelEntry(plan, row);
|
|
120
|
+
await localInfer.removeModel(entry.providerId, row.id);
|
|
121
|
+
return { removed: true };
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The request types the card's routes parse and the parsers that build them.
|
|
3
|
+
* Every request carries only the keys the card sent: absent values fall back
|
|
4
|
+
* to the stored config per key, the same rule every route applies. The
|
|
5
|
+
* parsers read a `Record<string, unknown>` body (or a URL query) and build
|
|
6
|
+
* the request with only the keys that are present, so
|
|
7
|
+
* exactOptionalPropertyTypes never sees a `key: undefined` write.
|
|
8
|
+
* @module dsh-plugin-local-infer/ui/request
|
|
9
|
+
*/
|
|
10
|
+
import type { Config } from 'dsh-plugin-local-infer/core';
|
|
11
|
+
import type { StoredPlatformConfig } from './config.ts';
|
|
12
|
+
/**
|
|
13
|
+
* DepsRequest is the query the card sends for the deps panel: the engine and
|
|
14
|
+
* the config the build mode reads from. Absent values fall back to the stored
|
|
15
|
+
* config, the same rule the summary route applies.
|
|
16
|
+
*/
|
|
17
|
+
export interface DepsRequest {
|
|
18
|
+
engine?: string;
|
|
19
|
+
config?: Config;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DownloadRequest is the query the card sends for the download route: the
|
|
23
|
+
* engine, model, and directory the hf CLI download targets. Absent values
|
|
24
|
+
* fall back to the stored config, the same rule the summary route applies.
|
|
25
|
+
*/
|
|
26
|
+
export interface DownloadRequest {
|
|
27
|
+
engine?: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
directory?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ChatTemplateDownloadRequest is the query the card sends for the chat-template
|
|
33
|
+
* download route: the engine, the template repo reference, and the directory
|
|
34
|
+
* the hf CLI targets. Absent values fall back to the stored config, the same
|
|
35
|
+
* rule the summary route applies.
|
|
36
|
+
*/
|
|
37
|
+
export interface ChatTemplateDownloadRequest {
|
|
38
|
+
engine?: string;
|
|
39
|
+
template?: string;
|
|
40
|
+
directory?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* LaunchRequest is the query the card sends for the launch and stop routes: the
|
|
44
|
+
* engine and the config the plan renders from. `platform` carries the card's
|
|
45
|
+
* unsaved Engine Directory / Engine Fork edits for the engine, so a launch uses
|
|
46
|
+
* them without a prior save. `providerId` names the saved provider entry the
|
|
47
|
+
* launch drives, so the route persists the launch record (or clears it on a
|
|
48
|
+
* stop) on that entry. `autoRebuild` is the card's "Auto Rebuild" checkbox:
|
|
49
|
+
* when false, the deploy step skips the git sync (fetch, rebase, rebuild) and
|
|
50
|
+
* launches the checkout as-is. Absent values fall back to the stored config,
|
|
51
|
+
* the same rule the summary route applies.
|
|
52
|
+
*/
|
|
53
|
+
export interface LaunchRequest {
|
|
54
|
+
engine?: string;
|
|
55
|
+
config?: Config;
|
|
56
|
+
platform?: StoredPlatformConfig;
|
|
57
|
+
providerId?: string;
|
|
58
|
+
autoRebuild?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* GetRequest is the query the card sends for the Get route: the engine and
|
|
62
|
+
* the config the dep plan and the build mode read from, and the platform
|
|
63
|
+
* override (the card's unsaved Engine Directory / Engine Fork edits), the
|
|
64
|
+
* same rule the launch request applies. Absent values fall back to the
|
|
65
|
+
* stored config.
|
|
66
|
+
*/
|
|
67
|
+
export interface GetRequest {
|
|
68
|
+
engine?: string;
|
|
69
|
+
config?: Config;
|
|
70
|
+
platform?: StoredPlatformConfig;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* RegisterRequest is the query the card sends for the register and
|
|
74
|
+
* unregister routes: the engine and the config the plan renders from, and
|
|
75
|
+
* agentDefault, which points the agent default model at the registered
|
|
76
|
+
* engine. Absent values fall back to the stored config, the same rule the
|
|
77
|
+
* summary route applies.
|
|
78
|
+
*/
|
|
79
|
+
export interface RegisterRequest {
|
|
80
|
+
engine?: string;
|
|
81
|
+
config?: Config;
|
|
82
|
+
agentDefault?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* depsRequestFromUrl parses the engine and config query params the GET routes
|
|
86
|
+
* (summary, deps) read. An absent engine falls back to the stored engine, and
|
|
87
|
+
* a config that cannot be parsed falls back to the stored config, the same
|
|
88
|
+
* rule the POST routes apply to a broken body key.
|
|
89
|
+
*/
|
|
90
|
+
export declare function depsRequestFromUrl(url: URL): DepsRequest;
|
|
91
|
+
/**
|
|
92
|
+
* launchRequestFromBody parses the launch and stop POST body: the engine,
|
|
93
|
+
* config, and platform override the plan renders from, falling back to the
|
|
94
|
+
* stored config per key. The stop route ignores the platform key.
|
|
95
|
+
* `providerId` names the saved provider entry the launch record (or its
|
|
96
|
+
* stop's clear) targets, and `autoRebuild` carries the card's Auto Rebuild
|
|
97
|
+
* checkbox.
|
|
98
|
+
*/
|
|
99
|
+
export declare function launchRequestFromBody(body: Record<string, unknown>): LaunchRequest;
|
|
100
|
+
/**
|
|
101
|
+
* registerRequestFromBody parses the register and unregister POST body: the
|
|
102
|
+
* engine and config the plan renders from, plus agentDefault for the register
|
|
103
|
+
* route, falling back to the stored config per key.
|
|
104
|
+
*/
|
|
105
|
+
export declare function registerRequestFromBody(body: Record<string, unknown>): RegisterRequest;
|
|
106
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The request types the card's routes parse and the parsers that build them.
|
|
3
|
+
* Every request carries only the keys the card sent: absent values fall back
|
|
4
|
+
* to the stored config per key, the same rule every route applies. The
|
|
5
|
+
* parsers read a `Record<string, unknown>` body (or a URL query) and build
|
|
6
|
+
* the request with only the keys that are present, so
|
|
7
|
+
* exactOptionalPropertyTypes never sees a `key: undefined` write.
|
|
8
|
+
* @module dsh-plugin-local-infer/ui/request
|
|
9
|
+
*/
|
|
10
|
+
import { parseStoredPlatformConfig } from "./config.js";
|
|
11
|
+
/**
|
|
12
|
+
* depsRequestFromUrl parses the engine and config query params the GET routes
|
|
13
|
+
* (summary, deps) read. An absent engine falls back to the stored engine, and
|
|
14
|
+
* a config that cannot be parsed falls back to the stored config, the same
|
|
15
|
+
* rule the POST routes apply to a broken body key.
|
|
16
|
+
*/
|
|
17
|
+
export function depsRequestFromUrl(url) {
|
|
18
|
+
const request = {};
|
|
19
|
+
const engineParam = url.searchParams.get('engine');
|
|
20
|
+
if (engineParam !== null) {
|
|
21
|
+
request.engine = engineParam;
|
|
22
|
+
}
|
|
23
|
+
const configParam = url.searchParams.get('config');
|
|
24
|
+
if (configParam !== null) {
|
|
25
|
+
try {
|
|
26
|
+
request.config = JSON.parse(configParam);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// A config that cannot parse reads as absent, so the stored config wins.
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return request;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* launchRequestFromBody parses the launch and stop POST body: the engine,
|
|
36
|
+
* config, and platform override the plan renders from, falling back to the
|
|
37
|
+
* stored config per key. The stop route ignores the platform key.
|
|
38
|
+
* `providerId` names the saved provider entry the launch record (or its
|
|
39
|
+
* stop's clear) targets, and `autoRebuild` carries the card's Auto Rebuild
|
|
40
|
+
* checkbox.
|
|
41
|
+
*/
|
|
42
|
+
export function launchRequestFromBody(body) {
|
|
43
|
+
const request = {};
|
|
44
|
+
if (typeof body.engine === 'string') {
|
|
45
|
+
request.engine = body.engine;
|
|
46
|
+
}
|
|
47
|
+
if (body.config && typeof body.config === 'object') {
|
|
48
|
+
request.config = body.config;
|
|
49
|
+
}
|
|
50
|
+
const platform = parseStoredPlatformConfig(body.platform);
|
|
51
|
+
if (platform !== undefined) {
|
|
52
|
+
request.platform = platform;
|
|
53
|
+
}
|
|
54
|
+
if (typeof body.providerId === 'string' && body.providerId.trim() !== '') {
|
|
55
|
+
request.providerId = body.providerId;
|
|
56
|
+
}
|
|
57
|
+
if (typeof body.autoRebuild === 'boolean') {
|
|
58
|
+
request.autoRebuild = body.autoRebuild;
|
|
59
|
+
}
|
|
60
|
+
return request;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* registerRequestFromBody parses the register and unregister POST body: the
|
|
64
|
+
* engine and config the plan renders from, plus agentDefault for the register
|
|
65
|
+
* route, falling back to the stored config per key.
|
|
66
|
+
*/
|
|
67
|
+
export function registerRequestFromBody(body) {
|
|
68
|
+
const request = {};
|
|
69
|
+
if (typeof body.engine === 'string') {
|
|
70
|
+
request.engine = body.engine;
|
|
71
|
+
}
|
|
72
|
+
if (body.config && typeof body.config === 'object') {
|
|
73
|
+
request.config = body.config;
|
|
74
|
+
}
|
|
75
|
+
if (typeof body.agentDefault === 'boolean') {
|
|
76
|
+
request.agentDefault = body.agentDefault;
|
|
77
|
+
}
|
|
78
|
+
return request;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=request.js.map
|