@huaqiu/hardware-artifacts 0.7.17 → 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.
- package/lib/index.d.mts +61 -8
- package/lib/index.mjs +2610 -6
- package/lib/routes-D78ML_ef.d.mts +438 -0
- package/lib/routes.d.mts +2 -18
- package/lib/routes.mjs +156 -41
- package/lib/{service-CtVn7z8b.d.mts → service-BGecln85.d.mts} +119 -28
- package/lib/{service-Yrc2C_eo.mjs → service-Bo58tzXv.mjs} +570 -167
- package/lib/service.d.mts +1 -1
- package/lib/service.mjs +1 -1
- package/package.json +2 -1
- package/src/index.ts +124 -5
- package/src/order.ts +22 -0
- package/src/package.ts +282 -0
- package/src/routes.ts +127 -48
- package/src/service.ts +1635 -1651
- package/src/toolchain/dialog.ts +240 -0
- package/src/toolchain/discovery.ts +266 -0
- package/src/toolchain/index.ts +36 -0
- package/src/toolchain/install.ts +430 -0
- package/src/toolchain/lzma.ts +384 -0
- package/src/toolchain/manager.ts +594 -0
- package/src/toolchain/manifest.ts +234 -0
- package/src/toolchain/resolve.ts +325 -0
- package/src/toolchain/zip.ts +495 -0
- package/src/tools.ts +470 -0
package/src/service.ts
CHANGED
|
@@ -1,1651 +1,1635 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hardware Engineering artifact model and host operations.
|
|
3
|
-
*
|
|
4
|
-
* This module deliberately has no Cordis dependency: it is the testable core
|
|
5
|
-
* behind `hardwareArtifacts`. Native project files remain authoritative; the
|
|
6
|
-
* objects here are path pointers, verified installation facts and disposable
|
|
7
|
-
* derived outputs, never a shadow project database.
|
|
8
|
-
*/
|
|
9
|
-
import { execFile, execFileSync, spawn, type ChildProcess } from 'node:child_process'
|
|
10
|
-
import { createHash } from 'node:crypto'
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync } from 'node:fs'
|
|
12
|
-
import { readFile } from 'node:fs/promises'
|
|
13
|
-
import { basename, dirname, extname, isAbsolute, join,
|
|
14
|
-
import { tmpdir } from 'node:os'
|
|
15
|
-
import {
|
|
16
|
-
DEFAULT_ORDER_BASE_URL, DEFAULT_ORDER_PAGE_BASE, multipartBody,
|
|
17
|
-
ORDER_PATHS, orderBomCsv, orderBomRows, orderIdsFromUrl, packageName, parsePositions,
|
|
18
|
-
pcbOrderForm, pcbOrderUrl, positionsCsv, readBoardFacts, readExportDirectory, smtOrderForm,
|
|
19
|
-
smtOrderUrl, smtOrderUrlFromBackend, zipPackage,
|
|
20
|
-
type BoardFacts,
|
|
21
|
-
} from './order.js'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
readonly
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
readonly
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly
|
|
48
|
-
|
|
49
|
-
readonly
|
|
50
|
-
|
|
51
|
-
readonly
|
|
52
|
-
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
readonly
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
readonly
|
|
69
|
-
readonly
|
|
70
|
-
readonly
|
|
71
|
-
readonly
|
|
72
|
-
readonly
|
|
73
|
-
readonly
|
|
74
|
-
readonly
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
readonly
|
|
86
|
-
readonly
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
readonly
|
|
93
|
-
readonly
|
|
94
|
-
readonly
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
readonly
|
|
111
|
-
readonly
|
|
112
|
-
readonly
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
readonly
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
readonly
|
|
127
|
-
readonly
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
readonly
|
|
137
|
-
readonly
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
readonly
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
readonly
|
|
146
|
-
readonly
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
readonly
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
readonly
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
readonly
|
|
170
|
-
readonly
|
|
171
|
-
readonly
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
readonly
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
readonly
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
readonly
|
|
186
|
-
readonly
|
|
187
|
-
readonly
|
|
188
|
-
readonly sessionId?: string
|
|
189
|
-
readonly quantity?: number
|
|
190
|
-
readonly signal?: AbortSignal
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
readonly
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
readonly
|
|
203
|
-
|
|
204
|
-
readonly
|
|
205
|
-
|
|
206
|
-
readonly
|
|
207
|
-
|
|
208
|
-
readonly
|
|
209
|
-
readonly
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
readonly
|
|
214
|
-
readonly
|
|
215
|
-
/**
|
|
216
|
-
readonly
|
|
217
|
-
readonly
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
readonly
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
readonly
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
:
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
const
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
)
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
this.
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
const
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
},
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
const
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
const group = groups.get(identity) ?? { references: [], fields, dnp }
|
|
1637
|
-
group.references.push(...references)
|
|
1638
|
-
groups.set(identity, group)
|
|
1639
|
-
}
|
|
1640
|
-
return [...groups.entries()].map(([identity, group]) => {
|
|
1641
|
-
const [value, footprint, dnp] = JSON.parse(identity) as [string, string, boolean]
|
|
1642
|
-
return {
|
|
1643
|
-
references: group.references,
|
|
1644
|
-
quantity: group.references.length,
|
|
1645
|
-
value,
|
|
1646
|
-
footprint,
|
|
1647
|
-
dnp,
|
|
1648
|
-
fields: group.fields,
|
|
1649
|
-
} satisfies BomRow
|
|
1650
|
-
})
|
|
1651
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Engineering artifact model and host operations.
|
|
3
|
+
*
|
|
4
|
+
* This module deliberately has no Cordis dependency: it is the testable core
|
|
5
|
+
* behind `hardwareArtifacts`. Native project files remain authoritative; the
|
|
6
|
+
* objects here are path pointers, verified installation facts and disposable
|
|
7
|
+
* derived outputs, never a shadow project database.
|
|
8
|
+
*/
|
|
9
|
+
import { execFile, execFileSync, spawn, type ChildProcess } from 'node:child_process'
|
|
10
|
+
import { createHash } from 'node:crypto'
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { readFile } from 'node:fs/promises'
|
|
13
|
+
import { basename, dirname, extname, isAbsolute, join, resolve, sep } from 'node:path'
|
|
14
|
+
import { tmpdir } from 'node:os'
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_ORDER_BASE_URL, DEFAULT_ORDER_PAGE_BASE, multipartBody,
|
|
17
|
+
ORDER_PATHS, orderBomCsv, orderBomRows, orderIdsFromUrl, packageName, parsePositions,
|
|
18
|
+
pcbOrderForm, pcbOrderUrl, positionsCsv, readBoardFacts, readExportDirectory, smtOrderForm,
|
|
19
|
+
smtOrderUrl, smtOrderUrlFromBackend, zipPackage,
|
|
20
|
+
type BoardFacts,
|
|
21
|
+
} from './order.js'
|
|
22
|
+
import { validateFabricationPackage, validationSummary, type PackageValidation } from './package.js'
|
|
23
|
+
import { resolveToolchain } from './toolchain/resolve.js'
|
|
24
|
+
|
|
25
|
+
export type ArtifactKind = 'schematic' | 'pcb' | 'pcb-3d' | 'bom' | 'mechanical-3d'
|
|
26
|
+
/** Native handoff is KiCad-only in this POC; SolidCraft stays agent context. */
|
|
27
|
+
export type NativeApplication = 'kicad'
|
|
28
|
+
|
|
29
|
+
export interface HardwareArtifact {
|
|
30
|
+
readonly id: string
|
|
31
|
+
readonly kind: ArtifactKind
|
|
32
|
+
readonly path: string
|
|
33
|
+
readonly projectPath?: string
|
|
34
|
+
/** BOM keeps its schematic; PCB 3D keeps its board; sheets keep their root. */
|
|
35
|
+
readonly sourcePath?: string
|
|
36
|
+
readonly title: string
|
|
37
|
+
readonly format: string
|
|
38
|
+
/** Content hash of the saved source, filled when the source is read. */
|
|
39
|
+
readonly revision?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface HardwareProject {
|
|
43
|
+
readonly path: string
|
|
44
|
+
readonly name: string
|
|
45
|
+
/** Root schematic: the authoritative project entry point. */
|
|
46
|
+
readonly rootSheet?: HardwareArtifact
|
|
47
|
+
readonly schematic?: HardwareArtifact
|
|
48
|
+
/** Semantic views; both keep the identity of their source artifact. */
|
|
49
|
+
readonly bom?: HardwareArtifact
|
|
50
|
+
readonly pcb3d?: HardwareArtifact
|
|
51
|
+
readonly sheets: readonly HardwareArtifact[]
|
|
52
|
+
/** Deterministic default board, only when ownership is unambiguous. */
|
|
53
|
+
readonly defaultBoard?: string
|
|
54
|
+
readonly boards: readonly HardwareArtifact[]
|
|
55
|
+
readonly mechanical: readonly HardwareArtifact[]
|
|
56
|
+
readonly selectionRequired: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DiscoveryResult {
|
|
60
|
+
readonly cwd: string
|
|
61
|
+
readonly manifestPath?: string
|
|
62
|
+
readonly projects: readonly HardwareProject[]
|
|
63
|
+
readonly selected?: HardwareProject
|
|
64
|
+
readonly issue?: { readonly code: string; readonly message: string }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface InstallationInfo {
|
|
68
|
+
readonly configured: boolean
|
|
69
|
+
readonly root?: string
|
|
70
|
+
readonly cli?: string
|
|
71
|
+
readonly projectManager?: string
|
|
72
|
+
readonly pcbEditor?: string
|
|
73
|
+
readonly schematicEditor?: string
|
|
74
|
+
readonly executable?: string
|
|
75
|
+
readonly version?: string
|
|
76
|
+
readonly error?: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface Installations {
|
|
80
|
+
readonly kicad: InstallationInfo
|
|
81
|
+
readonly solidcraft: InstallationInfo
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface OpenArtifactRequest {
|
|
85
|
+
readonly application: NativeApplication
|
|
86
|
+
readonly artifactPath: string
|
|
87
|
+
readonly kind: ArtifactKind
|
|
88
|
+
readonly projectPath?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface OpenArtifactResult {
|
|
92
|
+
readonly launched: true
|
|
93
|
+
readonly command: string
|
|
94
|
+
readonly args: readonly string[]
|
|
95
|
+
readonly cwd: string
|
|
96
|
+
readonly pid?: number
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface SourceRequest {
|
|
100
|
+
readonly artifactPath: string
|
|
101
|
+
readonly expectedRevision?: string
|
|
102
|
+
/** DSH session the read belongs to, used only to scope the discovery cache. */
|
|
103
|
+
readonly sessionId?: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface SourceResult {
|
|
107
|
+
readonly path: string
|
|
108
|
+
readonly kind: 'schematic' | 'pcb'
|
|
109
|
+
readonly revision: string
|
|
110
|
+
readonly bytes: number
|
|
111
|
+
readonly mtimeMs: number
|
|
112
|
+
readonly text: string
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface GlbRequest {
|
|
116
|
+
readonly artifactPath: string
|
|
117
|
+
readonly sessionId?: string
|
|
118
|
+
readonly signal?: AbortSignal
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface GlbResult {
|
|
122
|
+
readonly path: string
|
|
123
|
+
readonly revision: string
|
|
124
|
+
readonly bytes: number
|
|
125
|
+
readonly generatedAt: string
|
|
126
|
+
readonly cached: boolean
|
|
127
|
+
readonly file: string
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** One grouped BOM line, as KiCad's own BOM export groups it. */
|
|
131
|
+
export interface BomRow {
|
|
132
|
+
readonly references: readonly string[]
|
|
133
|
+
readonly quantity: number
|
|
134
|
+
readonly value: string
|
|
135
|
+
readonly footprint: string
|
|
136
|
+
readonly dnp: boolean
|
|
137
|
+
readonly fields: Readonly<Record<string, string>>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface BomResult {
|
|
141
|
+
readonly path: string
|
|
142
|
+
readonly revision: string
|
|
143
|
+
readonly generatedAt: string
|
|
144
|
+
readonly cached: boolean
|
|
145
|
+
readonly rows: readonly BomRow[]
|
|
146
|
+
readonly source: 'kicad-cli-bom'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface OrderPackageSummary {
|
|
150
|
+
readonly zipName: string
|
|
151
|
+
readonly zipBytes: number
|
|
152
|
+
readonly files: readonly { readonly name: string; readonly bytes: number }[]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A prepared fabrication package: what would be uploaded, nothing sent yet. */
|
|
156
|
+
export interface FabricationResult {
|
|
157
|
+
readonly boardPath: string
|
|
158
|
+
readonly revision: string
|
|
159
|
+
readonly generatedAt: string
|
|
160
|
+
readonly facts: BoardFacts
|
|
161
|
+
readonly archive: OrderPackageSummary
|
|
162
|
+
/**
|
|
163
|
+
* Whether the archive is actually fabricable. Present on every result: a
|
|
164
|
+
* package can be prepared and refused, and the caller needs the reason.
|
|
165
|
+
*/
|
|
166
|
+
readonly validation: PackageValidation
|
|
167
|
+
/** Assembly inputs, present when a schematic was supplied. */
|
|
168
|
+
readonly assembly?: {
|
|
169
|
+
readonly positions: number
|
|
170
|
+
readonly bomLines: number
|
|
171
|
+
readonly positionsBytes: number
|
|
172
|
+
readonly bomBytes: number
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface OrderConfigInfo {
|
|
177
|
+
readonly configured: boolean
|
|
178
|
+
readonly baseUrl: string
|
|
179
|
+
/** True when a signed-in session or a configured token can sign the page. */
|
|
180
|
+
readonly hasToken: boolean
|
|
181
|
+
readonly provider: 'huaqiu'
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface PlaceOrderRequest {
|
|
185
|
+
readonly kind: 'pcb' | 'smt'
|
|
186
|
+
readonly boardPath: string
|
|
187
|
+
readonly schematicPath?: string
|
|
188
|
+
readonly sessionId?: string
|
|
189
|
+
readonly quantity?: number
|
|
190
|
+
readonly signal?: AbortSignal
|
|
191
|
+
/**
|
|
192
|
+
* Hand the resulting page to the OS default browser.
|
|
193
|
+
*
|
|
194
|
+
* Off by default: a DSH client opens the page in its own Browser tab, and
|
|
195
|
+
* opening both would leave the user with two copies of the same page. Only a
|
|
196
|
+
* caller with no client (a script, a foreign MCP host) wants this on.
|
|
197
|
+
*/
|
|
198
|
+
readonly launch?: boolean
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface PlaceOrderResult {
|
|
202
|
+
readonly kind: 'pcb' | 'smt'
|
|
203
|
+
/** The exact URL KiCad's own action loads into its order webview. */
|
|
204
|
+
readonly orderUrl: string
|
|
205
|
+
/** The backend's raw URL, before KiCad's own query parameters were added. */
|
|
206
|
+
readonly responseUrl: string
|
|
207
|
+
/** True when the host handed `orderUrl` to the OS default browser. */
|
|
208
|
+
readonly launched: boolean
|
|
209
|
+
readonly launcher?: string
|
|
210
|
+
readonly status: 'launched' | 'ready'
|
|
211
|
+
readonly message: string
|
|
212
|
+
readonly endpoint: string
|
|
213
|
+
readonly facts: BoardFacts
|
|
214
|
+
readonly archive: OrderPackageSummary
|
|
215
|
+
/** The package judgement the order was placed with. */
|
|
216
|
+
readonly validation: PackageValidation
|
|
217
|
+
readonly assembly?: FabricationResult['assembly']
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface HardwareArtifactsOptions {
|
|
221
|
+
readonly kicadRoot?: string
|
|
222
|
+
readonly solidcraftRoot?: string
|
|
223
|
+
/** Origin for the place-order endpoints; defaults to the Huaqiu host. */
|
|
224
|
+
readonly orderBaseUrl?: string
|
|
225
|
+
readonly orderPageBase?: string
|
|
226
|
+
/** Huaqiu access token; only ever sent to the order endpoint. */
|
|
227
|
+
readonly accessToken?: string
|
|
228
|
+
/**
|
|
229
|
+
* Resolves the signed-in Huaqiu token when no explicit token is configured.
|
|
230
|
+
*
|
|
231
|
+
* hqpcb is a Huaqiu business, so the login that feeds the eda.cn API is also
|
|
232
|
+
* the token the order page expects — there is no second credential.
|
|
233
|
+
*/
|
|
234
|
+
readonly authToken?: () => Promise<string | null>
|
|
235
|
+
/** Injectable transport for tests; defaults to global fetch. */
|
|
236
|
+
readonly postOrder?: (url: string, init: {
|
|
237
|
+
readonly body: Buffer
|
|
238
|
+
readonly contentType: string
|
|
239
|
+
readonly headers?: Readonly<Record<string, string>>
|
|
240
|
+
readonly signal?: AbortSignal
|
|
241
|
+
}) => Promise<{ readonly status: number; readonly text: string }>
|
|
242
|
+
/**
|
|
243
|
+
* Live accessor for the user-configured roots.
|
|
244
|
+
*
|
|
245
|
+
* The plugin passes the profile config reference, so a settings write that
|
|
246
|
+
* replaces a volatile field is visible on the next validation without the
|
|
247
|
+
* service caching a start-time snapshot.
|
|
248
|
+
*/
|
|
249
|
+
readonly settings?: () => {
|
|
250
|
+
readonly kicadRoot?: string
|
|
251
|
+
readonly solidcraftRoot?: string
|
|
252
|
+
readonly orderBaseUrl?: string
|
|
253
|
+
readonly accessToken?: string
|
|
254
|
+
}
|
|
255
|
+
readonly probeVersion?: (executable: string, tool?: 'kicad' | 'solidcraft') => string | undefined
|
|
256
|
+
readonly spawnProcess?: (
|
|
257
|
+
command: string,
|
|
258
|
+
args: readonly string[],
|
|
259
|
+
options: { cwd: string; detached: boolean; stdio: 'ignore'; windowsHide: boolean; shell: false },
|
|
260
|
+
) => Pick<ChildProcess, 'pid'>
|
|
261
|
+
/**
|
|
262
|
+
* Command used to hand a URL to the OS. Defaults to `open` on macOS,
|
|
263
|
+
* `rundll32 url.dll,FileProtocolHandler` on Windows and `xdg-open` elsewhere.
|
|
264
|
+
*/
|
|
265
|
+
readonly openExternal?: (url: string) => { readonly command: string; readonly args: readonly string[] }
|
|
266
|
+
/** Runs one short-lived CLI command and returns its exit facts. */
|
|
267
|
+
readonly runCommand?: (
|
|
268
|
+
command: string,
|
|
269
|
+
args: readonly string[],
|
|
270
|
+
options: { cwd: string; timeoutMs: number; signal?: AbortSignal },
|
|
271
|
+
) => Promise<{ exitCode: number | null; stdout: string; stderr: string; timedOut: boolean }>
|
|
272
|
+
/** Cache directory for derived outputs; defaults to a temp subdirectory. */
|
|
273
|
+
readonly cacheRoot?: string
|
|
274
|
+
readonly glbTimeoutMs?: number
|
|
275
|
+
/** Source text limit; protects the host from pathological files. */
|
|
276
|
+
readonly maxSourceBytes?: number
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface ProjectManifest {
|
|
280
|
+
project?: string
|
|
281
|
+
schematic?: string
|
|
282
|
+
boards?: readonly { id?: string; path: string }[]
|
|
283
|
+
mechanical?: readonly { id?: string; path: string }[]
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const EXCLUDED_DIRS = new Set([
|
|
287
|
+
'.git', '.cache', 'node_modules', 'dist', 'build', 'out', 'tmp', 'temp',
|
|
288
|
+
'archive', 'archives', 'backup', 'backups', 'export', 'exports',
|
|
289
|
+
])
|
|
290
|
+
const MECHANICAL_EXTENSIONS = new Set(['.step', '.stp', '.glb'])
|
|
291
|
+
const SOURCE_EXTENSIONS: Readonly<Record<string, 'schematic' | 'pcb'>> = {
|
|
292
|
+
'.kicad_sch': 'schematic',
|
|
293
|
+
'.kicad_pcb': 'pcb',
|
|
294
|
+
}
|
|
295
|
+
const MAX_DEPTH = 5
|
|
296
|
+
/** KiCad writes each child sheet as `(property "Sheetfile" "child.kicad_sch")`. */
|
|
297
|
+
const SHEET_FILE_PATTERN = /\(property\s+"Sheetfile"\s+"((?:[^"\\]|\\.)*)"/gu
|
|
298
|
+
|
|
299
|
+
function canonical(path: string): string {
|
|
300
|
+
return resolve(path)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function isExcluded(name: string): boolean {
|
|
304
|
+
return EXCLUDED_DIRS.has(name.toLowerCase())
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function realOrUndefined(path: string): string | undefined {
|
|
308
|
+
try {
|
|
309
|
+
return realpathSync(path)
|
|
310
|
+
} catch {
|
|
311
|
+
return undefined
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Identity of one authorization scope. DSH sessions are the scope; an embed
|
|
317
|
+
* without sessions (tests, a bare host) shares the default entry.
|
|
318
|
+
*/
|
|
319
|
+
function scopeKey(sessionId?: string): string {
|
|
320
|
+
return sessionId === undefined || sessionId === '' ? '' : sessionId
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function errorWithCode(message: string, code: string, status: number): Error {
|
|
324
|
+
return Object.assign(new Error(message), { code, status })
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* POST one multipart order payload.
|
|
329
|
+
*
|
|
330
|
+
* Kept out of the class so tests can inject their own transport; the default
|
|
331
|
+
* has a hard timeout and never logs the body (it carries the access token).
|
|
332
|
+
*/
|
|
333
|
+
async function defaultPostOrder(url: string, init: {
|
|
334
|
+
readonly body: Buffer
|
|
335
|
+
readonly contentType: string
|
|
336
|
+
readonly headers?: Readonly<Record<string, string>>
|
|
337
|
+
readonly signal?: AbortSignal
|
|
338
|
+
}): Promise<{ readonly status: number; readonly text: string }> {
|
|
339
|
+
const controller = new AbortController()
|
|
340
|
+
const timer = setTimeout(() => { controller.abort() }, 90_000)
|
|
341
|
+
const forward = (): void => { controller.abort() }
|
|
342
|
+
init.signal?.addEventListener('abort', forward, { once: true })
|
|
343
|
+
try {
|
|
344
|
+
const response = await fetch(url, {
|
|
345
|
+
method: 'POST',
|
|
346
|
+
headers: {
|
|
347
|
+
...init.headers,
|
|
348
|
+
'content-type': init.contentType,
|
|
349
|
+
'content-length': String(init.body.byteLength),
|
|
350
|
+
},
|
|
351
|
+
// Node's fetch accepts a Buffer body; the DOM lib's BodyInit typing only
|
|
352
|
+
// names ArrayBuffer views backed by a non-shared buffer.
|
|
353
|
+
body: init.body as unknown as BodyInit,
|
|
354
|
+
signal: controller.signal,
|
|
355
|
+
})
|
|
356
|
+
return { status: response.status, text: await response.text() }
|
|
357
|
+
} finally {
|
|
358
|
+
clearTimeout(timer)
|
|
359
|
+
init.signal?.removeEventListener('abort', forward)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Command that opens one URL in the OS default browser.
|
|
365
|
+
*
|
|
366
|
+
* A URL argument is passed to a fixed executable with `shell: false`, so the
|
|
367
|
+
* page can never become a shell command.
|
|
368
|
+
*/
|
|
369
|
+
function defaultOpenExternal(url: string): { command: string; args: readonly string[] } {
|
|
370
|
+
if (process.platform === 'darwin') return { command: 'open', args: [url] }
|
|
371
|
+
if (process.platform === 'win32') return { command: 'rundll32', args: ['url.dll,FileProtocolHandler', url] }
|
|
372
|
+
return { command: 'xdg-open', args: [url] }
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Validate an order page URL before handing it to the OS.
|
|
377
|
+
*
|
|
378
|
+
* The backend owns this URL, so the check is deliberately about *shape*, not
|
|
379
|
+
* about a specific host: HTTPS anywhere, plain HTTP only on loopback (local
|
|
380
|
+
* stubs), and never a URL with embedded credentials or a non-web scheme.
|
|
381
|
+
*/
|
|
382
|
+
function externalUrlTarget(raw: string): string {
|
|
383
|
+
if (raw.length === 0 || raw.length > 4096) {
|
|
384
|
+
throw errorWithCode('the order URL is empty or too long', 'invalid-order-url', 400)
|
|
385
|
+
}
|
|
386
|
+
let parsed: URL
|
|
387
|
+
try {
|
|
388
|
+
parsed = new URL(raw)
|
|
389
|
+
} catch {
|
|
390
|
+
throw errorWithCode('the order URL is not a valid absolute URL', 'invalid-order-url', 400)
|
|
391
|
+
}
|
|
392
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
393
|
+
throw errorWithCode(`refusing to open a ${parsed.protocol} URL`, 'invalid-order-url', 400)
|
|
394
|
+
}
|
|
395
|
+
if (parsed.username !== '' || parsed.password !== '') {
|
|
396
|
+
throw errorWithCode('refusing to open a URL with embedded credentials', 'invalid-order-url', 400)
|
|
397
|
+
}
|
|
398
|
+
const host = parsed.hostname.replace(/^\[|\]$/gu, '')
|
|
399
|
+
const loopback = host === 'localhost' || host === '::1' || host === '127.0.0.1' || host.startsWith('127.')
|
|
400
|
+
if (parsed.protocol === 'http:' && !loopback) {
|
|
401
|
+
throw errorWithCode('refusing to open a plain-HTTP order URL outside loopback', 'invalid-order-url', 400)
|
|
402
|
+
}
|
|
403
|
+
return parsed.toString()
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** First backend-owned order URL in a place-order response. */
|
|
407
|
+
function orderUrlOf(body: unknown): string | undefined {
|
|
408
|
+
if (body === null || typeof body !== 'object') return undefined
|
|
409
|
+
const record = body as Record<string, unknown>
|
|
410
|
+
for (const key of ['url', 'redirect', 'data']) {
|
|
411
|
+
const value = record[key]
|
|
412
|
+
if (typeof value === 'string' && value !== '') return value
|
|
413
|
+
if (value !== null && typeof value === 'object') {
|
|
414
|
+
const nested = orderUrlOf(value)
|
|
415
|
+
if (nested !== undefined) return nested
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const result = record.result
|
|
419
|
+
return result === undefined ? undefined : orderUrlOf(result)
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function walkFiles(root: string, predicate: (name: string) => boolean): string[] {
|
|
423
|
+
const found: string[] = []
|
|
424
|
+
const visit = (dir: string, depth: number): void => {
|
|
425
|
+
if (depth > MAX_DEPTH || !existsSync(dir)) return
|
|
426
|
+
let entries
|
|
427
|
+
try {
|
|
428
|
+
entries = readdirSync(dir, { withFileTypes: true })
|
|
429
|
+
} catch {
|
|
430
|
+
return
|
|
431
|
+
}
|
|
432
|
+
for (const entry of entries) {
|
|
433
|
+
const full = join(dir, entry.name)
|
|
434
|
+
if (entry.isDirectory()) {
|
|
435
|
+
if (!isExcluded(entry.name)) visit(full, depth + 1)
|
|
436
|
+
} else if (entry.isFile() && predicate(entry.name)) {
|
|
437
|
+
found.push(canonical(full))
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
visit(root, 0)
|
|
442
|
+
return found.sort()
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Child schematics declared by sheet references in one saved schematic. */
|
|
446
|
+
function childSheetFiles(path: string): string[] {
|
|
447
|
+
let text: string
|
|
448
|
+
try {
|
|
449
|
+
text = readFileSync(path, 'utf8')
|
|
450
|
+
} catch {
|
|
451
|
+
return []
|
|
452
|
+
}
|
|
453
|
+
const dir = dirname(path)
|
|
454
|
+
const children: string[] = []
|
|
455
|
+
for (const match of text.matchAll(SHEET_FILE_PATTERN)) {
|
|
456
|
+
const raw = match[1]
|
|
457
|
+
if (raw === undefined || raw === '') continue
|
|
458
|
+
const declared = raw.replace(/\\(["\\])/gu, '$1')
|
|
459
|
+
const target = isAbsolute(declared) ? canonical(declared) : resolve(dir, declared)
|
|
460
|
+
children.push(target)
|
|
461
|
+
}
|
|
462
|
+
return children.sort()
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function artifact(kind: ArtifactKind, path: string, projectPath?: string, sourcePath?: string): HardwareArtifact {
|
|
466
|
+
const full = canonical(path)
|
|
467
|
+
return {
|
|
468
|
+
id: `${kind}:${full}`,
|
|
469
|
+
kind,
|
|
470
|
+
path: full,
|
|
471
|
+
...(projectPath === undefined ? {} : { projectPath: canonical(projectPath) }),
|
|
472
|
+
...(sourcePath === undefined ? {} : { sourcePath: canonical(sourcePath) }),
|
|
473
|
+
title: basename(full),
|
|
474
|
+
format: extname(full).toLowerCase().replace(/^\./, '') || kind,
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Is this path an existing regular file? Small helper shared by resolution. */
|
|
479
|
+
function isFile(path: string): boolean {
|
|
480
|
+
try {
|
|
481
|
+
return existsSync(path) && statSync(path).isFile()
|
|
482
|
+
} catch {
|
|
483
|
+
return false
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function defaultVersionProbe(executable: string, tool: 'kicad' | 'solidcraft' = 'kicad'): string | undefined {
|
|
488
|
+
if (!existsSync(executable)) return undefined
|
|
489
|
+
try {
|
|
490
|
+
// The two tools do not share a version interface: KiCad answers its `version`
|
|
491
|
+
// subcommand, SolidCraft only its `--version` flag.
|
|
492
|
+
const args = tool === 'kicad' ? ['version'] : ['--version']
|
|
493
|
+
return execFileSync(executable, args, {
|
|
494
|
+
encoding: 'utf8',
|
|
495
|
+
timeout: 5_000,
|
|
496
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
497
|
+
}).trim().split('\n')[0] || undefined
|
|
498
|
+
} catch {
|
|
499
|
+
return undefined
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function defaultRunCommand(
|
|
504
|
+
command: string,
|
|
505
|
+
args: readonly string[],
|
|
506
|
+
options: { cwd: string; timeoutMs: number; signal?: AbortSignal },
|
|
507
|
+
): Promise<{ exitCode: number | null; stdout: string; stderr: string; timedOut: boolean }> {
|
|
508
|
+
return new Promise((resolvePromise, reject) => {
|
|
509
|
+
execFile(command, [...args], {
|
|
510
|
+
cwd: options.cwd,
|
|
511
|
+
timeout: options.timeoutMs,
|
|
512
|
+
encoding: 'utf8',
|
|
513
|
+
windowsHide: true,
|
|
514
|
+
shell: false,
|
|
515
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
516
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
517
|
+
}, (error, stdout, stderr) => {
|
|
518
|
+
if (error === null) {
|
|
519
|
+
resolvePromise({ exitCode: 0, stdout: String(stdout), stderr: String(stderr), timedOut: false })
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
const killed = (error as { killed?: boolean }).killed === true
|
|
523
|
+
const signal = (error as { signal?: string | null }).signal
|
|
524
|
+
if (killed || signal !== null && signal !== undefined) {
|
|
525
|
+
resolvePromise({ exitCode: null, stdout: String(stdout), stderr: String(stderr), timedOut: true })
|
|
526
|
+
return
|
|
527
|
+
}
|
|
528
|
+
const code = typeof (error as { code?: unknown }).code === 'number' ? Number((error as { code: number }).code) : null
|
|
529
|
+
if (code === null) {
|
|
530
|
+
reject(error)
|
|
531
|
+
return
|
|
532
|
+
}
|
|
533
|
+
resolvePromise({ exitCode: code, stdout: String(stdout), stderr: String(stderr), timedOut: false })
|
|
534
|
+
})
|
|
535
|
+
})
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
/** Small, immutable host capability implementation. */
|
|
540
|
+
export class HardwareArtifactService {
|
|
541
|
+
private readonly options: Required<Pick<
|
|
542
|
+
HardwareArtifactsOptions,
|
|
543
|
+
'spawnProcess' | 'probeVersion' | 'runCommand' | 'openExternal'
|
|
544
|
+
>>
|
|
545
|
+
private readonly cacheRoot: string
|
|
546
|
+
private readonly glbTimeoutMs: number
|
|
547
|
+
private readonly maxSourceBytes: number
|
|
548
|
+
/**
|
|
549
|
+
* Last discovery per scope — one entry per DSH session, plus the unscoped
|
|
550
|
+
* default used by tests and non-DSH embeds.
|
|
551
|
+
*
|
|
552
|
+
* It is a map rather than one field on purpose: a single "most recent
|
|
553
|
+
* discovery" is shared by every open viewer, so switching to a session in
|
|
554
|
+
* another workspace silently revoked the authorization of the viewer that
|
|
555
|
+
* stayed open. Authorization must never depend on who asked last.
|
|
556
|
+
*/
|
|
557
|
+
private readonly discoveries = new Map<string, DiscoveryResult>()
|
|
558
|
+
/** Completed GLB exports keyed by `sourcePath:revision`. */
|
|
559
|
+
private readonly glbCache = new Map<string, GlbResult>()
|
|
560
|
+
/** In-flight GLB exports keyed by the same key, so concurrent callers share one run. */
|
|
561
|
+
private readonly glbPending = new Map<string, Promise<GlbResult>>()
|
|
562
|
+
/** BOM projections keyed by `sourcePath:revision`. */
|
|
563
|
+
private readonly bomCache = new Map<string, BomResult>()
|
|
564
|
+
/** Prepared fabrication packages keyed by board, revision and schematic. */
|
|
565
|
+
private readonly packageCache = new Map<string, FabricationResult & {
|
|
566
|
+
readonly archiveData: Uint8Array
|
|
567
|
+
readonly assemblyFiles?: { readonly positions: string; readonly bom: string }
|
|
568
|
+
}>()
|
|
569
|
+
|
|
570
|
+
constructor(private readonly config: HardwareArtifactsOptions = {}) {
|
|
571
|
+
this.options = {
|
|
572
|
+
probeVersion: config.probeVersion ?? defaultVersionProbe,
|
|
573
|
+
spawnProcess: config.spawnProcess ?? ((command, args, settings) => spawn(command, [...args], settings)),
|
|
574
|
+
runCommand: config.runCommand ?? defaultRunCommand,
|
|
575
|
+
openExternal: config.openExternal ?? defaultOpenExternal,
|
|
576
|
+
}
|
|
577
|
+
this.cacheRoot = canonical(config.cacheRoot ?? join(tmpdir(), 'huaqiu-hardware-artifacts'))
|
|
578
|
+
this.glbTimeoutMs = config.glbTimeoutMs ?? 120_000
|
|
579
|
+
this.maxSourceBytes = config.maxSourceBytes ?? 32 * 1024 * 1024
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Configured roots, read live so a settings write is visible immediately. */
|
|
583
|
+
private roots(): { kicadRoot?: string; solidcraftRoot?: string } {
|
|
584
|
+
const live = this.config.settings?.()
|
|
585
|
+
const kicadRoot = live?.kicadRoot ?? this.config.kicadRoot
|
|
586
|
+
const solidcraftRoot = live?.solidcraftRoot ?? this.config.solidcraftRoot
|
|
587
|
+
return {
|
|
588
|
+
...(kicadRoot === undefined ? {} : { kicadRoot }),
|
|
589
|
+
...(solidcraftRoot === undefined ? {} : { solidcraftRoot }),
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Resolve configured installations from validated absolute paths only.
|
|
595
|
+
*
|
|
596
|
+
* Resolution is delegated to the toolchain capability's one resolver
|
|
597
|
+
* (`./toolchain/resolve.ts`) so the settings panel, background discovery and
|
|
598
|
+
* the export path cannot disagree about what "configured" means.
|
|
599
|
+
*/
|
|
600
|
+
installations(): Installations {
|
|
601
|
+
const roots = this.roots()
|
|
602
|
+
const kicadResolution = resolveToolchain('kicad', roots.kicadRoot, {
|
|
603
|
+
exists: path => isFile(path),
|
|
604
|
+
probeVersion: executable => this.options.probeVersion(executable, 'kicad'),
|
|
605
|
+
})
|
|
606
|
+
const kicad: InstallationInfo = kicadResolution.configured
|
|
607
|
+
? {
|
|
608
|
+
configured: true,
|
|
609
|
+
...(roots.kicadRoot === undefined ? {} : { root: canonical(roots.kicadRoot) }),
|
|
610
|
+
...(kicadResolution.cli === undefined ? {} : { cli: kicadResolution.cli }),
|
|
611
|
+
...(kicadResolution.version === undefined ? {} : { version: kicadResolution.version }),
|
|
612
|
+
...(kicadResolution.projectManager === undefined ? {} : { projectManager: kicadResolution.projectManager }),
|
|
613
|
+
...(kicadResolution.pcbEditor === undefined ? {} : { pcbEditor: kicadResolution.pcbEditor }),
|
|
614
|
+
...(kicadResolution.schematicEditor === undefined ? {} : { schematicEditor: kicadResolution.schematicEditor }),
|
|
615
|
+
}
|
|
616
|
+
: {
|
|
617
|
+
configured: false,
|
|
618
|
+
...(roots.kicadRoot === undefined ? {} : { root: canonical(roots.kicadRoot) }),
|
|
619
|
+
...(kicadResolution.cli === undefined ? {} : { cli: kicadResolution.cli }),
|
|
620
|
+
...(kicadResolution.error === undefined ? {} : { error: kicadResolution.error }),
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const solidResolution = resolveToolchain('solidcraft', roots.solidcraftRoot, {
|
|
624
|
+
exists: path => isFile(path),
|
|
625
|
+
probeVersion: executable => this.options.probeVersion(executable, 'solidcraft'),
|
|
626
|
+
})
|
|
627
|
+
// The GUI executable keeps its historical field name (`executable`) so the
|
|
628
|
+
// launch path and the agent prompt are unchanged; the CLI is additive.
|
|
629
|
+
const solidcraft: InstallationInfo = solidResolution.configured
|
|
630
|
+
? {
|
|
631
|
+
configured: true,
|
|
632
|
+
...(roots.solidcraftRoot === undefined ? {} : { root: canonical(roots.solidcraftRoot) }),
|
|
633
|
+
...(solidResolution.app === undefined ? {} : { executable: solidResolution.app }),
|
|
634
|
+
...(solidResolution.cli === undefined ? {} : { cli: solidResolution.cli }),
|
|
635
|
+
...(solidResolution.version === undefined ? {} : { version: solidResolution.version }),
|
|
636
|
+
}
|
|
637
|
+
: {
|
|
638
|
+
configured: false,
|
|
639
|
+
...(roots.solidcraftRoot === undefined ? {} : { root: canonical(roots.solidcraftRoot) }),
|
|
640
|
+
...(solidResolution.error === undefined ? {} : { error: solidResolution.error }),
|
|
641
|
+
}
|
|
642
|
+
return { kicad, solidcraft }
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** Paths passed to agent child processes. Never assign these globally. */
|
|
646
|
+
childEnvironment(): Record<string, string> {
|
|
647
|
+
const installed = this.installations()
|
|
648
|
+
const env: Record<string, string> = {}
|
|
649
|
+
if (installed.kicad.cli !== undefined) env.HUAQIU_KICAD_CLI = installed.kicad.cli
|
|
650
|
+
if (installed.kicad.pcbEditor !== undefined) env.HUAQIU_KICAD_PCBNEW = installed.kicad.pcbEditor
|
|
651
|
+
if (installed.kicad.schematicEditor !== undefined) env.HUAQIU_KICAD_EESCHEMA = installed.kicad.schematicEditor
|
|
652
|
+
if (installed.solidcraft.executable !== undefined) env.HUAQIU_SOLIDCRAFT = installed.solidcraft.executable
|
|
653
|
+
return env
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Compact agent context: validated paths only, no project inventory dump. */
|
|
657
|
+
environmentText(current?: DiscoveryResult): string {
|
|
658
|
+
const installed = this.installations()
|
|
659
|
+
// The prompt has no session of its own; speaking for the only scope that
|
|
660
|
+
// ever discovered is honest, and with several open workspaces it says
|
|
661
|
+
// nothing rather than naming another session's project.
|
|
662
|
+
const scope = current ?? this.soleDiscovery()
|
|
663
|
+
const lines = ['<hardware_environment>']
|
|
664
|
+
lines.push('KiCad:')
|
|
665
|
+
lines.push(` configured: ${String(installed.kicad.configured)}`)
|
|
666
|
+
for (const key of ['version', 'cli', 'pcbEditor', 'schematicEditor'] as const) {
|
|
667
|
+
const value = installed.kicad[key]
|
|
668
|
+
if (value !== undefined) lines.push(` ${key}: ${value}`)
|
|
669
|
+
}
|
|
670
|
+
if (installed.kicad.error !== undefined) lines.push(` error: ${installed.kicad.error}`)
|
|
671
|
+
lines.push('SolidCraft:')
|
|
672
|
+
lines.push(` configured: ${String(installed.solidcraft.configured)}`)
|
|
673
|
+
for (const key of ['version', 'executable', 'cli'] as const) {
|
|
674
|
+
const value = installed.solidcraft[key]
|
|
675
|
+
if (value !== undefined) lines.push(` ${key}: ${value}`)
|
|
676
|
+
}
|
|
677
|
+
if (installed.solidcraft.error !== undefined) lines.push(` error: ${installed.solidcraft.error}`)
|
|
678
|
+
// §12.2: an agent must be able to tell the user *what to do* about a missing
|
|
679
|
+
// toolchain without guessing at product navigation.
|
|
680
|
+
const missing = [!installed.kicad.configured ? 'KiCad' : undefined, !installed.solidcraft.configured ? 'SolidCraft' : undefined]
|
|
681
|
+
.filter((entry): entry is string => entry !== undefined)
|
|
682
|
+
if (missing.length > 0) {
|
|
683
|
+
lines.push('setup:')
|
|
684
|
+
lines.push(` missing: ${missing.join(', ')}`)
|
|
685
|
+
lines.push(' remediation: Settings → Hardware Engineering (browse an existing installation, download the HuaQiu build, or skip)')
|
|
686
|
+
}
|
|
687
|
+
if (scope?.selected !== undefined) {
|
|
688
|
+
lines.push('Current project:')
|
|
689
|
+
lines.push(` root: ${scope.cwd}`)
|
|
690
|
+
lines.push(` project: ${scope.selected.path}`)
|
|
691
|
+
if (scope.selected.schematic !== undefined) lines.push(` schematic: ${scope.selected.schematic.path}`)
|
|
692
|
+
const board = scope.selected.boards[0]
|
|
693
|
+
if (board !== undefined) lines.push(` selected_pcb: ${board.path}`)
|
|
694
|
+
}
|
|
695
|
+
lines.push('</hardware_environment>')
|
|
696
|
+
return lines.join('\n')
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Deterministic discovery. An explicit project or manifest wins; otherwise
|
|
701
|
+
* exactly one `.kicad_pro` may be selected automatically. Ambiguity is
|
|
702
|
+
* returned as a selection requirement, never resolved by taking the first.
|
|
703
|
+
*
|
|
704
|
+
* @param cwdInput - workspace directory to walk.
|
|
705
|
+
* @param explicitProject - project chosen by the user, absolute or cwd-relative.
|
|
706
|
+
* @param sessionId - DSH session the discovery belongs to. Recording it per
|
|
707
|
+
* session is what keeps one open viewer from revoking another's roots.
|
|
708
|
+
*/
|
|
709
|
+
discover(cwdInput: string, explicitProject?: string, sessionId?: string): DiscoveryResult {
|
|
710
|
+
const cwd = canonical(cwdInput)
|
|
711
|
+
const manifestPath = join(cwd, '.hardware-engineering.json')
|
|
712
|
+
let manifest: ProjectManifest | undefined
|
|
713
|
+
if (existsSync(manifestPath)) {
|
|
714
|
+
try {
|
|
715
|
+
manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as ProjectManifest
|
|
716
|
+
} catch (error) {
|
|
717
|
+
return this.remember({
|
|
718
|
+
cwd,
|
|
719
|
+
manifestPath,
|
|
720
|
+
projects: [],
|
|
721
|
+
issue: { code: 'bad-manifest', message: `invalid .hardware-engineering.json: ${String(error)}` },
|
|
722
|
+
}, sessionId)
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const projectPaths = new Set<string>()
|
|
727
|
+
if (explicitProject !== undefined && explicitProject.trim() !== '') {
|
|
728
|
+
const requested = isAbsolute(explicitProject) ? canonical(explicitProject) : resolve(cwd, explicitProject)
|
|
729
|
+
if (!existsSync(requested)) {
|
|
730
|
+
return this.remember({
|
|
731
|
+
cwd,
|
|
732
|
+
...(manifest === undefined ? {} : { manifestPath }),
|
|
733
|
+
projects: [],
|
|
734
|
+
issue: { code: 'missing-project', message: `${requested} does not exist` },
|
|
735
|
+
}, sessionId)
|
|
736
|
+
}
|
|
737
|
+
projectPaths.add(requested)
|
|
738
|
+
} else if (manifest?.project !== undefined && manifest.project.trim() !== '') {
|
|
739
|
+
projectPaths.add(isAbsolute(manifest.project) ? canonical(manifest.project) : resolve(cwd, manifest.project))
|
|
740
|
+
} else {
|
|
741
|
+
for (const path of walkFiles(cwd, name => name.toLowerCase().endsWith('.kicad_pro'))) projectPaths.add(path)
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
const projects: HardwareProject[] = [...projectPaths].sort().map(path => this.projectFrom(path, cwd, manifest))
|
|
745
|
+
if (projects.length === 0) {
|
|
746
|
+
return this.remember({
|
|
747
|
+
cwd,
|
|
748
|
+
...(manifest === undefined ? {} : { manifestPath }),
|
|
749
|
+
projects,
|
|
750
|
+
issue: { code: 'no-project', message: `no .kicad_pro found under ${cwd}` },
|
|
751
|
+
}, sessionId)
|
|
752
|
+
}
|
|
753
|
+
if (projects.length > 1) {
|
|
754
|
+
return this.remember({
|
|
755
|
+
cwd,
|
|
756
|
+
...(manifest === undefined ? {} : { manifestPath }),
|
|
757
|
+
projects,
|
|
758
|
+
issue: { code: 'selection-required', message: `${projects.length} projects found; select one explicitly` },
|
|
759
|
+
}, sessionId)
|
|
760
|
+
}
|
|
761
|
+
const selected = projects[0] as HardwareProject
|
|
762
|
+
return this.remember({
|
|
763
|
+
cwd,
|
|
764
|
+
...(manifest === undefined ? {} : { manifestPath }),
|
|
765
|
+
projects,
|
|
766
|
+
selected,
|
|
767
|
+
...(selected.selectionRequired
|
|
768
|
+
? { issue: { code: 'selection-required', message: 'select an artifact explicitly' } }
|
|
769
|
+
: {}),
|
|
770
|
+
}, sessionId)
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/** Last discovery for one scope, never another session's. */
|
|
774
|
+
discovery(sessionId?: string): DiscoveryResult | undefined {
|
|
775
|
+
return this.discoveries.get(scopeKey(sessionId))
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/** The only discovery the host can speak for without being told a session. */
|
|
779
|
+
private soleDiscovery(): DiscoveryResult | undefined {
|
|
780
|
+
if (this.discoveries.size !== 1) return undefined
|
|
781
|
+
return [...this.discoveries.values()][0]
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private remember(result: DiscoveryResult, sessionId?: string): DiscoveryResult {
|
|
785
|
+
this.discoveries.set(scopeKey(sessionId), result)
|
|
786
|
+
return result
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
private projectFrom(projectPath: string, cwd: string, manifest?: ProjectManifest): HardwareProject {
|
|
790
|
+
const dir = dirname(projectPath)
|
|
791
|
+
const name = basename(projectPath, extname(projectPath))
|
|
792
|
+
const resolvePath = (value: string): string =>
|
|
793
|
+
isAbsolute(value) ? canonical(value) : resolve(dir, value)
|
|
794
|
+
|
|
795
|
+
// The root schematic is authoritative: an explicit manifest entry, then the
|
|
796
|
+
// project-named file, then a single unambiguous candidate. Unrelated
|
|
797
|
+
// sibling `.kicad_sch` files are never promoted to sheets.
|
|
798
|
+
const explicitSchematic = manifest?.schematic === undefined ? undefined : resolvePath(manifest.schematic)
|
|
799
|
+
let schematicPath = explicitSchematic !== undefined && existsSync(explicitSchematic) ? explicitSchematic : undefined
|
|
800
|
+
if (schematicPath === undefined) {
|
|
801
|
+
const named = join(dir, `${name}.kicad_sch`)
|
|
802
|
+
if (existsSync(named)) schematicPath = named
|
|
803
|
+
else {
|
|
804
|
+
const candidates = readdirSync(dir, { withFileTypes: true })
|
|
805
|
+
.filter(entry => entry.isFile() && entry.name.toLowerCase().endsWith('.kicad_sch'))
|
|
806
|
+
.map(entry => join(dir, entry.name))
|
|
807
|
+
.sort()
|
|
808
|
+
if (candidates.length === 1) schematicPath = candidates[0]
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// Hierarchy comes from sheet references only, resolved recursively with a
|
|
813
|
+
// cycle guard: parsing the root must never advertise unrelated files.
|
|
814
|
+
const sheets: HardwareArtifact[] = []
|
|
815
|
+
if (schematicPath !== undefined) {
|
|
816
|
+
const visited = new Set<string>([canonical(schematicPath)])
|
|
817
|
+
const queue = childSheetFiles(canonical(schematicPath))
|
|
818
|
+
while (queue.length > 0) {
|
|
819
|
+
const next = queue.shift() as string
|
|
820
|
+
const canonicalNext = canonical(next)
|
|
821
|
+
if (visited.has(canonicalNext)) continue
|
|
822
|
+
visited.add(canonicalNext)
|
|
823
|
+
if (!existsSync(canonicalNext) || extname(canonicalNext).toLowerCase() !== '.kicad_sch') continue
|
|
824
|
+
sheets.push(artifact('schematic', canonicalNext, projectPath, canonical(schematicPath)))
|
|
825
|
+
queue.push(...childSheetFiles(canonicalNext))
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Board ranking: manifest ownership first, then the project-named board, then
|
|
830
|
+
// the only candidate. Multiple unowned boards stay ambiguous on purpose.
|
|
831
|
+
const manifestBoards = manifest?.boards === undefined
|
|
832
|
+
? []
|
|
833
|
+
: manifest.boards
|
|
834
|
+
.filter(entry => existsSync(resolvePath(entry.path)))
|
|
835
|
+
.map(entry => artifact('pcb', resolvePath(entry.path), projectPath))
|
|
836
|
+
const scannedBoards = walkFiles(dir, file => file.toLowerCase().endsWith('.kicad_pcb'))
|
|
837
|
+
.map(path => artifact('pcb', path, projectPath))
|
|
838
|
+
const boards = manifestBoards.length > 0
|
|
839
|
+
? manifestBoards
|
|
840
|
+
: [...scannedBoards].sort((left, right) => boardRank(left, right, name))
|
|
841
|
+
const owned = boards.find(board => basename(board.path, '.kicad_pcb') === name) ?? boards[0]
|
|
842
|
+
const ownershipAmbiguous = manifestBoards.length === 0 && boards.length > 1
|
|
843
|
+
&& basename(owned?.path ?? '', '.kicad_pcb') !== name
|
|
844
|
+
|
|
845
|
+
const mechanical = manifest?.mechanical !== undefined
|
|
846
|
+
? manifest.mechanical.map(model => artifact('mechanical-3d', resolvePath(model.path), projectPath))
|
|
847
|
+
: walkFiles(dir, file => MECHANICAL_EXTENSIONS.has(extname(file).toLowerCase()))
|
|
848
|
+
.map(path => artifact('mechanical-3d', path, projectPath))
|
|
849
|
+
|
|
850
|
+
const sourceSchematic = schematicPath === undefined ? undefined : artifact('schematic', schematicPath, projectPath)
|
|
851
|
+
const sourceBoard = ownershipAmbiguous ? undefined : owned
|
|
852
|
+
return {
|
|
853
|
+
path: projectPath,
|
|
854
|
+
name,
|
|
855
|
+
...(sourceSchematic === undefined ? {} : { rootSheet: sourceSchematic, schematic: sourceSchematic }),
|
|
856
|
+
...(sourceSchematic === undefined ? {} : {
|
|
857
|
+
bom: { ...artifact('bom', sourceSchematic.path, projectPath, sourceSchematic.path), title: `BOM — ${sourceSchematic.title}` },
|
|
858
|
+
}),
|
|
859
|
+
...(sourceBoard === undefined ? {} : {
|
|
860
|
+
pcb3d: { ...artifact('pcb-3d', sourceBoard.path, projectPath, sourceBoard.path), title: `3D — ${sourceBoard.title}` },
|
|
861
|
+
defaultBoard: sourceBoard.path,
|
|
862
|
+
}),
|
|
863
|
+
sheets,
|
|
864
|
+
boards,
|
|
865
|
+
mechanical,
|
|
866
|
+
selectionRequired: boards.length > 1 && ownershipAmbiguous,
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** Validate and launch a native application without a shell. */
|
|
871
|
+
open(request: OpenArtifactRequest): OpenArtifactResult {
|
|
872
|
+
const path = canonical(request.artifactPath)
|
|
873
|
+
if (!existsSync(path)) {
|
|
874
|
+
throw errorWithCode(`artifact does not exist: ${path}`, 'missing-artifact', 404)
|
|
875
|
+
}
|
|
876
|
+
const installed = this.installations()
|
|
877
|
+
const ext = extname(path).toLowerCase()
|
|
878
|
+
let command: string | undefined
|
|
879
|
+
if (ext === '.kicad_sch') command = installed.kicad.schematicEditor
|
|
880
|
+
else if (ext === '.kicad_pcb') command = installed.kicad.pcbEditor
|
|
881
|
+
else if (ext === '.kicad_pro') command = installed.kicad.projectManager
|
|
882
|
+
else throw errorWithCode(`unsupported KiCad artifact: ${ext}`, 'unsupported-artifact', 415)
|
|
883
|
+
if (command === undefined) {
|
|
884
|
+
throw errorWithCode('the configured KiCad installation has no editor for this artifact', 'missing-executable', 412)
|
|
885
|
+
}
|
|
886
|
+
const settings = { cwd: dirname(path), detached: true, stdio: 'ignore' as const, windowsHide: true, shell: false as const }
|
|
887
|
+
const child = this.options.spawnProcess(command, [path], settings)
|
|
888
|
+
return { launched: true, command, args: [path], cwd: settings.cwd, ...(child.pid === undefined ? {} : { pid: child.pid }) }
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Resolve one artifact path: canonical, real, of an expected type.
|
|
893
|
+
*
|
|
894
|
+
* There is deliberately **no workspace fence**. This service only runs on the
|
|
895
|
+
* machine whose files it reads, under the same authority as the user's own
|
|
896
|
+
* editor, so a root check never protected anything the user could not already
|
|
897
|
+
* open — it only produced `403 artifact is outside the authorized workspace`
|
|
898
|
+
* whenever a panel and an agent call disagreed about a root, which is a
|
|
899
|
+
* configuration puzzle disguised as a security boundary.
|
|
900
|
+
*
|
|
901
|
+
* What remains is what makes the answer trustworthy rather than merely
|
|
902
|
+
* permitted: the path must be absolute, exist, be a regular file, be of a type
|
|
903
|
+
* this service renders, and be resolved through symlinks before anything
|
|
904
|
+
* reads it.
|
|
905
|
+
* @param artifactPath - absolute path supplied by a client or an agent tool.
|
|
906
|
+
*/
|
|
907
|
+
private authorize(artifactPath: string): { path: string; kind: 'schematic' | 'pcb' } {
|
|
908
|
+
if (!isAbsolute(artifactPath)) {
|
|
909
|
+
throw errorWithCode('artifact identity must be an absolute path', 'invalid-identity', 400)
|
|
910
|
+
}
|
|
911
|
+
const requested = canonical(artifactPath)
|
|
912
|
+
const kind = SOURCE_EXTENSIONS[extname(requested).toLowerCase()]
|
|
913
|
+
if (kind === undefined) {
|
|
914
|
+
throw errorWithCode(`unsupported artifact type: ${extname(requested)}`, 'unsupported-artifact', 415)
|
|
915
|
+
}
|
|
916
|
+
if (!existsSync(requested)) {
|
|
917
|
+
throw errorWithCode(`artifact does not exist: ${requested}`, 'missing-artifact', 404)
|
|
918
|
+
}
|
|
919
|
+
const real = realOrUndefined(requested)
|
|
920
|
+
if (real === undefined) {
|
|
921
|
+
throw errorWithCode(`artifact cannot be resolved: ${requested}`, 'invalid-identity', 400)
|
|
922
|
+
}
|
|
923
|
+
const info = statSync(real)
|
|
924
|
+
if (!info.isFile()) {
|
|
925
|
+
throw errorWithCode(`artifact is not a regular file: ${requested}`, 'invalid-identity', 400)
|
|
926
|
+
}
|
|
927
|
+
const resolvedKind = SOURCE_EXTENSIONS[extname(real).toLowerCase()]
|
|
928
|
+
if (resolvedKind === undefined) {
|
|
929
|
+
throw errorWithCode('artifact type changed during resolution', 'unsupported-artifact', 415)
|
|
930
|
+
}
|
|
931
|
+
return { path: real, kind: resolvedKind as 'schematic' | 'pcb' }
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** Saved source text plus a content-addressed revision. */
|
|
935
|
+
async readSource(request: SourceRequest): Promise<SourceResult> {
|
|
936
|
+
const { path, kind } = this.authorize(request.artifactPath)
|
|
937
|
+
const info = statSync(path)
|
|
938
|
+
if (info.size > this.maxSourceBytes) {
|
|
939
|
+
throw errorWithCode(`artifact is larger than ${this.maxSourceBytes} bytes`, 'too-large', 413)
|
|
940
|
+
}
|
|
941
|
+
const body = await readFile(path)
|
|
942
|
+
const revision = createHash('sha256').update(body).digest('hex')
|
|
943
|
+
if (request.expectedRevision !== undefined && request.expectedRevision !== ''
|
|
944
|
+
&& request.expectedRevision !== revision) {
|
|
945
|
+
throw errorWithCode(
|
|
946
|
+
`source changed since it was selected (expected ${request.expectedRevision}, found ${revision})`,
|
|
947
|
+
'stale-revision',
|
|
948
|
+
409,
|
|
949
|
+
)
|
|
950
|
+
}
|
|
951
|
+
return {
|
|
952
|
+
path,
|
|
953
|
+
kind,
|
|
954
|
+
revision,
|
|
955
|
+
bytes: body.byteLength,
|
|
956
|
+
mtimeMs: info.mtimeMs,
|
|
957
|
+
text: body.toString('utf8'),
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
private sourceRevision(path: string): string {
|
|
962
|
+
const info = statSync(path)
|
|
963
|
+
if (info.size > this.maxSourceBytes) {
|
|
964
|
+
throw errorWithCode(`artifact is larger than ${this.maxSourceBytes} bytes`, 'too-large', 413)
|
|
965
|
+
}
|
|
966
|
+
return createHash('sha256').update(readFileSync(path)).digest('hex')
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** Cache directory for one board's derived outputs. */
|
|
970
|
+
private glbDirectory(boardPath: string): string {
|
|
971
|
+
const digest = createHash('sha256').update(boardPath).digest('hex').slice(0, 16)
|
|
972
|
+
return join(this.cacheRoot, 'glb', digest)
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Generate (or reuse) the GLB for one board.
|
|
977
|
+
*
|
|
978
|
+
* - cache key includes the source content hash, so same-size/same-mtime edits invalidate
|
|
979
|
+
* - one in-flight export is shared by concurrent callers for the same revision
|
|
980
|
+
* - output is written to a temp file and renamed only after it validates
|
|
981
|
+
* - a timeout or abort leaves no partial file behind
|
|
982
|
+
*/
|
|
983
|
+
async exportGlb(request: GlbRequest): Promise<GlbResult> {
|
|
984
|
+
const { path } = this.authorize(request.artifactPath)
|
|
985
|
+
if (extname(path).toLowerCase() !== '.kicad_pcb') {
|
|
986
|
+
throw errorWithCode('GLB export requires a .kicad_pcb artifact', 'unsupported-artifact', 415)
|
|
987
|
+
}
|
|
988
|
+
const installed = this.installations()
|
|
989
|
+
if (!installed.kicad.configured || installed.kicad.cli === undefined) {
|
|
990
|
+
throw errorWithCode(
|
|
991
|
+
installed.kicad.error ?? 'the configured KiCad installation has no kicad-cli',
|
|
992
|
+
'not-configured',
|
|
993
|
+
412,
|
|
994
|
+
)
|
|
995
|
+
}
|
|
996
|
+
const cli = installed.kicad.cli
|
|
997
|
+
const revision = this.sourceRevision(path)
|
|
998
|
+
const key = `${path}:${revision}`
|
|
999
|
+
const cached = this.glbCache.get(key)
|
|
1000
|
+
if (cached !== undefined && existsSync(cached.file)) {
|
|
1001
|
+
const info = statSync(cached.file)
|
|
1002
|
+
return { ...cached, bytes: info.size, cached: true }
|
|
1003
|
+
}
|
|
1004
|
+
const pending = this.glbPending.get(key)
|
|
1005
|
+
if (pending !== undefined) return pending
|
|
1006
|
+
|
|
1007
|
+
const directory = this.glbDirectory(path)
|
|
1008
|
+
const target = join(directory, `board-${revision.slice(0, 16)}.glb`)
|
|
1009
|
+
const running = (async (): Promise<GlbResult> => {
|
|
1010
|
+
mkdirSync(directory, { recursive: true })
|
|
1011
|
+
const tempDirectory = join(directory, `tmp-${process.pid}-${String(Date.now())}`)
|
|
1012
|
+
mkdirSync(tempDirectory, { recursive: true })
|
|
1013
|
+
const tempFile = join(tempDirectory, 'board.glb')
|
|
1014
|
+
try {
|
|
1015
|
+
const result = await this.options.runCommand(
|
|
1016
|
+
cli,
|
|
1017
|
+
['pcb', 'export', 'glb', '--output', tempFile, path],
|
|
1018
|
+
{ cwd: dirname(path), timeoutMs: this.glbTimeoutMs, ...(request.signal === undefined ? {} : { signal: request.signal }) },
|
|
1019
|
+
)
|
|
1020
|
+
if (result.timedOut) {
|
|
1021
|
+
throw errorWithCode(`kicad-cli pcb export glb timed out after ${this.glbTimeoutMs} ms`, 'export-timeout', 504)
|
|
1022
|
+
}
|
|
1023
|
+
if (result.exitCode !== 0) {
|
|
1024
|
+
const detail = (result.stderr.trim() || result.stdout.trim() || `exit ${String(result.exitCode)}`).slice(0, 800)
|
|
1025
|
+
throw errorWithCode(`kicad-cli pcb export glb failed: ${detail}`, 'export-failed', 502)
|
|
1026
|
+
}
|
|
1027
|
+
if (!existsSync(tempFile)) {
|
|
1028
|
+
throw errorWithCode('kicad-cli pcb export glb produced no output', 'export-failed', 502)
|
|
1029
|
+
}
|
|
1030
|
+
const bytes = statSync(tempFile).size
|
|
1031
|
+
if (bytes === 0 || readFileSync(tempFile).subarray(0, 4).toString('ascii') !== 'glTF') {
|
|
1032
|
+
throw errorWithCode('kicad-cli wrote an invalid GLB', 'export-failed', 502)
|
|
1033
|
+
}
|
|
1034
|
+
renameSync(tempFile, target)
|
|
1035
|
+
const generated = {
|
|
1036
|
+
path,
|
|
1037
|
+
revision,
|
|
1038
|
+
bytes,
|
|
1039
|
+
generatedAt: new Date().toISOString(),
|
|
1040
|
+
cached: false,
|
|
1041
|
+
file: target,
|
|
1042
|
+
} satisfies GlbResult
|
|
1043
|
+
this.glbCache.set(key, generated)
|
|
1044
|
+
return generated
|
|
1045
|
+
} finally {
|
|
1046
|
+
rmSync(tempDirectory, { recursive: true, force: true })
|
|
1047
|
+
}
|
|
1048
|
+
})()
|
|
1049
|
+
|
|
1050
|
+
this.glbPending.set(key, running)
|
|
1051
|
+
try {
|
|
1052
|
+
return await running
|
|
1053
|
+
} finally {
|
|
1054
|
+
this.glbPending.delete(key)
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* Grouped BOM for one saved root schematic.
|
|
1060
|
+
*
|
|
1061
|
+
* Reuses KiCad's own BOM extraction (`kicad-cli sch export bom`), the same
|
|
1062
|
+
* authoritative source `analyze_kicad_module` consumes, rather than building a
|
|
1063
|
+
* second component analyser. Grouping key is every non-reference column, so
|
|
1064
|
+
* different MPNs never merge and DNP stays explicit.
|
|
1065
|
+
*/
|
|
1066
|
+
async exportBom(request: {
|
|
1067
|
+
readonly artifactPath: string
|
|
1068
|
+
readonly sessionId?: string
|
|
1069
|
+
readonly signal?: AbortSignal
|
|
1070
|
+
}): Promise<BomResult> {
|
|
1071
|
+
const { path, kind } = this.authorize(request.artifactPath)
|
|
1072
|
+
if (kind !== 'schematic') {
|
|
1073
|
+
throw errorWithCode('BOM export requires a .kicad_sch artifact', 'unsupported-artifact', 415)
|
|
1074
|
+
}
|
|
1075
|
+
const installed = this.installations()
|
|
1076
|
+
if (!installed.kicad.configured || installed.kicad.cli === undefined) {
|
|
1077
|
+
throw errorWithCode(installed.kicad.error ?? 'the configured KiCad installation has no kicad-cli', 'not-configured', 412)
|
|
1078
|
+
}
|
|
1079
|
+
const revision = this.sourceRevision(path)
|
|
1080
|
+
const key = `${path}:${revision}`
|
|
1081
|
+
const cached = this.bomCache.get(key)
|
|
1082
|
+
if (cached !== undefined) return { ...cached, cached: true }
|
|
1083
|
+
|
|
1084
|
+
const directory = join(this.cacheRoot, 'bom', createHash('sha256').update(path).digest('hex').slice(0, 16))
|
|
1085
|
+
const tempDirectory = join(directory, `tmp-${process.pid}-${String(Date.now())}`)
|
|
1086
|
+
mkdirSync(tempDirectory, { recursive: true })
|
|
1087
|
+
const tempFile = join(tempDirectory, 'bom.csv')
|
|
1088
|
+
try {
|
|
1089
|
+
const result = await this.options.runCommand(
|
|
1090
|
+
installed.kicad.cli,
|
|
1091
|
+
['sch', 'export', 'bom', '--output', tempFile, path],
|
|
1092
|
+
{ cwd: dirname(path), timeoutMs: 60_000, ...(request.signal === undefined ? {} : { signal: request.signal }) },
|
|
1093
|
+
)
|
|
1094
|
+
if (result.timedOut) throw errorWithCode('kicad-cli sch export bom timed out', 'export-timeout', 504)
|
|
1095
|
+
if (result.exitCode !== 0) {
|
|
1096
|
+
const detail = (result.stderr.trim() || result.stdout.trim() || `exit ${String(result.exitCode)}`).slice(0, 800)
|
|
1097
|
+
throw errorWithCode(`kicad-cli sch export bom failed: ${detail}`, 'export-failed', 502)
|
|
1098
|
+
}
|
|
1099
|
+
if (!existsSync(tempFile)) throw errorWithCode('kicad-cli produced no BOM output', 'export-failed', 502)
|
|
1100
|
+
const rows = groupBomRows(parseCsv(readFileSync(tempFile, 'utf8')))
|
|
1101
|
+
const generated: BomResult = {
|
|
1102
|
+
path,
|
|
1103
|
+
revision,
|
|
1104
|
+
generatedAt: new Date().toISOString(),
|
|
1105
|
+
cached: false,
|
|
1106
|
+
rows,
|
|
1107
|
+
source: 'kicad-cli-bom',
|
|
1108
|
+
}
|
|
1109
|
+
this.bomCache.set(key, generated)
|
|
1110
|
+
return generated
|
|
1111
|
+
} finally {
|
|
1112
|
+
rmSync(tempDirectory, { recursive: true, force: true })
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// -------------------------------------------------------------------------
|
|
1117
|
+
// Fabrication packaging and order submission
|
|
1118
|
+
// -------------------------------------------------------------------------
|
|
1119
|
+
|
|
1120
|
+
/** Live order settings, read at call time so a settings write is immediate. */
|
|
1121
|
+
private orderSettings(): { baseUrl: string; pageBase: string; accessToken?: string } {
|
|
1122
|
+
const live = this.config.settings?.()
|
|
1123
|
+
const configured = [live?.orderBaseUrl, this.config.orderBaseUrl, process.env.HUAQIU_ORDER_BASE_URL]
|
|
1124
|
+
.find(value => value !== undefined && value.trim() !== '')
|
|
1125
|
+
const baseUrl = (configured ?? DEFAULT_ORDER_BASE_URL).replace(/\/+$/u, '')
|
|
1126
|
+
const pageBase = (this.config.orderPageBase ?? DEFAULT_ORDER_PAGE_BASE).replace(/\/+$/u, '')
|
|
1127
|
+
const token = live?.accessToken ?? this.config.accessToken ?? process.env.HUAQIU_ACCESS_TOKEN
|
|
1128
|
+
return {
|
|
1129
|
+
baseUrl,
|
|
1130
|
+
pageBase,
|
|
1131
|
+
...(token === undefined || token.trim() === '' ? {} : { accessToken: token.trim() }),
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/** What the Order destination may do right now, without contacting anything. */
|
|
1136
|
+
async orderConfig(): Promise<OrderConfigInfo> {
|
|
1137
|
+
const installed = this.installations()
|
|
1138
|
+
const settings = this.orderSettings()
|
|
1139
|
+
return {
|
|
1140
|
+
configured: installed.kicad.configured,
|
|
1141
|
+
baseUrl: settings.baseUrl,
|
|
1142
|
+
hasToken: (await this.orderToken()) !== undefined,
|
|
1143
|
+
provider: 'huaqiu',
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* The token the order page must carry.
|
|
1149
|
+
*
|
|
1150
|
+
* An explicitly configured token wins (it makes a scripted run possible);
|
|
1151
|
+
* otherwise the signed-in Huaqiu session is used, which is the same token the
|
|
1152
|
+
* eda.cn API accepts. Absent both, ordering is refused before anything is
|
|
1153
|
+
* uploaded — the page would render signed out otherwise.
|
|
1154
|
+
*/
|
|
1155
|
+
private async orderToken(): Promise<string | undefined> {
|
|
1156
|
+
const settings = this.orderSettings()
|
|
1157
|
+
if (settings.accessToken !== undefined) return settings.accessToken
|
|
1158
|
+
if (this.config.authToken === undefined) return undefined
|
|
1159
|
+
try {
|
|
1160
|
+
const token = await this.config.authToken()
|
|
1161
|
+
return token === null || token.trim() === '' ? undefined : token.trim()
|
|
1162
|
+
} catch {
|
|
1163
|
+
return undefined
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Build the fabrication archive and the assembly inputs for one board.
|
|
1169
|
+
*
|
|
1170
|
+
* The gerber/drill export is `kicad-cli`'s own plotter, so the archive is the
|
|
1171
|
+
* same set of files a KiCad "Place order" would upload. Cached by source
|
|
1172
|
+
* revision: reopening the panel must not re-run the exporter.
|
|
1173
|
+
*/
|
|
1174
|
+
async fabricate(request: {
|
|
1175
|
+
readonly boardPath: string
|
|
1176
|
+
readonly schematicPath?: string
|
|
1177
|
+
readonly sessionId?: string
|
|
1178
|
+
readonly signal?: AbortSignal
|
|
1179
|
+
}): Promise<FabricationResult & { readonly archiveData: Uint8Array; readonly assemblyFiles?: {
|
|
1180
|
+
readonly positions: string
|
|
1181
|
+
readonly bom: string
|
|
1182
|
+
} }> {
|
|
1183
|
+
const { path } = this.authorize(request.boardPath)
|
|
1184
|
+
if (extname(path).toLowerCase() !== '.kicad_pcb') {
|
|
1185
|
+
throw errorWithCode('Fabrication packaging requires a .kicad_pcb artifact', 'unsupported-artifact', 415)
|
|
1186
|
+
}
|
|
1187
|
+
const installed = this.installations()
|
|
1188
|
+
if (!installed.kicad.configured || installed.kicad.cli === undefined) {
|
|
1189
|
+
throw errorWithCode(installed.kicad.error ?? 'the configured KiCad installation has no kicad-cli', 'not-configured', 412)
|
|
1190
|
+
}
|
|
1191
|
+
const cli = installed.kicad.cli
|
|
1192
|
+
const revision = this.sourceRevision(path)
|
|
1193
|
+
const schematicPath = request.schematicPath === undefined
|
|
1194
|
+
? undefined
|
|
1195
|
+
: this.authorize(request.schematicPath).path
|
|
1196
|
+
const key = `${path}:${revision}:${schematicPath ?? ''}`
|
|
1197
|
+
const cached = this.packageCache.get(key)
|
|
1198
|
+
if (cached !== undefined) return cached
|
|
1199
|
+
|
|
1200
|
+
const directory = join(this.cacheRoot, 'fabrication', createHash('sha256').update(path).digest('hex').slice(0, 16))
|
|
1201
|
+
const work = join(directory, `tmp-${process.pid}-${String(Date.now())}`)
|
|
1202
|
+
const plots = join(work, 'plots')
|
|
1203
|
+
const positionsFile = join(work, 'positions.raw.csv')
|
|
1204
|
+
mkdirSync(plots, { recursive: true })
|
|
1205
|
+
|
|
1206
|
+
const signal = request.signal
|
|
1207
|
+
const run = async (args: readonly string[], what: string, timeoutMs = 120_000): Promise<void> => {
|
|
1208
|
+
const result = await this.options.runCommand(cli, args, {
|
|
1209
|
+
cwd: dirname(path),
|
|
1210
|
+
timeoutMs,
|
|
1211
|
+
...(signal === undefined ? {} : { signal }),
|
|
1212
|
+
})
|
|
1213
|
+
if (result.timedOut) throw errorWithCode(`kicad-cli ${what} timed out`, 'export-timeout', 504)
|
|
1214
|
+
if (result.exitCode !== 0) {
|
|
1215
|
+
const detail = (result.stderr.trim() || result.stdout.trim() || `exit ${String(result.exitCode)}`).slice(0, 800)
|
|
1216
|
+
throw errorWithCode(`kicad-cli ${what} failed: ${detail}`, 'export-failed', 502)
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
try {
|
|
1221
|
+
await run(['pcb', 'export', 'gerbers', '--output', plots, path], 'pcb export gerbers')
|
|
1222
|
+
await run(['pcb', 'export', 'drill', '--output', plots, '--format', 'excellon',
|
|
1223
|
+
'--excellon-units', 'mm', '--drill-origin', 'absolute', path], 'pcb export drill')
|
|
1224
|
+
const plotNames = readdirSync(plots).filter(name => statSync(join(plots, name)).isFile()).sort()
|
|
1225
|
+
if (plotNames.length === 0) throw errorWithCode('kicad-cli wrote no fabrication files', 'export-failed', 502)
|
|
1226
|
+
const plotted = readExportDirectory(plots, plotNames)
|
|
1227
|
+
const archiveData = zipPackage(plotted)
|
|
1228
|
+
const facts = readBoardFacts(readFileSync(path, 'utf8'))
|
|
1229
|
+
// Validated here, not at the call sites: the UI, the HTTP route and the
|
|
1230
|
+
// agent tool all consume this one result, so the archive they show and
|
|
1231
|
+
// the package they would upload have to carry the same judgement.
|
|
1232
|
+
const validation = validateFabricationPackage(
|
|
1233
|
+
plotted.map(file => ({ name: file.name, bytes: file.data.byteLength })),
|
|
1234
|
+
facts,
|
|
1235
|
+
)
|
|
1236
|
+
|
|
1237
|
+
let assembly: FabricationResult['assembly']
|
|
1238
|
+
let assemblyFiles: { positions: string; bom: string } | undefined
|
|
1239
|
+
if (schematicPath !== undefined) {
|
|
1240
|
+
await run(['pcb', 'export', 'pos', '--format', 'csv', '--units', 'mm', '--side', 'both',
|
|
1241
|
+
'--output', positionsFile, path], 'pcb export pos')
|
|
1242
|
+
const positions = parsePositions(readFileSync(positionsFile, 'utf8'))
|
|
1243
|
+
const bom = await this.exportBom({
|
|
1244
|
+
artifactPath: schematicPath,
|
|
1245
|
+
...(signal === undefined ? {} : { signal }),
|
|
1246
|
+
})
|
|
1247
|
+
const bomRows = orderBomRows(positions, bom.rows)
|
|
1248
|
+
const positionsText = positionsCsv(positions)
|
|
1249
|
+
const bomText = orderBomCsv(bomRows)
|
|
1250
|
+
assemblyFiles = { positions: positionsText, bom: bomText }
|
|
1251
|
+
assembly = {
|
|
1252
|
+
positions: positions.length,
|
|
1253
|
+
bomLines: bomRows.length,
|
|
1254
|
+
positionsBytes: Buffer.byteLength(positionsText, 'utf8'),
|
|
1255
|
+
bomBytes: Buffer.byteLength(bomText, 'utf8'),
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
const result: FabricationResult & { archiveData: Uint8Array; assemblyFiles?: { positions: string; bom: string } } = {
|
|
1260
|
+
boardPath: path,
|
|
1261
|
+
revision,
|
|
1262
|
+
generatedAt: new Date().toISOString(),
|
|
1263
|
+
facts,
|
|
1264
|
+
archive: {
|
|
1265
|
+
zipName: `${packageName(path)}.zip`,
|
|
1266
|
+
zipBytes: archiveData.byteLength,
|
|
1267
|
+
files: plotted.map(file => ({ name: file.name, bytes: file.data.byteLength })),
|
|
1268
|
+
},
|
|
1269
|
+
validation,
|
|
1270
|
+
archiveData,
|
|
1271
|
+
...(assembly === undefined ? {} : { assembly }),
|
|
1272
|
+
...(assemblyFiles === undefined ? {} : { assemblyFiles }),
|
|
1273
|
+
}
|
|
1274
|
+
this.packageCache.set(key, result)
|
|
1275
|
+
return result
|
|
1276
|
+
} finally {
|
|
1277
|
+
rmSync(work, { recursive: true, force: true })
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Write one prepared package into a directory.
|
|
1283
|
+
*
|
|
1284
|
+
* The package is normally kept in memory: the order panel shows it, the
|
|
1285
|
+
* submit uploads it, and neither needs a file. A caller that has to hand the
|
|
1286
|
+
* archive to someone else does — and re-running the plotter for that would
|
|
1287
|
+
* produce a different revision than the one already validated. This writes
|
|
1288
|
+
* exactly the bytes that were validated.
|
|
1289
|
+
*
|
|
1290
|
+
* Files are overwritten by design: the directory holds derived output, and a
|
|
1291
|
+
* rebuild of the same board replaces the previous export rather than
|
|
1292
|
+
* accumulating copies beside it. Nothing outside `directory` is touched.
|
|
1293
|
+
*
|
|
1294
|
+
* @param prepared - the value `fabricate` returned, archive bytes included.
|
|
1295
|
+
* @param directory - target directory, created when missing.
|
|
1296
|
+
*/
|
|
1297
|
+
writePackage(
|
|
1298
|
+
prepared: FabricationResult & {
|
|
1299
|
+
readonly archiveData: Uint8Array
|
|
1300
|
+
readonly assemblyFiles?: { readonly positions: string; readonly bom: string }
|
|
1301
|
+
},
|
|
1302
|
+
directory: string,
|
|
1303
|
+
): { directory: string; files: readonly { name: string; path: string; bytes: number }[] } {
|
|
1304
|
+
const target = canonical(directory)
|
|
1305
|
+
mkdirSync(target, { recursive: true })
|
|
1306
|
+
const files: { name: string; path: string; bytes: number }[] = []
|
|
1307
|
+
const write = (name: string, data: Uint8Array | string): void => {
|
|
1308
|
+
const path = join(target, name)
|
|
1309
|
+
const payload = typeof data === 'string' ? new TextEncoder().encode(data) : data
|
|
1310
|
+
writeFileSync(path, payload)
|
|
1311
|
+
files.push({ name, path, bytes: payload.byteLength })
|
|
1312
|
+
}
|
|
1313
|
+
write(prepared.archive.zipName, prepared.archiveData)
|
|
1314
|
+
if (prepared.assemblyFiles !== undefined) {
|
|
1315
|
+
const stem = packageName(prepared.boardPath)
|
|
1316
|
+
write(`${stem}-positions.csv`, prepared.assemblyFiles.positions)
|
|
1317
|
+
write(`${stem}-bom.csv`, prepared.assemblyFiles.bom)
|
|
1318
|
+
}
|
|
1319
|
+
return { directory: target, files }
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Submit one order to the Huaqiu openapi, exactly as the KiCad action does.
|
|
1324
|
+
* PCB: every `PCB_FORM` field plus the gerber/drill archive as `file`.
|
|
1325
|
+
* SMT: `pcbFile` + `coordFile` + `bomFile` and `reqParseVO`, with the caller's
|
|
1326
|
+
* access token in `authorization`. The backend owns the order; this method
|
|
1327
|
+
* forwards the files and composes the final page URL from the returned id the
|
|
1328
|
+
* way the reference does.
|
|
1329
|
+
*/
|
|
1330
|
+
async placeOrder(request: PlaceOrderRequest): Promise<PlaceOrderResult> {
|
|
1331
|
+
const settings = this.orderSettings()
|
|
1332
|
+
const bundle = await this.fabricate({
|
|
1333
|
+
boardPath: request.boardPath,
|
|
1334
|
+
...(request.schematicPath === undefined ? {} : { schematicPath: request.schematicPath }),
|
|
1335
|
+
...(request.sessionId === undefined ? {} : { sessionId: request.sessionId }),
|
|
1336
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
1337
|
+
})
|
|
1338
|
+
// Checked after the install gate so a missing KiCad is reported as such,
|
|
1339
|
+
// but before any upload: the page would open signed out without a token.
|
|
1340
|
+
const token = await this.orderToken()
|
|
1341
|
+
if (token === undefined) {
|
|
1342
|
+
throw errorWithCode(
|
|
1343
|
+
'placing an order requires a signed-in Huaqiu account (or HUAQIU_ACCESS_TOKEN)',
|
|
1344
|
+
'unauthorized',
|
|
1345
|
+
401,
|
|
1346
|
+
)
|
|
1347
|
+
}
|
|
1348
|
+
// A package that failed validation is refused here rather than at the
|
|
1349
|
+
// backend: an order is a real purchase, and uploading a gerber set missing
|
|
1350
|
+
// a layer produces a real, wrong board. Warnings do not block.
|
|
1351
|
+
if (!bundle.validation.ok) {
|
|
1352
|
+
throw errorWithCode(
|
|
1353
|
+
`the fabrication package cannot be ordered: ${validationSummary(bundle.validation) ?? 'validation failed'}`,
|
|
1354
|
+
'package-invalid',
|
|
1355
|
+
422,
|
|
1356
|
+
)
|
|
1357
|
+
}
|
|
1358
|
+
const facts = bundle.facts
|
|
1359
|
+
const endpoint = `${settings.baseUrl}${ORDER_PATHS[request.kind]}`
|
|
1360
|
+
|
|
1361
|
+
let parts: { name: string; value: string }[]
|
|
1362
|
+
let files: { field: string; name: string; type: string; data: Uint8Array }[]
|
|
1363
|
+
let headers: Record<string, string> | undefined
|
|
1364
|
+
|
|
1365
|
+
if (request.kind === 'pcb') {
|
|
1366
|
+
const form = pcbOrderForm(facts, request.quantity === undefined ? {} : { quantity: request.quantity })
|
|
1367
|
+
parts = Object.entries(form).map(([name, value]) => ({ name, value }))
|
|
1368
|
+
files = [{ field: 'file', name: bundle.archive.zipName, type: 'application/zip', data: bundle.archiveData }]
|
|
1369
|
+
} else {
|
|
1370
|
+
if (bundle.assemblyFiles === undefined) {
|
|
1371
|
+
throw errorWithCode('SMT order placement requires the project root schematic', 'invalid-request', 400)
|
|
1372
|
+
}
|
|
1373
|
+
const smt = smtOrderForm(facts, {
|
|
1374
|
+
bomFileName: `${packageName(bundle.boardPath)}-bom.csv`,
|
|
1375
|
+
coordFileName: `${packageName(bundle.boardPath)}-positions.csv`,
|
|
1376
|
+
materialTypes: bundle.assembly?.bomLines ?? 0,
|
|
1377
|
+
...(request.quantity === undefined ? {} : { quantity: request.quantity }),
|
|
1378
|
+
})
|
|
1379
|
+
parts = [{
|
|
1380
|
+
name: 'reqParseVO',
|
|
1381
|
+
value: JSON.stringify({
|
|
1382
|
+
pcb_order: pcbOrderForm(facts, request.quantity === undefined ? {} : { quantity: request.quantity }),
|
|
1383
|
+
smt_order: smt,
|
|
1384
|
+
}),
|
|
1385
|
+
}]
|
|
1386
|
+
files = [
|
|
1387
|
+
{ field: 'pcbFile', name: bundle.archive.zipName, type: 'application/zip', data: bundle.archiveData },
|
|
1388
|
+
{
|
|
1389
|
+
field: 'coordFile', name: String(smt.coord_file_name), type: 'application/octet-stream',
|
|
1390
|
+
data: new TextEncoder().encode(bundle.assemblyFiles.positions),
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
field: 'bomFile', name: String(smt.bom_file_name), type: 'application/octet-stream',
|
|
1394
|
+
data: new TextEncoder().encode(bundle.assemblyFiles.bom),
|
|
1395
|
+
},
|
|
1396
|
+
]
|
|
1397
|
+
headers = { authorization: token }
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
const boundary = `----huaqiu${createHash('sha256').update(`${endpoint}:${String(Date.now())}`).digest('hex').slice(0, 24)}`
|
|
1401
|
+
const payload = multipartBody(parts, files, boundary)
|
|
1402
|
+
const post = this.config.postOrder ?? defaultPostOrder
|
|
1403
|
+
|
|
1404
|
+
let response: { status: number; text: string }
|
|
1405
|
+
try {
|
|
1406
|
+
response = await post(endpoint, {
|
|
1407
|
+
body: payload.body,
|
|
1408
|
+
contentType: payload.contentType,
|
|
1409
|
+
...(headers === undefined ? {} : { headers }),
|
|
1410
|
+
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
1411
|
+
})
|
|
1412
|
+
} catch (error) {
|
|
1413
|
+
const detail = error instanceof Error ? error.message : String(error)
|
|
1414
|
+
throw errorWithCode(`the order endpoint could not be reached: ${detail}`, 'order-unreachable', 502)
|
|
1415
|
+
}
|
|
1416
|
+
if (response.status < 200 || response.status >= 300) {
|
|
1417
|
+
throw errorWithCode(
|
|
1418
|
+
`the order endpoint rejected the request (HTTP ${String(response.status)}): ${response.text.slice(0, 400)}`,
|
|
1419
|
+
'order-rejected',
|
|
1420
|
+
502,
|
|
1421
|
+
)
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
let json: unknown
|
|
1425
|
+
try {
|
|
1426
|
+
json = JSON.parse(response.text)
|
|
1427
|
+
} catch {
|
|
1428
|
+
throw errorWithCode('the order endpoint returned an unreadable response', 'order-rejected', 502)
|
|
1429
|
+
}
|
|
1430
|
+
const responseUrl = orderUrlOf(json)
|
|
1431
|
+
if (responseUrl === undefined) {
|
|
1432
|
+
throw errorWithCode('the order endpoint returned no order URL', 'order-rejected', 502)
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// Reproduce the URL KiCad's own action loads in its webview, including the
|
|
1436
|
+
// exact query the hqpcb page expects. For PCB that is a page composed
|
|
1437
|
+
// around the returned id/guid; for assembly the same kind of page, composed
|
|
1438
|
+
// from the returned id with `source=bom` (BOM matching). The backend's own
|
|
1439
|
+
// string is kept as `responseUrl` for diagnostics.
|
|
1440
|
+
const ids = orderIdsFromUrl(responseUrl)
|
|
1441
|
+
const orderUrl = request.kind === 'pcb'
|
|
1442
|
+
? pcbOrderUrl(settings.pageBase, ids, token)
|
|
1443
|
+
: smtOrderUrl(settings.pageBase, ids, token) ?? smtOrderUrlFromBackend(responseUrl, token)
|
|
1444
|
+
if (orderUrl === undefined) {
|
|
1445
|
+
throw errorWithCode('the order endpoint returned an order id that cannot form a page URL', 'order-rejected', 502)
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// The page must be shown, but the *client* shows it: a DSH panel opens it in
|
|
1449
|
+
// its own Browser tab, so the host opening the OS browser too would leave two
|
|
1450
|
+
// copies of the same order. Only a caller with no client asks for `launch`,
|
|
1451
|
+
// and even then a browser that will not start never discards the order.
|
|
1452
|
+
const launch = request.launch === true
|
|
1453
|
+
let opened: { launched: boolean; launcher?: string } = { launched: false }
|
|
1454
|
+
if (launch) {
|
|
1455
|
+
try {
|
|
1456
|
+
const result = this.openOrderUrl(orderUrl)
|
|
1457
|
+
opened = { launched: true, launcher: result.command }
|
|
1458
|
+
} catch {
|
|
1459
|
+
opened = { launched: false }
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
return {
|
|
1464
|
+
kind: request.kind,
|
|
1465
|
+
orderUrl,
|
|
1466
|
+
responseUrl,
|
|
1467
|
+
...opened,
|
|
1468
|
+
status: opened.launched ? 'launched' : 'ready',
|
|
1469
|
+
message: opened.launched
|
|
1470
|
+
? `Opened the ${request.kind === 'pcb' ? 'PCB' : 'assembly'} order page in the default browser.`
|
|
1471
|
+
: `The ${request.kind === 'pcb' ? 'PCB' : 'assembly'} order page is ready at orderUrl.`,
|
|
1472
|
+
endpoint,
|
|
1473
|
+
facts,
|
|
1474
|
+
archive: bundle.archive,
|
|
1475
|
+
validation: bundle.validation,
|
|
1476
|
+
...(bundle.assembly === undefined ? {} : { assembly: bundle.assembly }),
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* Open one order page in the OS default browser.
|
|
1482
|
+
*
|
|
1483
|
+
* This is the only place a URL reaches an external program; the URL is
|
|
1484
|
+
* validated by shape first and passed as a plain argument.
|
|
1485
|
+
*/
|
|
1486
|
+
openOrderUrl(raw: string): { launched: true; command: string; url: string } {
|
|
1487
|
+
const url = externalUrlTarget(raw)
|
|
1488
|
+
const spec = this.options.openExternal(url)
|
|
1489
|
+
this.options.spawnProcess(spec.command, spec.args, {
|
|
1490
|
+
cwd: tmpdir(), detached: true, stdio: 'ignore', windowsHide: true, shell: false,
|
|
1491
|
+
})
|
|
1492
|
+
return { launched: true, command: spec.command, url }
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
/** Serve a generated GLB file, re-validating the cache entry first. */
|
|
1496
|
+
glbFile(boardPath: string, revision: string): string {
|
|
1497
|
+
const key = `${canonical(boardPath)}:${revision}`
|
|
1498
|
+
const entry = this.glbCache.get(key)
|
|
1499
|
+
if (entry === undefined || !existsSync(entry.file)) {
|
|
1500
|
+
throw errorWithCode('generated GLB is not available for this revision', 'stale-revision', 409)
|
|
1501
|
+
}
|
|
1502
|
+
return entry.file
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
/** Drop cached derived outputs for one board (or all of them). */
|
|
1506
|
+
clearCache(boardPath?: string): void {
|
|
1507
|
+
this.packageCache.clear()
|
|
1508
|
+
if (boardPath === undefined) {
|
|
1509
|
+
this.glbCache.clear()
|
|
1510
|
+
rmSync(this.cacheRoot, { recursive: true, force: true })
|
|
1511
|
+
return
|
|
1512
|
+
}
|
|
1513
|
+
const prefix = `${canonical(boardPath)}:`
|
|
1514
|
+
for (const key of [...this.glbCache.keys()]) {
|
|
1515
|
+
if (key.startsWith(prefix)) this.glbCache.delete(key)
|
|
1516
|
+
}
|
|
1517
|
+
rmSync(this.glbDirectory(canonical(boardPath)), { recursive: true, force: true })
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/** Ownership order: project-named board first, then shallower, then alphabetical. */
|
|
1522
|
+
function boardRank(left: HardwareArtifact, right: HardwareArtifact, projectName: string): number { const leftNamed = basename(left.path, '.kicad_pcb') === projectName ? 0 : 1
|
|
1523
|
+
const rightNamed = basename(right.path, '.kicad_pcb') === projectName ? 0 : 1
|
|
1524
|
+
if (leftNamed !== rightNamed) return leftNamed - rightNamed
|
|
1525
|
+
const leftDepth = left.path.split(sep).length
|
|
1526
|
+
const rightDepth = right.path.split(sep).length
|
|
1527
|
+
if (leftDepth !== rightDepth) return leftDepth - rightDepth
|
|
1528
|
+
return left.path.localeCompare(right.path)
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
/** RFC4180-style CSV reader: quoted fields, doubled quotes, CRLF rows. */
|
|
1532
|
+
export function parseCsv(text: string): string[][] {
|
|
1533
|
+
const rows: string[][] = []
|
|
1534
|
+
let row: string[] = []
|
|
1535
|
+
let field = ''
|
|
1536
|
+
let quoted = false
|
|
1537
|
+
const source = text.replace(/^\uFEFF/u, '')
|
|
1538
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
1539
|
+
const char = source[index]
|
|
1540
|
+
if (quoted) {
|
|
1541
|
+
if (char === '"') {
|
|
1542
|
+
if (source[index + 1] === '"') {
|
|
1543
|
+
field += '"'
|
|
1544
|
+
index += 1
|
|
1545
|
+
} else {
|
|
1546
|
+
quoted = false
|
|
1547
|
+
}
|
|
1548
|
+
} else {
|
|
1549
|
+
field += char
|
|
1550
|
+
}
|
|
1551
|
+
continue
|
|
1552
|
+
}
|
|
1553
|
+
if (char === '"') {
|
|
1554
|
+
quoted = true
|
|
1555
|
+
} else if (char === ',') {
|
|
1556
|
+
row.push(field)
|
|
1557
|
+
field = ''
|
|
1558
|
+
} else if (char === '\r') {
|
|
1559
|
+
continue
|
|
1560
|
+
} else if (char === '\n') {
|
|
1561
|
+
row.push(field)
|
|
1562
|
+
rows.push(row)
|
|
1563
|
+
row = []
|
|
1564
|
+
field = ''
|
|
1565
|
+
} else {
|
|
1566
|
+
field += char
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
if (field !== '' || row.length > 0) {
|
|
1570
|
+
row.push(field)
|
|
1571
|
+
rows.push(row)
|
|
1572
|
+
}
|
|
1573
|
+
return rows.filter(cells => cells.some(cell => cell.trim() !== ''))
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Group KiCad's per-reference BOM rows.
|
|
1578
|
+
*
|
|
1579
|
+
* Identity is every column except the reference and quantity columns, so a
|
|
1580
|
+
* different MPN or a DNP flag always produces a separate line; ordering follows
|
|
1581
|
+
* the first reference seen, which keeps the table stable between reads.
|
|
1582
|
+
*
|
|
1583
|
+
* Column names follow `kicad-cli sch export bom`'s default field set, which is
|
|
1584
|
+
* `Refs,Value,Footprint,Qty,DNP`; a customized `--fields` header may spell the
|
|
1585
|
+
* same columns out in full, and a grouped export may pack several references
|
|
1586
|
+
* into one cell, so both spellings and both shapes are accepted.
|
|
1587
|
+
*/
|
|
1588
|
+
export function groupBomRows(table: readonly string[][]): BomRow[] {
|
|
1589
|
+
const [header, ...body] = table
|
|
1590
|
+
if (header === undefined) return []
|
|
1591
|
+
const columns = header.map(cell => cell.trim())
|
|
1592
|
+
const find = (...aliases: readonly RegExp[]): number =>
|
|
1593
|
+
columns.findIndex(cell => aliases.some(alias => alias.test(cell)))
|
|
1594
|
+
const referenceIndex = find(/^refs?$/iu, /^references?$/iu)
|
|
1595
|
+
const quantityIndex = find(/^qty$/iu, /^quantity$/iu)
|
|
1596
|
+
const valueIndex = find(/^value$/iu)
|
|
1597
|
+
const footprintIndex = find(/^footprint$/iu)
|
|
1598
|
+
const dnpIndex = find(/^dnp$/iu)
|
|
1599
|
+
const groups = new Map<string, { references: string[]; fields: Record<string, string>; dnp: boolean }>()
|
|
1600
|
+
for (const cells of body) {
|
|
1601
|
+
const references = referenceIndex === -1
|
|
1602
|
+
? []
|
|
1603
|
+
: (cells[referenceIndex] ?? '').split(/[,;\s]+/u).map(reference => reference.trim()).filter(reference => reference !== '')
|
|
1604
|
+
if (references.length === 0) continue
|
|
1605
|
+
const fields: Record<string, string> = {}
|
|
1606
|
+
columns.forEach((column, index) => {
|
|
1607
|
+
if (index === referenceIndex || index === quantityIndex || index === valueIndex
|
|
1608
|
+
|| index === footprintIndex || index === dnpIndex) return
|
|
1609
|
+
const text = (cells[index] ?? '').trim()
|
|
1610
|
+
if (text !== '') fields[column] = text
|
|
1611
|
+
})
|
|
1612
|
+
const dnpText = dnpIndex === -1 ? '' : (cells[dnpIndex] ?? '').trim()
|
|
1613
|
+
const dnp = /^(1|true|yes|dnp|x)$/iu.test(dnpText)
|
|
1614
|
+
const identity = JSON.stringify([
|
|
1615
|
+
valueIndex === -1 ? '' : (cells[valueIndex] ?? '').trim(),
|
|
1616
|
+
footprintIndex === -1 ? '' : (cells[footprintIndex] ?? '').trim(),
|
|
1617
|
+
dnp,
|
|
1618
|
+
Object.fromEntries(Object.entries(fields).sort(([a], [b]) => a.localeCompare(b))),
|
|
1619
|
+
])
|
|
1620
|
+
const group = groups.get(identity) ?? { references: [], fields, dnp }
|
|
1621
|
+
group.references.push(...references)
|
|
1622
|
+
groups.set(identity, group)
|
|
1623
|
+
}
|
|
1624
|
+
return [...groups.entries()].map(([identity, group]) => {
|
|
1625
|
+
const [value, footprint, dnp] = JSON.parse(identity) as [string, string, boolean]
|
|
1626
|
+
return {
|
|
1627
|
+
references: group.references,
|
|
1628
|
+
quantity: group.references.length,
|
|
1629
|
+
value,
|
|
1630
|
+
footprint,
|
|
1631
|
+
dnp,
|
|
1632
|
+
fields: group.fields,
|
|
1633
|
+
} satisfies BomRow
|
|
1634
|
+
})
|
|
1635
|
+
}
|