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.
Files changed (251) hide show
  1. package/README.md +32 -6
  2. package/cordis.patch.yml +7 -0
  3. package/docs/zh/README.md +24 -4
  4. package/dsh/client.js +4200 -4049
  5. package/package.json +33 -11
  6. package/packages/core/lib/adapter.d.ts +177 -11
  7. package/packages/core/lib/adapter.js +74 -1
  8. package/packages/core/lib/config.d.ts +1 -1
  9. package/packages/core/lib/config.js +1 -1
  10. package/packages/core/lib/debug.d.ts +1 -1
  11. package/packages/core/lib/debug.js +1 -1
  12. package/packages/core/lib/defaults.d.ts +1 -1
  13. package/packages/core/lib/defaults.js +1 -1
  14. package/packages/core/lib/deps.d.ts +48 -20
  15. package/packages/core/lib/deps.js +24 -8
  16. package/packages/core/lib/estimator.d.ts +1 -1
  17. package/packages/core/lib/estimator.js +1 -1
  18. package/packages/core/lib/guideline.d.ts +1 -1
  19. package/packages/core/lib/guideline.js +1 -1
  20. package/packages/core/lib/hardware.d.ts +1 -1
  21. package/packages/core/lib/hardware.js +1 -1
  22. package/packages/core/lib/hf-cache.d.ts +70 -0
  23. package/packages/core/lib/hf-cache.js +83 -0
  24. package/packages/core/lib/index.d.ts +16 -9
  25. package/packages/core/lib/index.js +10 -6
  26. package/packages/core/lib/infer-cache.d.ts +39 -0
  27. package/packages/core/lib/infer-cache.js +53 -0
  28. package/packages/core/lib/launch-command.d.ts +8 -4
  29. package/packages/core/lib/launch-command.js +13 -6
  30. package/packages/core/lib/launch-record.d.ts +1 -1
  31. package/packages/core/lib/launch-record.js +1 -1
  32. package/packages/core/lib/logs.d.ts +8 -1
  33. package/packages/core/lib/logs.js +12 -4
  34. package/packages/core/lib/models.d.ts +120 -14
  35. package/packages/core/lib/models.js +209 -17
  36. package/packages/core/lib/parameter.d.ts +31 -3
  37. package/packages/core/lib/parameter.js +1 -1
  38. package/packages/core/lib/progress.d.ts +54 -0
  39. package/packages/core/lib/progress.js +120 -0
  40. package/packages/core/lib/registrar.d.ts +25 -14
  41. package/packages/core/lib/registrar.js +30 -10
  42. package/packages/core/lib/reserve.d.ts +11 -3
  43. package/packages/core/lib/reserve.js +6 -4
  44. package/packages/core/lib/status.d.ts +12 -6
  45. package/packages/core/lib/status.js +21 -10
  46. package/packages/core/lib/sudo.d.ts +80 -0
  47. package/packages/core/lib/sudo.js +78 -0
  48. package/packages/core/package.json +1 -1
  49. package/packages/orchestrator/lib/config.d.ts +63 -0
  50. package/packages/orchestrator/lib/config.js +111 -0
  51. package/packages/orchestrator/lib/index.d.ts +51 -0
  52. package/packages/orchestrator/lib/index.js +73 -0
  53. package/packages/orchestrator/lib/route.d.ts +60 -0
  54. package/packages/orchestrator/lib/route.js +159 -0
  55. package/packages/orchestrator/locale/en.json +6 -0
  56. package/packages/orchestrator/package.json +39 -0
  57. package/packages/orchestrator/prompt.md +87 -0
  58. package/packages/providers/lib/acquire.d.ts +95 -15
  59. package/packages/providers/lib/acquire.js +239 -40
  60. package/packages/providers/lib/adapters.d.ts +155 -221
  61. package/packages/providers/lib/adapters.js +589 -935
  62. package/packages/providers/lib/debug.d.ts +1 -1
  63. package/packages/providers/lib/debug.js +1 -1
  64. package/packages/providers/lib/deps.d.ts +31 -212
  65. package/packages/providers/lib/deps.js +71 -205
  66. package/packages/providers/lib/engines/basalt/basalt.d.ts +130 -0
  67. package/packages/providers/lib/engines/basalt/basalt.js +304 -0
  68. package/packages/providers/lib/engines/basalt/basaltAdapter.d.ts +85 -0
  69. package/packages/providers/lib/engines/basalt/basaltAdapter.js +439 -0
  70. package/packages/providers/lib/engines/basalt/basaltLinux.d.ts +23 -0
  71. package/packages/providers/lib/engines/basalt/basaltLinux.js +47 -0
  72. package/packages/providers/lib/engines/basalt/basaltMacOS.d.ts +17 -0
  73. package/packages/providers/lib/engines/basalt/basaltMacOS.js +19 -0
  74. package/packages/providers/lib/engines/basalt/basaltWindows.d.ts +24 -0
  75. package/packages/providers/lib/engines/basalt/basaltWindows.js +49 -0
  76. package/packages/providers/lib/engines/engineOs.d.ts +24 -0
  77. package/packages/providers/lib/engines/engineOs.js +17 -0
  78. package/packages/providers/lib/{hyperqwen.d.ts → engines/hyperqwen/hyperqwen.d.ts} +2 -2
  79. package/packages/providers/lib/{hyperqwen.js → engines/hyperqwen/hyperqwen.js} +14 -2
  80. package/packages/providers/lib/engines/hyperqwen/hyperqwenAdapter.d.ts +38 -0
  81. package/packages/providers/lib/engines/hyperqwen/hyperqwenAdapter.js +115 -0
  82. package/packages/providers/lib/engines/hyperqwen/hyperqwenArch.d.ts +9 -0
  83. package/packages/providers/lib/engines/hyperqwen/hyperqwenArch.js +9 -0
  84. package/packages/providers/lib/engines/hyperqwen/hyperqwenDebian.d.ts +9 -0
  85. package/packages/providers/lib/engines/hyperqwen/hyperqwenDebian.js +9 -0
  86. package/packages/providers/lib/engines/hyperqwen/hyperqwenFedora.d.ts +9 -0
  87. package/packages/providers/lib/engines/hyperqwen/hyperqwenFedora.js +9 -0
  88. package/packages/providers/lib/engines/hyperqwen/hyperqwenLinux.d.ts +10 -0
  89. package/packages/providers/lib/engines/hyperqwen/hyperqwenLinux.js +14 -0
  90. package/packages/providers/lib/engines/hyperqwen/hyperqwenMacOS.d.ts +9 -0
  91. package/packages/providers/lib/engines/hyperqwen/hyperqwenMacOS.js +9 -0
  92. package/packages/providers/lib/engines/hyperqwen/hyperqwenWindows.d.ts +9 -0
  93. package/packages/providers/lib/engines/hyperqwen/hyperqwenWindows.js +9 -0
  94. package/packages/providers/lib/{infernix.d.ts → engines/infernix/infernix.d.ts} +7 -4
  95. package/packages/providers/lib/{infernix.js → engines/infernix/infernix.js} +53 -8
  96. package/packages/providers/lib/engines/infernix/infernixAdapter.d.ts +52 -0
  97. package/packages/providers/lib/engines/infernix/infernixAdapter.js +235 -0
  98. package/packages/providers/lib/engines/infernix/infernixArch.d.ts +9 -0
  99. package/packages/providers/lib/engines/infernix/infernixArch.js +9 -0
  100. package/packages/providers/lib/engines/infernix/infernixDebian.d.ts +9 -0
  101. package/packages/providers/lib/engines/infernix/infernixDebian.js +9 -0
  102. package/packages/providers/lib/engines/infernix/infernixFedora.d.ts +9 -0
  103. package/packages/providers/lib/engines/infernix/infernixFedora.js +9 -0
  104. package/packages/providers/lib/engines/infernix/infernixLinux.d.ts +17 -0
  105. package/packages/providers/lib/engines/infernix/infernixLinux.js +35 -0
  106. package/packages/providers/lib/engines/infernix/infernixMacOS.d.ts +16 -0
  107. package/packages/providers/lib/engines/infernix/infernixMacOS.js +18 -0
  108. package/packages/providers/lib/engines/infernix/infernixWindows.d.ts +16 -0
  109. package/packages/providers/lib/engines/infernix/infernixWindows.js +34 -0
  110. package/packages/providers/lib/{llamacpp.d.ts → engines/llamacpp/llamacpp.d.ts} +2 -2
  111. package/packages/providers/lib/{llamacpp.js → engines/llamacpp/llamacpp.js} +12 -2
  112. package/packages/providers/lib/engines/llamacpp/llamacppAdapter.d.ts +50 -0
  113. package/packages/providers/lib/engines/llamacpp/llamacppAdapter.js +274 -0
  114. package/packages/providers/lib/engines/llamacpp/llamacppArch.d.ts +9 -0
  115. package/packages/providers/lib/engines/llamacpp/llamacppArch.js +9 -0
  116. package/packages/providers/lib/engines/llamacpp/llamacppDebian.d.ts +9 -0
  117. package/packages/providers/lib/engines/llamacpp/llamacppDebian.js +9 -0
  118. package/packages/providers/lib/engines/llamacpp/llamacppFedora.d.ts +9 -0
  119. package/packages/providers/lib/engines/llamacpp/llamacppFedora.js +9 -0
  120. package/packages/providers/lib/engines/llamacpp/llamacppLinux.d.ts +17 -0
  121. package/packages/providers/lib/engines/llamacpp/llamacppLinux.js +28 -0
  122. package/packages/providers/lib/engines/llamacpp/llamacppMacOS.d.ts +15 -0
  123. package/packages/providers/lib/engines/llamacpp/llamacppMacOS.js +17 -0
  124. package/packages/providers/lib/engines/llamacpp/llamacppWindows.d.ts +15 -0
  125. package/packages/providers/lib/engines/llamacpp/llamacppWindows.js +26 -0
  126. package/packages/providers/lib/{ninfer.d.ts → engines/ninfer/ninfer.d.ts} +2 -2
  127. package/packages/providers/lib/{ninfer.js → engines/ninfer/ninfer.js} +25 -3
  128. package/packages/providers/lib/engines/ninfer/ninferAdapter.d.ts +81 -0
  129. package/packages/providers/lib/engines/ninfer/ninferAdapter.js +392 -0
  130. package/packages/providers/lib/engines/ninfer/ninferArch.d.ts +9 -0
  131. package/packages/providers/lib/engines/ninfer/ninferArch.js +9 -0
  132. package/packages/providers/lib/engines/ninfer/ninferDebian.d.ts +9 -0
  133. package/packages/providers/lib/engines/ninfer/ninferDebian.js +9 -0
  134. package/packages/providers/lib/engines/ninfer/ninferFedora.d.ts +9 -0
  135. package/packages/providers/lib/engines/ninfer/ninferFedora.js +9 -0
  136. package/packages/providers/lib/engines/ninfer/ninferLinux.d.ts +17 -0
  137. package/packages/providers/lib/engines/ninfer/ninferLinux.js +37 -0
  138. package/packages/providers/lib/engines/ninfer/ninferMacOS.d.ts +15 -0
  139. package/packages/providers/lib/engines/ninfer/ninferMacOS.js +17 -0
  140. package/packages/providers/lib/engines/ninfer/ninferWindows.d.ts +29 -0
  141. package/packages/providers/lib/engines/ninfer/ninferWindows.js +59 -0
  142. package/packages/providers/lib/engines/strata/strata.d.ts +1 -0
  143. package/packages/providers/lib/engines/strata/strata.js +264 -0
  144. package/packages/providers/lib/engines/strata/strataAdapter.d.ts +97 -0
  145. package/packages/providers/lib/engines/strata/strataAdapter.js +463 -0
  146. package/packages/providers/lib/engines/strata/strataArch.d.ts +9 -0
  147. package/packages/providers/lib/engines/strata/strataArch.js +9 -0
  148. package/packages/providers/lib/engines/strata/strataDebian.d.ts +9 -0
  149. package/packages/providers/lib/engines/strata/strataDebian.js +9 -0
  150. package/packages/providers/lib/engines/strata/strataFedora.d.ts +9 -0
  151. package/packages/providers/lib/engines/strata/strataFedora.js +9 -0
  152. package/packages/providers/lib/engines/strata/strataLinux.d.ts +21 -0
  153. package/packages/providers/lib/engines/strata/strataLinux.js +30 -0
  154. package/packages/providers/lib/engines/strata/strataMacOS.d.ts +16 -0
  155. package/packages/providers/lib/engines/strata/strataMacOS.js +17 -0
  156. package/packages/providers/lib/engines/strata/strataWindows.d.ts +27 -0
  157. package/packages/providers/lib/engines/strata/strataWindows.js +37 -0
  158. package/packages/providers/lib/engines.d.ts +8 -5
  159. package/packages/providers/lib/engines.js +22 -11
  160. package/packages/providers/lib/guidelines.d.ts +5 -4
  161. package/packages/providers/lib/guidelines.js +18 -5
  162. package/packages/providers/lib/index.d.ts +33 -24
  163. package/packages/providers/lib/index.js +46 -24
  164. package/packages/providers/lib/model-defaults.d.ts +10 -5
  165. package/packages/providers/lib/model-defaults.js +47 -5
  166. package/packages/providers/lib/platform.d.ts +8 -5
  167. package/packages/providers/lib/platform.js +27 -7
  168. package/packages/providers/lib/presets.d.ts +6 -4
  169. package/packages/providers/lib/presets.js +53 -5
  170. package/packages/providers/lib/systemDeps.d.ts +313 -0
  171. package/packages/providers/lib/systemDeps.js +284 -0
  172. package/packages/providers/lib/vram.d.ts +34 -8
  173. package/packages/providers/lib/vram.js +81 -8
  174. package/packages/providers/package.json +2 -2
  175. package/packages/service/lib/index.d.ts +187 -23
  176. package/packages/service/lib/index.js +667 -90
  177. package/packages/service/lib/launch-target.d.ts +19 -0
  178. package/packages/service/lib/launch-target.js +28 -0
  179. package/packages/service/lib/run-logs.d.ts +72 -0
  180. package/packages/service/lib/run-logs.js +125 -0
  181. package/packages/service/lib/types.d.ts +166 -8
  182. package/packages/service/lib/types.js +1 -1
  183. package/packages/service/package.json +2 -2
  184. package/packages/tool/lib/index.d.ts +1 -1
  185. package/packages/tool/lib/index.js +1 -1
  186. package/packages/tool/package.json +2 -2
  187. package/packages/ui/lib/config.d.ts +89 -0
  188. package/packages/ui/lib/config.js +251 -0
  189. package/packages/ui/lib/deps.d.ts +4 -4
  190. package/packages/ui/lib/deps.js +1 -1
  191. package/packages/ui/lib/form.d.ts +1 -1
  192. package/packages/ui/lib/form.js +1 -1
  193. package/packages/ui/lib/index.d.ts +7 -1
  194. package/packages/ui/lib/index.js +12 -2
  195. package/packages/ui/lib/meter.d.ts +1 -1
  196. package/packages/ui/lib/meter.js +1 -1
  197. package/packages/ui/lib/ops/engine.d.ts +216 -0
  198. package/packages/ui/lib/ops/engine.js +697 -0
  199. package/packages/ui/lib/ops/get-steps.d.ts +98 -0
  200. package/packages/ui/lib/ops/get-steps.js +359 -0
  201. package/packages/ui/lib/ops/hf.d.ts +42 -0
  202. package/packages/ui/lib/ops/hf.js +150 -0
  203. package/packages/ui/lib/ops/logs.d.ts +78 -0
  204. package/packages/ui/lib/ops/logs.js +119 -0
  205. package/packages/ui/lib/ops/model.d.ts +71 -0
  206. package/packages/ui/lib/ops/model.js +123 -0
  207. package/packages/ui/lib/request.d.ts +106 -0
  208. package/packages/ui/lib/request.js +80 -0
  209. package/packages/ui/lib/route.d.ts +106 -422
  210. package/packages/ui/lib/route.js +136 -1845
  211. package/packages/ui/lib/routes/chat-template.d.ts +1 -0
  212. package/packages/ui/lib/routes/chat-template.js +1 -0
  213. package/packages/ui/lib/routes/deps.d.ts +1 -0
  214. package/packages/ui/lib/routes/deps.js +1 -0
  215. package/packages/ui/lib/routes/download.d.ts +1 -0
  216. package/packages/ui/lib/routes/download.js +1 -0
  217. package/packages/ui/lib/routes/get.d.ts +1 -0
  218. package/packages/ui/lib/routes/get.js +106 -0
  219. package/packages/ui/lib/routes/install.d.ts +16 -0
  220. package/packages/ui/lib/routes/install.js +36 -0
  221. package/packages/ui/lib/routes/launch.d.ts +24 -0
  222. package/packages/ui/lib/routes/launch.js +74 -0
  223. package/packages/ui/lib/routes/logs.d.ts +57 -0
  224. package/packages/ui/lib/routes/logs.js +117 -0
  225. package/packages/ui/lib/routes/provider-delete.d.ts +15 -0
  226. package/packages/ui/lib/routes/provider-delete.js +37 -0
  227. package/packages/ui/lib/routes/register.d.ts +16 -0
  228. package/packages/ui/lib/routes/register.js +28 -0
  229. package/packages/ui/lib/routes/save.d.ts +18 -0
  230. package/packages/ui/lib/routes/save.js +159 -0
  231. package/packages/ui/lib/routes/stop.d.ts +19 -0
  232. package/packages/ui/lib/routes/stop.js +32 -0
  233. package/packages/ui/lib/routes/stream.d.ts +40 -0
  234. package/packages/ui/lib/routes/stream.js +68 -0
  235. package/packages/ui/lib/routes/summary.d.ts +15 -0
  236. package/packages/ui/lib/routes/summary.js +26 -0
  237. package/packages/ui/lib/routes/unregister.d.ts +14 -0
  238. package/packages/ui/lib/routes/unregister.js +26 -0
  239. package/packages/ui/lib/viewmodels/deps.d.ts +1 -0
  240. package/packages/ui/lib/viewmodels/deps.js +1 -0
  241. package/packages/ui/lib/viewmodels/depsHelpers.d.ts +1 -0
  242. package/packages/ui/lib/viewmodels/depsHelpers.js +94 -0
  243. package/packages/ui/lib/viewmodels/summary.d.ts +145 -0
  244. package/packages/ui/lib/viewmodels/summary.js +245 -0
  245. package/packages/ui/lib/viewmodels/summaryHelpers.d.ts +30 -0
  246. package/packages/ui/lib/viewmodels/summaryHelpers.js +42 -0
  247. package/packages/ui/lib/warnings.d.ts +1 -1
  248. package/packages/ui/lib/warnings.js +1 -1
  249. package/packages/ui/package.json +4 -4
  250. package/packages/providers/lib/strata.d.ts +0 -15
  251. package/packages/providers/lib/strata.js +0 -14
@@ -12,27 +12,38 @@
12
12
  * ~/.dsh/local-infer/config.json, shared with the CLI, so the browser never
13
13
  * sees a secret it did not store. The routes are held by an effect, so they
14
14
  * go when the plugin does.
15
+ *
16
+ * This module holds the HTTP plumbing every route builds on: the RouteError
17
+ * the domain operations throw with their own status, the RouteResponder the
18
+ * handlers answer through, and defineRoute, the template method that guards
19
+ * the method (405), reads the bounded body (413), and maps the handler's
20
+ * answer to a status. The request parsing lives in ./request.ts, the stored-
21
+ * config persistence in ./config.ts, the view models in ./viewmodels/, the
22
+ * operations in ./ops/, and each route definition in its own file under
23
+ * ./routes/. registerLocalInferRoute wires them onto the web server.
15
24
  * @module dsh-plugin-local-infer/ui/route
16
25
  */
17
26
  import type { Context } from '@deepseek-ai/cordis';
18
- import type { Config, DefaultProvenance, HardwareProfile, InstallResult, LaunchStep, LifecycleHost, ProviderLaunchRecord, ProviderStatus, RegisterResult, VramModel, VramVerdict } from 'dsh-plugin-local-infer/core';
19
- import type { DownloadResult, EngineDeathEvent, LaunchResult, LocalInferService } from 'dsh-plugin-local-infer/service';
20
- import type { EngineInfo } from '../../providers/lib/index.js';
21
- import type { DepsModel } from './deps.ts';
22
- import type { FormModel } from './form.ts';
23
- import type { MeterModel } from './meter.ts';
24
- import type { WarningsModel } from './warnings.ts';
27
+ import type { LifecycleHost } from 'dsh-plugin-local-infer/core';
28
+ import type { LocalInferService } from 'dsh-plugin-local-infer/service';
29
+ /**
30
+ * LocalInferRoute is one webServer route definition the register step holds
31
+ * by an effect: the stable name, the exact-match path, and the handler the
32
+ * web server invokes per request. The route files under ./routes/ each build
33
+ * one of these through defineRoute.
34
+ */
35
+ export interface LocalInferRoute {
36
+ name: string;
37
+ kind: 'exact';
38
+ path: string;
39
+ handler: (req: IncomingLike, res: OutgoingLike) => void | Promise<void>;
40
+ }
25
41
  /**
26
42
  * The webServer service is dsh-specific and absent from the cordis Context
27
43
  * type, so the route narrows the scoped context to the two members it needs.
28
44
  */
29
45
  export interface WebServerService {
30
- register(route: {
31
- name: string;
32
- kind: 'exact';
33
- path: string;
34
- handler: (req: IncomingLike, res: OutgoingLike) => void | Promise<void>;
35
- }): () => void;
46
+ register(route: LocalInferRoute): () => void;
36
47
  }
37
48
  interface IncomingLike extends AsyncIterable<Buffer> {
38
49
  method: string;
@@ -49,198 +60,15 @@ interface OutgoingLike {
49
60
  */
50
61
  write?(chunk: string): unknown;
51
62
  end(body?: string): void;
63
+ /**
64
+ * Optional: watch the response for the client disconnecting (the node
65
+ * ServerResponse's 'close' before the route ends), so a stream route can
66
+ * abort the in-flight run when the card cancels it. The web server hands
67
+ * the handler a node ServerResponse; the tests' fake may omit it, and the
68
+ * route degrades to no abort.
69
+ */
70
+ on?(event: string, listener: (...args: unknown[]) => void): unknown;
52
71
  }
53
- /**
54
- * LocalInferSummary is the JSON the card renders: the engine list, the model
55
- * list, the detected hardware, the form model for the selected engine, the
56
- * meter model for the current config, the verdict the banner renders, the
57
- * guideline warning model the red banner and inline warnings render from,
58
- * and the config the form edits. Every field is plain data, so it crosses
59
- * the socket without a function left behind.
60
- */
61
- export interface LocalInferSummary {
62
- engines: {
63
- id: string;
64
- label: string;
65
- supports: {
66
- docker: boolean;
67
- local: boolean;
68
- };
69
- defaultBuildCommand?: string;
70
- defaultDockerTag?: string;
71
- }[];
72
- models: {
73
- id: string;
74
- source: string;
75
- }[];
76
- hardware: HardwareProfile;
77
- engineId: string;
78
- formModel: FormModel;
79
- meterModel: MeterModel;
80
- verdict: VramVerdict;
81
- warningsModel: WarningsModel;
82
- config: Config;
83
- platformConfigs: Record<string, StoredPlatformConfig>;
84
- defaults: DefaultsModel;
85
- modelDirectory: string;
86
- modelDefaults: ModelDefaultModel[];
87
- modelStatus: ModelStatusModel | null;
88
- chatTemplateStatus: ChatTemplateStatusModel | null;
89
- modelFiles: string[];
90
- showHelp: boolean;
91
- providers: ProviderSummaryEntry[];
92
- logPath: string;
93
- lastLogs: string;
94
- unsureBanner: {
95
- message: string;
96
- killCommands: string[];
97
- } | null;
98
- registered: boolean;
99
- }
100
- /**
101
- * ProviderSummaryEntry is the card-facing view of one saved provider config:
102
- * the stable id the card edits and deletes against, the engine and model the
103
- * title renders ("NInfer: <model>"), the running-state the status dot paints,
104
- * and the full config and platform the expanded form draws from.
105
- */
106
- export interface ProviderSummaryEntry {
107
- id: string;
108
- engine: string;
109
- model: string;
110
- status: ProviderStatus;
111
- config: Config;
112
- platform: StoredPlatformConfig;
113
- }
114
- /**
115
- * ModelDefaultModel is the card-facing view of one default model entry: the
116
- * registry key the config `model` field carries, the label the dropdown
117
- * shows, and the Hugging Face URL the no-CLI row links to.
118
- */
119
- export interface ModelDefaultModel {
120
- id: string;
121
- label: string;
122
- url: string;
123
- }
124
- /**
125
- * ModelStatusModel is the model-status read model the card draws: whether the
126
- * model is present in the model directory, whether the hf CLI is available,
127
- * and the download command the Download button runs. The card shows the row
128
- * only while the model is absent.
129
- */
130
- export interface ModelStatusModel {
131
- modelId: string;
132
- label: string;
133
- url: string;
134
- present: boolean;
135
- hfCli: boolean;
136
- downloadCommand: string;
137
- }
138
- /**
139
- * ChatTemplateStatusModel is the answer to "is the selected chat template in
140
- * the model directory": the repo reference, its display label, whether the
141
- * template file is present, whether the hf CLI is available, and the download
142
- * command the card runs (and the System dependencies box shows when the auto-
143
- * download is unavailable).
144
- */
145
- export interface ChatTemplateStatusModel {
146
- repo: string;
147
- label: string;
148
- present: boolean;
149
- hfCli: boolean;
150
- downloadCommand: string;
151
- }
152
- /**
153
- * DefaultsModel is the resolved-defaults read model the card draws: the
154
- * starting config the defaults resolver produced and the per-key provenance
155
- * that names the source that supplied each value (a preset, the user, or a
156
- * spec default).
157
- */
158
- export interface DefaultsModel {
159
- config: Config;
160
- provenance: DefaultProvenance[];
161
- }
162
- /**
163
- * The config file the route owns. It sits under the dsh home so a web user and
164
- * a CLI user share one file, the way modsearch shares ~/.modsearch.
165
- */
166
- export declare function localInferConfigPath(): string;
167
- /**
168
- * StoredPlatformConfig is the per-engine platform config the deploy step
169
- * consumes (§3.10): where the engine platform lives locally and the git repo
170
- * that overrides the engine's default upstream. The map is keyed by engine id,
171
- * so the stored entry carries no id of its own; the route adds it when it
172
- * builds the EnginePlatformConfig the service registry stores.
173
- */
174
- export interface StoredPlatformConfig {
175
- engineDirectory?: string;
176
- engineFork?: string;
177
- buildCommands?: string;
178
- dockerTag?: string;
179
- }
180
- /**
181
- * StoredProviderConfig is one saved provider model+engine config the card
182
- * lists: a stable id the card edits and deletes against, the engine and the
183
- * full parameter config it serves, the per-engine platform config the deploy
184
- * step consumes, and the launch record the launch step persists when it
185
- * starts the entry's engine (the engine pid, start time, launch arguments,
186
- * and the DSH process pid that launched it). The record is what a DSH
187
- * restart re-links a surviving engine to its config; a stop clears it.
188
- */
189
- export interface StoredProviderConfig {
190
- id: string;
191
- engine: string;
192
- config: Config;
193
- platform: StoredPlatformConfig;
194
- launch?: ProviderLaunchRecord;
195
- }
196
- export interface StoredConfig {
197
- engine: string;
198
- config: Config;
199
- allowRunDeps: boolean;
200
- platform: Record<string, StoredPlatformConfig>;
201
- showHelp: boolean;
202
- providers: StoredProviderConfig[];
203
- logPath: string;
204
- lastLogs: string;
205
- }
206
- /**
207
- * readConfig reads the stored engine, config, trust gate, and per-engine
208
- * platform configs. A missing or broken file reads as the scaffold default
209
- * (NInfer, empty config, gate off, no platform configs) so the card always has
210
- * a form to draw. A platform entry that is not an object (or whose fields are
211
- * not strings) is dropped, so a by-hand edit never poisons the deploy step.
212
- */
213
- export declare function readConfig(): StoredConfig;
214
- /**
215
- * writeConfig persists the engine, config, trust gate, per-engine platform
216
- * configs, and the help toggle, creating the directory tree on first write.
217
- */
218
- export declare function writeConfig(engine: string, config: Config, allowRunDeps: boolean, platform?: Record<string, StoredPlatformConfig>, showHelp?: boolean, providers?: StoredProviderConfig[], logPath?: string, lastLogs?: string): void;
219
- /**
220
- * relinkStoredProviders prices every stored provider launch record against the
221
- * live process table through the service's re-link rule and returns the
222
- * provider list the card should read: an adopted engine is re-marked plugin-
223
- * launched and tied to its model by the service, and a liveness watcher starts
224
- * on its port so a later pkill settles the stored state through the death
225
- * observer without another summary read; a dead engine's record is cleared on
226
- * disk here (the previous-pid list with it), so a recycled pid cannot re-link
227
- * to a config whose engine is down. The route calls it on mount and the
228
- * summary calls it per read, making re-attach independent of the card opening.
229
- */
230
- export declare function relinkStoredProviders(localInfer: LocalInferService, stored: StoredConfig): Promise<StoredProviderConfig[]>;
231
- /**
232
- * buildSummary assembles the card's read model for one engine and config: the
233
- * static engine and model lists, the detected hardware, the form model the
234
- * selected engine's parameter surface renders to, the meter model the
235
- * service's estimate prices, and the warning model the service's guideline
236
- * engine fires. The estimate is the single source the meter and the verdict
237
- * banner agree on, and the guideline results are the single source the red
238
- * banner and the inline warnings agree on.
239
- */
240
- export declare function buildSummary(localInfer: LocalInferService, request?: {
241
- engine?: string;
242
- config?: Config;
243
- }): Promise<LocalInferSummary>;
244
72
  /**
245
73
  * RouteError is a route failure that carries its own HTTP status, so the
246
74
  * handlers map the domain answer (a gate that is off, an unsupported build
@@ -251,227 +79,83 @@ export declare class RouteError extends Error {
251
79
  constructor(status: number, message: string);
252
80
  }
253
81
  /**
254
- * DepsRequest is the query the card sends for the deps panel: the engine and
255
- * the config the build mode reads from. Absent values fall back to the stored
256
- * config, the same rule the summary route applies.
257
- */
258
- export interface DepsRequest {
259
- engine?: string;
260
- config?: Config;
261
- }
262
- /**
263
- * resolveBuildMode picks the deploy mode the dep plan prices: the config's
264
- * buildMode when the selected engine supports it, else the engine's default
265
- * (local when the engine can build locally, docker when it cannot). The
266
- * docker-not-installed guideline reads this same value, so the panel and the
267
- * warning never disagree about the mode.
268
- */
269
- export declare function resolveBuildMode(engine: EngineInfo, config: Config): 'docker' | 'local';
270
- /**
271
- * buildDeps assembles the deps panel read model for one engine and config:
272
- * the detected hardware (with its package manager), the dep plan the service
273
- * resolves, the per-dep statuses, the copy/paste install string, and the
274
- * Play/Run trust gate the stored config carries.
275
- */
276
- export declare function buildDeps(localInfer: LocalInferService, request?: DepsRequest): Promise<DepsModel>;
277
- /**
278
- * InstallResponse is the answer to a Play/Run: the install result and the
279
- * refreshed deps model, so the card re-renders the gate from the same
280
- * re-check the install ran.
281
- */
282
- export interface InstallResponse {
283
- result: InstallResult;
284
- deps: DepsModel;
285
- }
286
- /**
287
- * runInstallFor is the Play/Run path: it refuses with a 409 while the
288
- * trust gate is off (the copy/paste path is always the fallback), runs the
289
- * install through the service, and refreshes the deps model from the
290
- * re-check, so the "Get" gate opens only after a re-check passes.
291
- */
292
- export declare function runInstallFor(localInfer: LocalInferService, request: DepsRequest): Promise<InstallResponse>;
293
- /**
294
- * DownloadRequest is the query the card sends for the download route: the
295
- * engine, model, and directory the hf CLI download targets. Absent values
296
- * fall back to the stored config, the same rule the summary route applies.
297
- */
298
- export interface DownloadRequest {
299
- engine?: string;
300
- model?: string;
301
- directory?: string;
302
- }
303
- /**
304
- * downloadFor runs the hf CLI download for the request's default model: it
305
- * resolves the entry through the providers' default list (a 404 when no
306
- * entry names the pair), resolves the directory against the request, the
307
- * stored config, and the plugin's default model directory in that order, and
308
- * runs the download through the service.
309
- */
310
- export declare function downloadFor(localInfer: LocalInferService, request: DownloadRequest): Promise<DownloadResult>;
311
- /**
312
- * ChatTemplateDownloadRequest is the query the card sends for the chat-template
313
- * download route: the engine, the template repo reference, and the directory
314
- * the hf CLI targets. Absent values fall back to the stored config, the same
315
- * rule the summary route applies.
316
- */
317
- export interface ChatTemplateDownloadRequest {
318
- engine?: string;
319
- template?: string;
320
- directory?: string;
321
- }
322
- /**
323
- * chatTemplateDownloadFor runs the hf CLI download for the request's chat
324
- * template: it resolves the template repo reference from the request or the
325
- * stored config's chatTemplate (a 400 when neither names an HF repo
326
- * reference), resolves the directory against the request, the stored config,
327
- * and the plugin's default model directory in that order, and runs the
328
- * download through the service.
329
- */
330
- export declare function chatTemplateDownloadFor(localInfer: LocalInferService, request: ChatTemplateDownloadRequest): Promise<DownloadResult>;
331
- /**
332
- * LaunchRequest is the query the card sends for the launch and stop routes: the
333
- * engine and the config the plan renders from. `platform` carries the card's
334
- * unsaved Engine Directory / Engine Fork edits for the engine, so a launch uses
335
- * them without a prior save. `providerId` names the saved provider entry the
336
- * launch drives, so the route persists the launch record (or clears it on a
337
- * stop) on that entry. `autoRebuild` is the card's "Auto Rebuild" checkbox:
338
- * when false, the deploy step skips the git sync (fetch, rebase, rebuild) and
339
- * launches the checkout as-is. Absent values fall back to the stored config,
340
- * the same rule the summary route applies.
341
- */
342
- export interface LaunchRequest {
343
- engine?: string;
344
- config?: Config;
345
- platform?: StoredPlatformConfig;
346
- providerId?: string;
347
- autoRebuild?: boolean;
348
- }
349
- /**
350
- * launchEngine renders the plan the registered adapter produces for the config
351
- * and the detected hardware, then runs the service's launch entry point
352
- * (deploy, then the health poll). The detail the launch returns names the
353
- * broken step when the engine does not come up. The launch line (the engine
354
- * binary and its arguments) leads the run logs the card's Logs section and
355
- * the log file carry, so a broken setup diagnoses against the exact child
356
- * process the launch started. The launch step persists the
357
- * launch record (the engine pid, start time, launch arguments, and the DSH
358
- * process pid that launched it) on the request's provider entry, so a DSH
359
- * restart can re-link a surviving engine to its config.
360
- */
361
- export declare function launchEngine(localInfer: LocalInferService, request: LaunchRequest, onProgress?: (step: LaunchStep) => void): Promise<LaunchResult>;
362
- /**
363
- * handleEngineDeath persists a provider entry's state when its engine process
364
- * dies outside the plugin's stop path: a crash, a pkill of a plugin-launched
365
- * child seen through the service's exit watch, or the poll-detected exit of a
366
- * process adopted after a DSH restart. The entry whose launch record names the
367
- * dead pid (or the dead engine-and-port, when the report carries no pid match)
368
- * has its record cleared, so a restart never re-links a dead pid, and the exit
369
- * line lands in the card's last-run logs beside the engine's own output. An
370
- * event that matches no entry carrying a record (a stop the route already
371
- * cleared, an engine the plugin never tracked) is a no-op, which keeps an
372
- * expected stop quiet.
373
- */
374
- export declare function handleEngineDeath(event: EngineDeathEvent): void;
375
- /**
376
- * persistLaunchLogs stores a launch's captured output as the last run and
377
- * writes it to the configured log file. The log file is only written when the
378
- * run produced output and the log location is set; the last-run logs are always
379
- * persisted (an empty string clears a stale run) so the card's Logs section
380
- * shows the previous run after a reload.
381
- */
382
- export declare function persistLaunchLogs(result: LaunchResult, engineId: string, config: Config): void;
383
- /**
384
- * stopEngine renders the same plan and runs the service's stop entry point, so
385
- * the stop step targets the exact container or process the launch started. The
386
- * stop then clears the target entry's launch record (the engine pid and the
387
- * previous-pid list with it), so a recycled pid cannot re-link an engine the
388
- * user just stopped.
389
- */
390
- export declare function stopEngine(localInfer: LocalInferService, request: LaunchRequest): Promise<void>;
391
- /**
392
- * GetRequest is the query the card sends for the Get route: the engine and
393
- * the config the dep plan and the build mode read from, and the platform
394
- * override (the card's unsaved Engine Directory / Engine Fork edits), the
395
- * same rule the launch request applies. Absent values fall back to the
396
- * stored config.
397
- */
398
- export interface GetRequest {
399
- engine?: string;
400
- config?: Config;
401
- platform?: StoredPlatformConfig;
402
- }
403
- /**
404
- * getEngine is the Get step: it syncs the engine checkout (clone the git
405
- * repo, or the fork when the platform entry provides one; fetch and rebase
406
- * a clean checkout; abort with a Logs alert when the checkout has local
407
- * changes), runs the system dependency plan, and runs the engine's build
408
- * steps. Every command and its output streams through log as it lands, so
409
- * the card appends it to the Logs section live. The dependency install only
410
- * runs while the Play/Run trust gate is on; with the gate off the deps are
411
- * re-checked and a missing one aborts the step with the copy/paste note.
412
- */
413
- export declare function getEngine(localInfer: LocalInferService, request: GetRequest, log: (chunk: string) => void, host?: LifecycleHost): Promise<{
414
- ok: boolean;
415
- detail?: string;
416
- }>;
417
- /**
418
- * RegisterRequest is the query the card sends for the register and
419
- * unregister routes: the engine and the config the plan renders from, and
420
- * agentDefault, which points the agent default model at the registered
421
- * engine. Absent values fall back to the stored config, the same rule the
422
- * summary route applies.
423
- */
424
- export interface RegisterRequest {
425
- engine?: string;
426
- config?: Config;
427
- agentDefault?: boolean;
82
+ * RouteResponder is the answer side of a route: the JSON writer every route
83
+ * answers through, the stream openers the Get and launch routes use for live
84
+ * output, and the chunk writer a fake response may omit (the route then
85
+ * degrades to collecting only).
86
+ */
87
+ export declare class RouteResponder {
88
+ private readonly res;
89
+ constructor(res: OutgoingLike);
90
+ /** Write a JSON answer: the status and content-type head, then the body. */
91
+ json(status: number, body: unknown): void;
92
+ /** Open a plain-text stream (the Get route's live log output). */
93
+ textStream(): void;
94
+ /** Open an NDJSON stream (the launch route's progress events). */
95
+ ndjsonStream(): void;
96
+ /** Stream one chunk; a fake response without write() collects nothing. */
97
+ write(chunk: string): void;
98
+ /**
99
+ * Watch the response's client disconnect (the node 'close' before the
100
+ * route ends): the listener fires once when the card's Cancel closes the
101
+ * stream, so the route aborts the in-flight run. A fake response without
102
+ * on() never fires it, and the run degrades to running to completion.
103
+ */
104
+ onClose(listener: () => void): void;
105
+ /** End the response, optionally with a final body chunk. */
106
+ end(body?: string): void;
428
107
  }
429
108
  /**
430
- * resolveContextWindow picks the context window the registrar publishes: the
431
- * config's maxContext when it names one, else the native ceiling of the
432
- * VramModel the config resolves to (the named model, or the single
433
- * registered model), else the 32768 spec default. The DSH contextWindow must
434
- * not promise a context the engine cannot serve, so the ceiling is the
435
- * model's own, not an optimistic number.
436
- */
437
- export declare function resolveContextWindow(config: Config, models: readonly VramModel[]): number;
438
- /**
439
- * registerFor renders the plan through the registered adapter, resolves the
440
- * model row and the context window, and runs the service's register entry
441
- * point, which upserts the provider and model through the settings seam.
442
- * The result carries the entry the registrar wrote, so the card names the
443
- * model it published.
444
- */
445
- export declare function registerFor(localInfer: LocalInferService, request?: RegisterRequest): Promise<RegisterResult>;
446
- /**
447
- * syncRegisteredModel re-runs the registration for a saved config when the
448
- * model is already registered in the DSH settings, so the registered model's
449
- * input types (the vision flag) stay in step with the saved config. A model
450
- * that is not registered (a fresh save) is a no-op, and a profile without the
451
- * settings seam throws, which the save route catches and swallows so the save
452
- * itself never fails on a sync that cannot run.
453
- */
454
- export declare function syncRegisteredModel(localInfer: LocalInferService, engine: string, config: Config): Promise<void>;
455
- /**
456
- * unregisterFor runs the service's removeModel entry point for the engine's
457
- * provider and the model row the register step resolved, so the removal
458
- * targets the exact entry the registration wrote.
459
- */
460
- export declare function unregisterFor(localInfer: LocalInferService, request?: RegisterRequest): Promise<{
461
- removed: boolean;
462
- }>;
463
- /**
464
- * registerLocalInferRoute registers the summary, save, deps, install, get,
465
- * launch, stop, register, and unregister routes on the web server and holds
466
- * them by an effect, so a bundle switch off removes them before the next
467
- * switch on re-registers. The scoped context carries the webServer; the
468
- * localInfer service is passed in because the scope only injects what it
469
- * names. The optional getHost is the lifecycle host the Get route's git and
470
- * build steps run through; it defaults to the node host, and a test injects
471
- * a stub so the route never clones a real repo in CI.
109
+ * RouteInput is what a route handler receives: the parsed URL (the query
110
+ * params the GET routes read) and, for POST routes, the bounded JSON body.
111
+ */
112
+ export interface RouteInput {
113
+ url: URL;
114
+ body: Record<string, unknown>;
115
+ }
116
+ /**
117
+ * RouteSpec is a route definition the register step holds by an effect: the
118
+ * stable name, the exact-match path, the method guard, the status an
119
+ * unexpected handler failure answers with, and the handler. The object
120
+ * literal union keeps the invariant the guard enforces: only a POST spec
121
+ * carries a 413 message, because only a POST spec reads a body.
122
+ */
123
+ export type RouteSpec = {
124
+ name: string;
125
+ path: string;
126
+ method: 'GET';
127
+ failStatus: number;
128
+ run(input: RouteInput, res: RouteResponder): Promise<void>;
129
+ } | {
130
+ name: string;
131
+ path: string;
132
+ method: 'POST';
133
+ failStatus: number;
134
+ tooLargeMessage: string;
135
+ run(input: RouteInput, res: RouteResponder): Promise<void>;
136
+ };
137
+ /**
138
+ * defineRoute is the template every route file builds on: it guards the
139
+ * method (405), reads the bounded body (413, POST only), and maps the
140
+ * handler's answer to a status: a RouteError carries its own status, any
141
+ * other failure answers with the spec's failStatus. The route files carry
142
+ * only the handler body.
143
+ */
144
+ export declare function defineRoute(spec: RouteSpec): LocalInferRoute;
145
+ /**
146
+ * registerLocalInferRoute registers the summary, save, provider-delete, deps,
147
+ * install, download, chat-template, get, launch, stop, logs, register, and
148
+ * unregister routes on the web server and holds them by an effect, so a
149
+ * bundle switch off removes them before the next switch on re-registers. The
150
+ * scoped context carries the webServer; the localInfer service is passed in
151
+ * because the scope only injects what it names. The optional getHost is the
152
+ * lifecycle host the Get route's git and build steps run through, and the
153
+ * optional launchHost the launch route's Get steps run through; both default
154
+ * to the node host, and a test injects a stub so the routes never clone a
155
+ * real repo in CI.
472
156
  */
473
157
  export declare function registerLocalInferRoute(scope: Context & {
474
158
  webServer: WebServerService;
475
- }, localInfer: LocalInferService, getHost?: LifecycleHost): void;
159
+ }, localInfer: LocalInferService, getHost?: LifecycleHost, launchHost?: LifecycleHost): void;
476
160
  export {};
477
- //# sourceMappingURL=route.d.ts.map
161
+ //# sourceMappingURL=route.d.ts.map