@huaqiu/dsh-hardware-ui 0.7.18 → 0.7.19

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.
@@ -3,6 +3,9 @@ import { describeHostError } from './copy.js'
3
3
  import type {
4
4
  DiscoveryInfo, HardwareProjectInfo, InstallationsInfo, NativeApplication,
5
5
  } from './model.js'
6
+ import type {
7
+ BrowseOutcome, InstallJob, ToolchainId, ToolchainStatus, ToolSource, ValidationOutcome,
8
+ } from './toolchain.js'
6
9
 
7
10
  const PREFIX = '/api/v1/hardware'
8
11
 
@@ -262,20 +265,19 @@ export interface PlacedOrder {
262
265
 
263
266
  /**
264
267
  * Submit one order. `confirm` is what the host requires; the panel sets it only
265
- * after the user confirms the upload in the dialog. The host opens the order
266
- * page in the default browser unless `launch` is false.
268
+ * after the user confirms the upload in the dialog. The host never opens the
269
+ * page by itself — the client shows `orderUrl` in its own Browser tab.
267
270
  */
268
271
  export async function placeOrder(
269
272
  kind: 'pcb' | 'smt',
270
273
  requestBody: {
271
274
  path: string
272
275
  schematic?: string
273
- /** Workspace root, never the project file; the host authorizes against it. */
276
+ /** Workspace root of the panel's session; the base for a relative path. */
274
277
  cwd?: string
275
278
  session?: string
276
279
  quantity?: number
277
280
  confirm: boolean
278
- launch?: boolean
279
281
  },
280
282
  signal?: AbortSignal,
281
283
  ): Promise<PlacedOrder> {
@@ -295,3 +297,80 @@ export async function openOrderUrl(url: string): Promise<{ readonly launched: bo
295
297
  body: JSON.stringify({ url }),
296
298
  })
297
299
  }
300
+
301
+ /**
302
+ * Toolchain capability calls (`/api/v1/hardware/toolchain`).
303
+ *
304
+ * Every read is a poll: the Host owns the truth, including whether a job is
305
+ * still running, so nothing here caches. `install` is the one call that answers
306
+ * a *state* rather than a failure when a download is impossible (no manifest
307
+ * entry for this platform) — that state is the UI's cue to offer the official
308
+ * page instead (§9.2/§14.2), which is why it resolves to `undefined`.
309
+ */
310
+ /** `?job=a,b` — the panel watches both tools' runs at once, so ids travel together. */
311
+ export async function loadToolchainStatus(jobIds?: readonly string[]): Promise<ToolchainStatus> {
312
+ const ids = (jobIds ?? []).filter(id => id !== '')
313
+ const suffix = ids.length === 0 ? '' : `?job=${encodeURIComponent(ids.join(','))}`
314
+ return request<ToolchainStatus>(`/toolchain/status${suffix}`)
315
+ }
316
+
317
+ /** Validate one path without persisting it (the input's own verdict). */
318
+ export async function validateToolchain(tool: ToolchainId, path: string): Promise<ValidationOutcome> {
319
+ return request<ValidationOutcome>('/toolchain/validate', {
320
+ method: 'POST',
321
+ headers: { 'content-type': 'application/json' },
322
+ body: JSON.stringify({ tool, path }),
323
+ })
324
+ }
325
+
326
+ /** Validate and persist one path; the Host settings service stays authoritative. */
327
+ export async function saveToolchain(
328
+ tool: ToolchainId,
329
+ path: string,
330
+ source: ToolSource,
331
+ ): Promise<ValidationOutcome> {
332
+ return request<ValidationOutcome>('/toolchain/save', {
333
+ method: 'POST',
334
+ headers: { 'content-type': 'application/json' },
335
+ body: JSON.stringify({ tool, path, source }),
336
+ })
337
+ }
338
+
339
+ /** Open the Host's native chooser for one tool; a cancellation is not an error. */
340
+ export async function browseToolchain(tool: ToolchainId): Promise<BrowseOutcome> {
341
+ return request<BrowseOutcome>('/toolchain/browse', {
342
+ method: 'POST',
343
+ headers: { 'content-type': 'application/json' },
344
+ body: JSON.stringify({ tool }),
345
+ })
346
+ }
347
+
348
+ /** Start the manifest download for one tool; `undefined` means "not offered here". */
349
+ export async function installToolchain(tool: ToolchainId): Promise<InstallJob | undefined> {
350
+ const body = await request<{ readonly job?: InstallJob }>('/toolchain/install', {
351
+ method: 'POST',
352
+ headers: { 'content-type': 'application/json' },
353
+ body: JSON.stringify({ tool }),
354
+ })
355
+ return body.job
356
+ }
357
+
358
+ /** Cancel one running job; the Host reports whether it was still cancellable. */
359
+ export async function cancelToolchain(id: string): Promise<boolean> {
360
+ const body = await request<{ readonly cancelled?: boolean }>('/toolchain/cancel', {
361
+ method: 'POST',
362
+ headers: { 'content-type': 'application/json' },
363
+ body: JSON.stringify({ id }),
364
+ })
365
+ return body.cancelled === true
366
+ }
367
+
368
+ /** Start background discovery (answers immediately, verdicts arrive by poll). */
369
+ export async function startToolchainDiscovery(tool?: ToolchainId): Promise<void> {
370
+ await request('/toolchain/discover', {
371
+ method: 'POST',
372
+ headers: { 'content-type': 'application/json' },
373
+ body: JSON.stringify(tool === undefined ? {} : { tool }),
374
+ })
375
+ }
376
+