@huaqiu/hardware-artifacts 0.7.23 → 0.7.25
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 +70 -3
- package/lib/index.mjs +183 -7
- package/lib/{routes-CzTSZSfL.d.mts → routes-DgdeewkN.d.mts} +23 -5
- package/lib/routes.d.mts +1 -1
- package/lib/routes.mjs +3 -3
- package/lib/{service-DQV0soSK.d.mts → service-DDUXPMvb.d.mts} +289 -9
- package/lib/{service-JazWEnwB.mjs → service-DFQ0q0uR.mjs} +734 -53
- package/lib/service.d.mts +2 -2
- package/lib/service.mjs +1 -1
- package/package.json +1 -1
- package/src/index.ts +14 -0
- package/src/kicad-inputs.ts +45 -0
- package/src/order.ts +52 -3
- package/src/quote.ts +488 -0
- package/src/routes.ts +6 -3
- package/src/service.ts +442 -57
- package/src/solidcraft-inputs.ts +44 -0
- package/src/toolchain/manager.ts +36 -6
- package/src/toolchain/resolve.ts +41 -9
- package/src/tools.ts +199 -1
|
@@ -157,6 +157,15 @@ function snapOz(thicknessMm, allowed) {
|
|
|
157
157
|
for (const candidate of allowed) if (Math.abs(oz - candidate) < Math.abs(oz - best)) best = candidate;
|
|
158
158
|
return best;
|
|
159
159
|
}
|
|
160
|
+
/** A footprint's value text: the `Value` property (KiCad 8+) or its legacy `fp_text`. */
|
|
161
|
+
function footprintValue(node) {
|
|
162
|
+
for (const entry of node) {
|
|
163
|
+
if (!isNode(entry)) continue;
|
|
164
|
+
if (head(entry) === "property" && entry[1] === "Value" && typeof entry[2] === "string") return entry[2];
|
|
165
|
+
if (head(entry) === "fp_text" && entry[1] === "value" && typeof entry[2] === "string") return entry[2];
|
|
166
|
+
}
|
|
167
|
+
return "";
|
|
168
|
+
}
|
|
160
169
|
/**
|
|
161
170
|
* Derive the fabrication facts the order form needs from a saved board.
|
|
162
171
|
*
|
|
@@ -185,6 +194,9 @@ function readBoardFacts(text) {
|
|
|
185
194
|
let minViaDrillMm;
|
|
186
195
|
let smdPads = 0;
|
|
187
196
|
let allPads = 0;
|
|
197
|
+
let smdPadCount = 0;
|
|
198
|
+
let pthPadCount = 0;
|
|
199
|
+
const parts = /* @__PURE__ */ new Set();
|
|
188
200
|
for (const node of root) {
|
|
189
201
|
if (!isNode(node)) continue;
|
|
190
202
|
const name = head(node);
|
|
@@ -199,9 +211,18 @@ function readBoardFacts(text) {
|
|
|
199
211
|
continue;
|
|
200
212
|
}
|
|
201
213
|
if (name === "footprint") {
|
|
202
|
-
const
|
|
203
|
-
allPads +=
|
|
204
|
-
|
|
214
|
+
const padNodes = node.filter((entry) => isNode(entry) && head(entry) === "pad");
|
|
215
|
+
allPads += padNodes.length;
|
|
216
|
+
const attr = child(node, "attr") ?? [];
|
|
217
|
+
if (attr.some((entry) => entry === "smd")) smdPads += padNodes.length;
|
|
218
|
+
for (const pad of padNodes) if (pad[2] === "smd") smdPadCount += 1;
|
|
219
|
+
else if (pad[2] === "thru_hole") pthPadCount += 1;
|
|
220
|
+
const libId = typeof node[1] === "string" ? node[1] : "";
|
|
221
|
+
const excluded = attr.some((entry) => entry === "exclude_from_bom" || entry === "board_only");
|
|
222
|
+
if (libId !== "" && !excluded) {
|
|
223
|
+
const footprint = libId.slice(libId.lastIndexOf(":") + 1);
|
|
224
|
+
parts.add(`${footprintValue(node)}\u0000${footprint}`);
|
|
225
|
+
}
|
|
205
226
|
continue;
|
|
206
227
|
}
|
|
207
228
|
if (name === "segment" || name === "arc") {
|
|
@@ -249,6 +270,11 @@ function readBoardFacts(text) {
|
|
|
249
270
|
4
|
|
250
271
|
]) },
|
|
251
272
|
...allPads === 0 ? {} : { padCount: smdPads > 0 ? smdPads : allPads },
|
|
273
|
+
...allPads === 0 ? {} : {
|
|
274
|
+
smdPadCount,
|
|
275
|
+
pthPadCount
|
|
276
|
+
},
|
|
277
|
+
...parts.size === 0 ? {} : { partCount: parts.size },
|
|
252
278
|
...Object.keys(copperAliases).length === 0 ? {} : { copperAliases }
|
|
253
279
|
};
|
|
254
280
|
}
|
|
@@ -700,6 +726,50 @@ function packageName(boardPath) {
|
|
|
700
726
|
return basename(boardPath).replace(/\.kicad_pcb$/iu, "");
|
|
701
727
|
}
|
|
702
728
|
//#endregion
|
|
729
|
+
//#region src/kicad-inputs.ts
|
|
730
|
+
/**
|
|
731
|
+
* What KiCad verifiably opens as a *design document*, and what it does not.
|
|
732
|
+
*
|
|
733
|
+
* This list is the routing table's KiCad half, and it is deliberately short:
|
|
734
|
+
* each suffix here has an editor resolution behind it in `service.open()` —
|
|
735
|
+
* `eeschema` for a schematic, `pcbnew` for a board, `kicad` for a project — and
|
|
736
|
+
* that resolution is what the launch path has always used and what the tests
|
|
737
|
+
* exercise. A suffix without an editor is not offered, because §2 of the
|
|
738
|
+
* toolchain-aware open-in-app task enables a format only after its support is
|
|
739
|
+
* verified rather than assumed.
|
|
740
|
+
*
|
|
741
|
+
* `.kicad_wks` is the case that proves the rule: KiCad's page-layout editor does
|
|
742
|
+
* open worksheet files from its own File menu, but this product resolves no
|
|
743
|
+
* worksheet editor, has no launch path for one, and therefore does not claim it.
|
|
744
|
+
* Adding it later is adding a resolution *and* a test, not adding a string here.
|
|
745
|
+
*
|
|
746
|
+
* The list lives in this module — not in the client action, not in the previewer
|
|
747
|
+
* — so the document action, the launch route and the agent prompt cannot
|
|
748
|
+
* disagree about what a KiCad hand-off accepts.
|
|
749
|
+
*
|
|
750
|
+
* @module @huaqiu/hardware-artifacts/kicad-inputs
|
|
751
|
+
*/
|
|
752
|
+
/** Suffixes KiCad's editors open as design documents, lower case, no dot. */
|
|
753
|
+
const KICAD_INPUT_EXTENSIONS = Object.freeze([
|
|
754
|
+
"kicad_sch",
|
|
755
|
+
"kicad_pcb",
|
|
756
|
+
"kicad_pro"
|
|
757
|
+
]);
|
|
758
|
+
/** Display form of {@link KICAD_INPUT_EXTENSIONS}, for capability text and prompts. */
|
|
759
|
+
const KICAD_INPUT_FORMATS = Object.freeze(KICAD_INPUT_EXTENSIONS.map((extension) => `.${extension}`));
|
|
760
|
+
/**
|
|
761
|
+
* Is this path a KiCad document this product can hand to a configured editor?
|
|
762
|
+
* @param path - any filesystem path or bare file name; only its suffix is read.
|
|
763
|
+
* @returns true for a verified KiCad design document, false for everything else.
|
|
764
|
+
*/
|
|
765
|
+
function isKicadInput(path) {
|
|
766
|
+
const lower = path.toLowerCase();
|
|
767
|
+
const dot = lower.lastIndexOf(".");
|
|
768
|
+
if (dot === -1) return false;
|
|
769
|
+
const suffix = lower.slice(dot + 1).replace(/[?#].*$/u, "");
|
|
770
|
+
return KICAD_INPUT_EXTENSIONS.includes(suffix);
|
|
771
|
+
}
|
|
772
|
+
//#endregion
|
|
703
773
|
//#region src/package.ts
|
|
704
774
|
/**
|
|
705
775
|
* Gerber/drill suffixes that carry no fabrication intent.
|
|
@@ -888,6 +958,394 @@ function validationSummary(validation) {
|
|
|
888
958
|
return [...validation.errors, ...validation.warnings].map((issue) => issue.message).join("; ");
|
|
889
959
|
}
|
|
890
960
|
//#endregion
|
|
961
|
+
//#region src/quote.ts
|
|
962
|
+
/**
|
|
963
|
+
* Real-time PCB and SMT price quoting, straight from the board file.
|
|
964
|
+
*
|
|
965
|
+
* `order.ts` can already reach the Huaqiu *order* endpoints, but an order
|
|
966
|
+
* endpoint answers with a page URL — the price is drawn by that page, which is
|
|
967
|
+
* why asking "how much is this board?" used to mean opening the order page.
|
|
968
|
+
* The vendor has a second, separate endpoint family for that question:
|
|
969
|
+
*
|
|
970
|
+
* PCB POST <base>/openapi/api/hqpcb/public/ajax_valuation form
|
|
971
|
+
* SMT POST <base>/openapi/api/smt-hqchip/smtservice/app/price/pricing JSON
|
|
972
|
+
*
|
|
973
|
+
* Both are anonymous (no login, no token, no order id), both return itemized
|
|
974
|
+
* JSON, and neither knows anything about KiCad — so a price needs no running
|
|
975
|
+
* editor, no HQ Edge and no `kicad-cli`: only the `.kicad_pcb` file, whose
|
|
976
|
+
* geometry and pad counts are read by `readBoardFacts`.
|
|
977
|
+
*
|
|
978
|
+
* The PCB form is deliberately built *on top of* `pcbOrderForm`: the quote is
|
|
979
|
+
* the price of the exact form this plugin would order, with only the five
|
|
980
|
+
* fields the valuation endpoint insists on (its region/transport block plus a
|
|
981
|
+
* delivery address) replaced. Anything else the board or the caller controls
|
|
982
|
+
* therefore cannot drift between "what the agent quoted" and "what the order
|
|
983
|
+
* page shows".
|
|
984
|
+
*
|
|
985
|
+
* Wire contract provenance: the same one hq-edge implements for
|
|
986
|
+
* `hq.fab.v1.QuoteService` (`apps/server/src/quote/{defaults,serialize,parse}`),
|
|
987
|
+
* itself ported from the reference plugin's `pcb_price_model.py` /
|
|
988
|
+
* `smt_price_model.py` and the KiCad copilot's quote views. Two behaviours are
|
|
989
|
+
* load-bearing and were verified against the live endpoint while writing this:
|
|
990
|
+
*
|
|
991
|
+
* - `pbnum` (panel count) and `address` are REQUIRED; omitting either is a
|
|
992
|
+
* Spring `400 Bad Request` with no explanation. `insidecopper` must be
|
|
993
|
+
* present even for 2-layer boards (value 0).
|
|
994
|
+
* - `total` already includes `expressage` (shipping), so the fee items plus
|
|
995
|
+
* the shipping line are what the total is made of — never add them twice.
|
|
996
|
+
*
|
|
997
|
+
* Nothing here mutates state: a quote creates no order, uploads nothing and
|
|
998
|
+
* needs no confirmation.
|
|
999
|
+
*
|
|
1000
|
+
* @module
|
|
1001
|
+
*/
|
|
1002
|
+
/** Endpoint paths relative to the quote base URL (the host, not a DSH route). */
|
|
1003
|
+
const QUOTE_PATHS = Object.freeze({
|
|
1004
|
+
pcb: "/openapi/api/hqpcb/public/ajax_valuation",
|
|
1005
|
+
smt: "/openapi/api/smt-hqchip/smtservice/app/price/pricing"
|
|
1006
|
+
});
|
|
1007
|
+
/** Origin serving the two valuation endpoints. */
|
|
1008
|
+
const DEFAULT_QUOTE_BASE_URL = "https://www.eda.cn";
|
|
1009
|
+
/** Boards per quote when the caller names no quantity (the reference default). */
|
|
1010
|
+
const DEFAULT_QUOTE_QUANTITY = 5;
|
|
1011
|
+
/** Solder mask colours the price endpoint knows, by the form's Chinese label. */
|
|
1012
|
+
const MASK_LABEL = Object.freeze({
|
|
1013
|
+
green: "绿色",
|
|
1014
|
+
red: "红色",
|
|
1015
|
+
yellow: "黄色",
|
|
1016
|
+
blue: "蓝色",
|
|
1017
|
+
white: "白色",
|
|
1018
|
+
black: "黑色",
|
|
1019
|
+
matte_black: "哑黑"
|
|
1020
|
+
});
|
|
1021
|
+
/** Surface finishes, by the form's Chinese label. */
|
|
1022
|
+
const FINISH_LABEL = Object.freeze({
|
|
1023
|
+
hasl_lead: "有铅喷锡",
|
|
1024
|
+
hasl_lf: "无铅喷锡",
|
|
1025
|
+
enig: "沉金",
|
|
1026
|
+
osp: "OSP"
|
|
1027
|
+
});
|
|
1028
|
+
/**
|
|
1029
|
+
* The valuation endpoint's own transport block for the China region.
|
|
1030
|
+
*
|
|
1031
|
+
* Distinct from the order form's block (`service: ''`, `region_id: 'cn'`,
|
|
1032
|
+
* `express: ''`): the price endpoint validates its region/mail values and
|
|
1033
|
+
* refuses the quote without an `address`, while the order endpoint derives all
|
|
1034
|
+
* of that from the signed-in account. These five fields are the only ones a
|
|
1035
|
+
* quote overrides.
|
|
1036
|
+
*/
|
|
1037
|
+
const CN_QUOTE_TRANSPORT = Object.freeze({
|
|
1038
|
+
service: "pcb",
|
|
1039
|
+
region_id: "211",
|
|
1040
|
+
country: "211",
|
|
1041
|
+
express: "顺丰快递",
|
|
1042
|
+
address: "广东省深圳市"
|
|
1043
|
+
});
|
|
1044
|
+
/** The PCB form field carrying shipping — reported on its own line. */
|
|
1045
|
+
const SHIPPING_KEY = "expressage";
|
|
1046
|
+
/**
|
|
1047
|
+
* Fee keys that are not `*fee`-suffixed. Everything else the endpoint charges
|
|
1048
|
+
* for does end in `fee`, so a vendor fee we have never seen still lands in the
|
|
1049
|
+
* itemized list instead of vanishing from the total.
|
|
1050
|
+
*/
|
|
1051
|
+
const PLAIN_FEE_KEYS = [
|
|
1052
|
+
"plate",
|
|
1053
|
+
"clc",
|
|
1054
|
+
"gch",
|
|
1055
|
+
"pin",
|
|
1056
|
+
"luocao",
|
|
1057
|
+
"luocheng"
|
|
1058
|
+
];
|
|
1059
|
+
/** `mm` → the centimetre-grade string the endpoint expects. */
|
|
1060
|
+
function cm(mm) {
|
|
1061
|
+
return (mm / 10).toFixed(2);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The PCB valuation form: our own order form, plus the endpoint's transport.
|
|
1065
|
+
*
|
|
1066
|
+
* Reusing `pcbOrderForm` is the point — the thickness menu, the trace/hole
|
|
1067
|
+
* tiers, TG grade, inner copper and the default mask/finish are all resolved in
|
|
1068
|
+
* one place, so a quote can never describe a board differently from the order
|
|
1069
|
+
* this plugin would place for it.
|
|
1070
|
+
*/
|
|
1071
|
+
function pcbQuoteForm(facts, overrides = {}) {
|
|
1072
|
+
return {
|
|
1073
|
+
...pcbOrderForm(overrides.layers === void 0 || overrides.layers === facts.layers ? facts : {
|
|
1074
|
+
...facts,
|
|
1075
|
+
layers: overrides.layers
|
|
1076
|
+
}, {
|
|
1077
|
+
...overrides.quantity === void 0 ? {} : { quantity: overrides.quantity },
|
|
1078
|
+
...overrides.color === void 0 ? {} : { solderMaskColor: MASK_LABEL[overrides.color] ?? overrides.color },
|
|
1079
|
+
...overrides.surfaceFinish === void 0 ? {} : { surfaceFinish: FINISH_LABEL[overrides.surfaceFinish] ?? overrides.surfaceFinish },
|
|
1080
|
+
...overrides.thicknessMm === void 0 ? {} : { thicknessMm: overrides.thicknessMm }
|
|
1081
|
+
}),
|
|
1082
|
+
...CN_QUOTE_TRANSPORT
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* The SMT valuation form.
|
|
1087
|
+
*
|
|
1088
|
+
* Not the order form: the assembly *order* endpoint reads `pcb_ban_height` as
|
|
1089
|
+
* the board's thickness and `pcb_ban_width` as its length, while the *price*
|
|
1090
|
+
* endpoint reads them as the panel's height and width in cm. Two endpoints,
|
|
1091
|
+
* two readings of the same key names — this is why the quote builds its own
|
|
1092
|
+
* assembly form instead of borrowing `smtOrderForm`.
|
|
1093
|
+
*/
|
|
1094
|
+
function smtQuoteForm(facts, overrides = {}) {
|
|
1095
|
+
const patchPads = facts.smdPadCount ?? facts.padCount ?? 0;
|
|
1096
|
+
const plugPads = facts.pthPadCount ?? 0;
|
|
1097
|
+
return {
|
|
1098
|
+
add_plat_form: 5,
|
|
1099
|
+
patch_file_name: "",
|
|
1100
|
+
bom_file_name: "",
|
|
1101
|
+
pcb_file_name: "",
|
|
1102
|
+
application_sphere: 1,
|
|
1103
|
+
is_pcb_soft_board: 0,
|
|
1104
|
+
single_or_double_technique: overrides.sides === "single" ? "1" : "2",
|
|
1105
|
+
custom_pcb_ban: 1,
|
|
1106
|
+
bom_purchase: "1",
|
|
1107
|
+
number: String(overrides.quantity ?? 5),
|
|
1108
|
+
pcb_ban_height: cm(facts.heightMm),
|
|
1109
|
+
pcb_ban_width: cm(facts.widthMm),
|
|
1110
|
+
bom_material_type_number: String(facts.partCount ?? 1),
|
|
1111
|
+
patch_pad_number: String(patchPads),
|
|
1112
|
+
is_plug: 1,
|
|
1113
|
+
plug_number: String(plugPads),
|
|
1114
|
+
steel_type: 0,
|
|
1115
|
+
is_steel_follow_delivery: 0,
|
|
1116
|
+
solder_paste_type: 0,
|
|
1117
|
+
is_assembly_weld: 0,
|
|
1118
|
+
is_layout_cleaning: 0,
|
|
1119
|
+
is_material_baking: 0,
|
|
1120
|
+
is_welding_wire: 0,
|
|
1121
|
+
is_test: 0,
|
|
1122
|
+
is_assemble: 0,
|
|
1123
|
+
is_program_burning: 0,
|
|
1124
|
+
need_split: 0,
|
|
1125
|
+
is_increase_tinning: 0,
|
|
1126
|
+
need_conformal_coating: 0,
|
|
1127
|
+
is_first_confirm: 0,
|
|
1128
|
+
packing_type: 0,
|
|
1129
|
+
x_ray_number: 1,
|
|
1130
|
+
x_ray_unit_number: 1
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function toNumber(value) {
|
|
1134
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
1135
|
+
if (typeof value !== "string") return void 0;
|
|
1136
|
+
const trimmed = value.trim();
|
|
1137
|
+
if (trimmed === "") return void 0;
|
|
1138
|
+
const parsed = Number(trimmed);
|
|
1139
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
1140
|
+
}
|
|
1141
|
+
function round2(value) {
|
|
1142
|
+
return Math.round(value * 100) / 100;
|
|
1143
|
+
}
|
|
1144
|
+
/** A payload we cannot price is a failure, not an empty quote. */
|
|
1145
|
+
function unreadable(detail, code = "quote-unreadable") {
|
|
1146
|
+
return Object.assign(/* @__PURE__ */ new Error(`the price endpoint returned an unexpected payload: ${detail}`), {
|
|
1147
|
+
code,
|
|
1148
|
+
status: 502
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
/** "正常5天" / "5 days" → 5; hours are reported as a fraction of a day. */
|
|
1152
|
+
function leadTimeDays(name) {
|
|
1153
|
+
if (typeof name !== "string") return void 0;
|
|
1154
|
+
const digits = /\d+/u.exec(name)?.[0];
|
|
1155
|
+
if (digits === void 0) return void 0;
|
|
1156
|
+
const time = Number(digits);
|
|
1157
|
+
if (!Number.isFinite(time)) return void 0;
|
|
1158
|
+
if (name.includes("天")) return time;
|
|
1159
|
+
if (name.includes("小时") || /hour/iu.test(name)) return round2(time / 24);
|
|
1160
|
+
if (/day/iu.test(name)) return time;
|
|
1161
|
+
}
|
|
1162
|
+
/** The delivery options a `suggest.deltime` array describes. */
|
|
1163
|
+
function deliveryOf(suggest, total) {
|
|
1164
|
+
if (typeof suggest !== "object" || suggest === null) return [];
|
|
1165
|
+
const deltime = suggest["deltime"];
|
|
1166
|
+
if (!Array.isArray(deltime)) return [];
|
|
1167
|
+
const options = [];
|
|
1168
|
+
for (const entry of deltime) {
|
|
1169
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
1170
|
+
const record = entry;
|
|
1171
|
+
const name = typeof record["name"] === "string" ? record["name"] : "";
|
|
1172
|
+
if (name === "") continue;
|
|
1173
|
+
const days = leadTimeDays(name);
|
|
1174
|
+
const fee = toNumber(record["fee"]);
|
|
1175
|
+
const totalPrice = toNumber(record["total"]) ?? (fee === void 0 ? void 0 : round2(total + fee));
|
|
1176
|
+
options.push({
|
|
1177
|
+
name,
|
|
1178
|
+
...days === void 0 ? {} : { days },
|
|
1179
|
+
...totalPrice === void 0 ? {} : { totalPrice }
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
return options;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* The record that actually carries the PCB fees.
|
|
1186
|
+
*
|
|
1187
|
+
* Two shapes exist in the wild: `{data: {list: {pcb: {...}}}}` (the
|
|
1188
|
+
* international shape) and the flat one the CN endpoint returns, where the
|
|
1189
|
+
* payload itself is the fee record and `suggest` rides along. Only the `pcb`
|
|
1190
|
+
* category is a board price, so it is picked explicitly rather than letting
|
|
1191
|
+
* whichever category came last win.
|
|
1192
|
+
*/
|
|
1193
|
+
function pcbFeeRecord(body) {
|
|
1194
|
+
const data = body["data"];
|
|
1195
|
+
if (typeof data === "object" && data !== null) {
|
|
1196
|
+
const list = data["list"];
|
|
1197
|
+
if (typeof list === "object" && list !== null) {
|
|
1198
|
+
const categories = list;
|
|
1199
|
+
for (const category of ["pcb", ...Object.keys(categories)]) {
|
|
1200
|
+
const entry = categories[category];
|
|
1201
|
+
if (typeof entry === "object" && entry !== null && hasFees(entry)) return entry;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
if (typeof body["suggest"] === "object" && body["suggest"] !== null) return body;
|
|
1206
|
+
throw unreadable("no PCB fee record (data.list.pcb or suggest) in the response");
|
|
1207
|
+
}
|
|
1208
|
+
function hasFees(record) {
|
|
1209
|
+
for (const key of Object.keys(record)) if (isFeeKey(key) && toNumber(record[key]) !== void 0) return true;
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
function isFeeKey(key) {
|
|
1213
|
+
if (key === SHIPPING_KEY) return false;
|
|
1214
|
+
if (PLAIN_FEE_KEYS.includes(key)) return true;
|
|
1215
|
+
return key.endsWith("fee");
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Normalize a PCB valuation response.
|
|
1219
|
+
*
|
|
1220
|
+
* The total is the endpoint's own `total` whenever it sends one: it is the
|
|
1221
|
+
* number the order page shows, and it already includes shipping. Summing the
|
|
1222
|
+
* items is only the fallback for a payload without it, because not every fee
|
|
1223
|
+
* key is one we know about.
|
|
1224
|
+
*/
|
|
1225
|
+
function parsePcbQuote(body, quantity) {
|
|
1226
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) throw unreadable("the response is not a JSON object");
|
|
1227
|
+
const record = pcbFeeRecord(body);
|
|
1228
|
+
const items = [];
|
|
1229
|
+
for (const [key, raw] of Object.entries(record)) {
|
|
1230
|
+
if (!isFeeKey(key)) continue;
|
|
1231
|
+
const amount = toNumber(raw);
|
|
1232
|
+
if (amount === void 0 || amount === 0) continue;
|
|
1233
|
+
items.push({
|
|
1234
|
+
key,
|
|
1235
|
+
amount
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
const shipping = toNumber(record[SHIPPING_KEY]);
|
|
1239
|
+
const summed = round2(items.reduce((total, item) => total + item.amount, 0) + (shipping ?? 0));
|
|
1240
|
+
const total = toNumber(record["total"]) ?? toNumber(record["webpay"]) ?? summed;
|
|
1241
|
+
if (items.length === 0 && total === 0) throw unreadable(typeof record["msg"] === "string" ? record["msg"] : "no fees in the response", "quote-rejected");
|
|
1242
|
+
const delivery = deliveryOf(typeof record["suggest"] === "object" && record["suggest"] !== null ? record["suggest"] : body["suggest"], total);
|
|
1243
|
+
const days = leadTimeDays(record["deltime"]) ?? delivery.find((option) => option.days !== void 0)?.days;
|
|
1244
|
+
return {
|
|
1245
|
+
kind: "pcb",
|
|
1246
|
+
region: "cn",
|
|
1247
|
+
currency: "CNY",
|
|
1248
|
+
currencySymbol: "¥",
|
|
1249
|
+
quantity,
|
|
1250
|
+
totalPrice: round2(total),
|
|
1251
|
+
unitPrice: quantity > 0 ? round2(total / quantity) : round2(total),
|
|
1252
|
+
...shipping === void 0 || shipping === 0 ? {} : { shipping },
|
|
1253
|
+
...days === void 0 ? {} : { leadTimeDays: days },
|
|
1254
|
+
items,
|
|
1255
|
+
delivery
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Normalize an SMT valuation response (`{suc, body}`).
|
|
1260
|
+
*
|
|
1261
|
+
* The CN body reports `smt_goods_fee_no_tax` and `smt_goods_fee_tax`, where the
|
|
1262
|
+
* "tax" figure is the tax *amount* (13% of the net) — so the price is their
|
|
1263
|
+
* sum. It also itemizes the assembly (`boot_fee` stencil, `patch_fee`, …), all
|
|
1264
|
+
* tax included, and those lines add up to that sum exactly.
|
|
1265
|
+
*/
|
|
1266
|
+
function parseSmtQuote(body, quantity) {
|
|
1267
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) throw unreadable("the response is not a JSON object");
|
|
1268
|
+
const envelope = body;
|
|
1269
|
+
if (envelope["suc"] !== true && envelope["suc"] !== 1) throw unreadable(typeof envelope["msg"] === "string" ? envelope["msg"] : "the assembly endpoint refused the quote", "quote-rejected");
|
|
1270
|
+
const payload = envelope["body"];
|
|
1271
|
+
if (typeof payload !== "object" || payload === null) throw unreadable("the assembly response carries no body");
|
|
1272
|
+
const record = payload;
|
|
1273
|
+
const items = [];
|
|
1274
|
+
for (const [key, raw] of Object.entries(record)) {
|
|
1275
|
+
if (/^smt_(?:goods|order)_fee/u.test(key)) continue;
|
|
1276
|
+
if (!key.endsWith("fee") || key.endsWith("_no_tax")) continue;
|
|
1277
|
+
const amount = toNumber(raw);
|
|
1278
|
+
if (amount === void 0 || amount === 0) continue;
|
|
1279
|
+
items.push({
|
|
1280
|
+
key,
|
|
1281
|
+
amount
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
const noTax = toNumber(record["smt_goods_fee_no_tax"]) ?? toNumber(record["smt_order_fee_no_tax"]);
|
|
1285
|
+
const tax = toNumber(record["smt_goods_fee_tax"]) ?? toNumber(record["smt_order_fee_tax"]);
|
|
1286
|
+
const declared = toNumber(record["total"]);
|
|
1287
|
+
const total = declared ?? (noTax !== void 0 && tax !== void 0 ? round2(noTax + tax) : void 0) ?? (noTax !== void 0 || tax !== void 0 ? round2((noTax ?? 0) + (tax ?? 0)) : void 0) ?? round2(items.reduce((sum, item) => sum + item.amount, 0));
|
|
1288
|
+
if (total === 0 && items.length === 0) throw unreadable("no assembly fees in the response", "quote-rejected");
|
|
1289
|
+
return {
|
|
1290
|
+
kind: "smt",
|
|
1291
|
+
region: "cn",
|
|
1292
|
+
currency: "CNY",
|
|
1293
|
+
currencySymbol: "¥",
|
|
1294
|
+
quantity,
|
|
1295
|
+
totalPrice: round2(total),
|
|
1296
|
+
unitPrice: quantity > 0 ? round2(total / quantity) : round2(total),
|
|
1297
|
+
items,
|
|
1298
|
+
smt: {
|
|
1299
|
+
...noTax === void 0 ? {} : { noTax },
|
|
1300
|
+
...tax === void 0 ? {} : { tax },
|
|
1301
|
+
...declared === void 0 ? {} : { total: declared }
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
//#endregion
|
|
1306
|
+
//#region src/solidcraft-inputs.ts
|
|
1307
|
+
/**
|
|
1308
|
+
* What SolidCraft verifiably opens, and what it only writes.
|
|
1309
|
+
*
|
|
1310
|
+
* This list is **evidence**, not preference. It was read from the installed
|
|
1311
|
+
* distribution's own command surface (`solidcraft-cli.exe --help` and
|
|
1312
|
+
* `solidcraft-cli.exe commands export`, SolidCraft 0.49.1, `7b2bd2be`):
|
|
1313
|
+
*
|
|
1314
|
+
* - Native *inputs* are the two the CLI takes positionally or after `--in`:
|
|
1315
|
+
* `<design.sc|part.step>`. `.stp` is the same STEP family the reader accepts.
|
|
1316
|
+
* - `.stl`, `.obj`, `.3mf`, `.glb` and friends are `file.export*` **outputs**,
|
|
1317
|
+
* not inputs. Other formats reach a design only through an installed importer
|
|
1318
|
+
* *plugin* (`file.import`, `plugin.list importers`), whose presence is per
|
|
1319
|
+
* machine and therefore cannot be promised by a document action.
|
|
1320
|
+
*
|
|
1321
|
+
* Keeping this list here — one module, imported by the launch path, the
|
|
1322
|
+
* capability report and the agent prompt — is what stops the product from
|
|
1323
|
+
* inheriting the *previewer's* format list. §7.1 of the task says exactly that:
|
|
1324
|
+
* a format Three.js can draw is not thereby a format SolidCraft can open.
|
|
1325
|
+
*
|
|
1326
|
+
* @module @huaqiu/hardware-artifacts/solidcraft-inputs
|
|
1327
|
+
*/
|
|
1328
|
+
/** Suffixes SolidCraft 0.49.1 opens without an importer plugin, lower case, no dot. */
|
|
1329
|
+
const SOLIDCRAFT_INPUT_EXTENSIONS = Object.freeze([
|
|
1330
|
+
"step",
|
|
1331
|
+
"stp",
|
|
1332
|
+
"sc"
|
|
1333
|
+
]);
|
|
1334
|
+
/** Display form of {@link SOLIDCRAFT_INPUT_EXTENSIONS}, for capability text and prompts. */
|
|
1335
|
+
const SOLIDCRAFT_INPUT_FORMATS = Object.freeze(SOLIDCRAFT_INPUT_EXTENSIONS.map((extension) => `.${extension}`));
|
|
1336
|
+
/**
|
|
1337
|
+
* Is this path one SolidCraft opens natively?
|
|
1338
|
+
* @param path - any filesystem path or bare file name; only its suffix is read.
|
|
1339
|
+
* @returns true for a verified SolidCraft input, false for everything else.
|
|
1340
|
+
*/
|
|
1341
|
+
function isSolidcraftInput(path) {
|
|
1342
|
+
const lower = path.toLowerCase();
|
|
1343
|
+
const dot = lower.lastIndexOf(".");
|
|
1344
|
+
if (dot === -1) return false;
|
|
1345
|
+
const suffix = lower.slice(dot + 1).replace(/[?#].*$/u, "");
|
|
1346
|
+
return SOLIDCRAFT_INPUT_EXTENSIONS.includes(suffix);
|
|
1347
|
+
}
|
|
1348
|
+
//#endregion
|
|
891
1349
|
//#region src/toolchain/resolve.ts
|
|
892
1350
|
/**
|
|
893
1351
|
* One resolver for both external toolchains.
|
|
@@ -1048,11 +1506,12 @@ function isDirectory(path) {
|
|
|
1048
1506
|
/**
|
|
1049
1507
|
* Resolve one configured root into its executables and validated state.
|
|
1050
1508
|
*
|
|
1051
|
-
* A candidate is configured only after its primary CLI exists *and*
|
|
1052
|
-
* version probe (§5.3).
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1509
|
+
* A KiCad candidate is configured only after its primary CLI exists *and*
|
|
1510
|
+
* answers a version probe (§5.3). SolidCraft is judged per half: its GUI counts
|
|
1511
|
+
* on presence (probing it would open a window) and its CLI on a real `--version`
|
|
1512
|
+
* probe, and either half alone keeps the installation usable (§3.1, §6.2 of the
|
|
1513
|
+
* 3D/SolidCraft task). `configured` is the union of the two; `guiAvailable` and
|
|
1514
|
+
* `cliAvailable` answer "can I launch it" and "can I run it" separately.
|
|
1056
1515
|
* @param tool - which toolchain to resolve.
|
|
1057
1516
|
* @param root - configured installation root.
|
|
1058
1517
|
* @param internals - platform/probe injection.
|
|
@@ -1061,6 +1520,8 @@ function isDirectory(path) {
|
|
|
1061
1520
|
function resolveToolchain(tool, root, internals = {}) {
|
|
1062
1521
|
if (root === void 0 || root.trim() === "") return {
|
|
1063
1522
|
configured: false,
|
|
1523
|
+
guiAvailable: false,
|
|
1524
|
+
cliAvailable: false,
|
|
1064
1525
|
error: `${label(tool)} installation is not configured`
|
|
1065
1526
|
};
|
|
1066
1527
|
const installPath = canonicalPath(root);
|
|
@@ -1076,8 +1537,11 @@ function resolveToolchain(tool, root, internals = {}) {
|
|
|
1076
1537
|
...pcbEditor === void 0 ? {} : { pcbEditor }
|
|
1077
1538
|
};
|
|
1078
1539
|
if (tool === "kicad") {
|
|
1540
|
+
const guiAvailable = projectManager !== void 0 || pcbEditor !== void 0 || schematicEditor !== void 0 || app !== void 0;
|
|
1079
1541
|
if (cli === void 0) return {
|
|
1080
1542
|
configured: false,
|
|
1543
|
+
guiAvailable,
|
|
1544
|
+
cliAvailable: false,
|
|
1081
1545
|
installPath,
|
|
1082
1546
|
...app === void 0 ? {} : { app },
|
|
1083
1547
|
...editors,
|
|
@@ -1086,6 +1550,8 @@ function resolveToolchain(tool, root, internals = {}) {
|
|
|
1086
1550
|
const version = internals.probeVersion?.(cli, tool);
|
|
1087
1551
|
if (version === void 0) return {
|
|
1088
1552
|
configured: false,
|
|
1553
|
+
guiAvailable,
|
|
1554
|
+
cliAvailable: true,
|
|
1089
1555
|
installPath,
|
|
1090
1556
|
cli,
|
|
1091
1557
|
...app === void 0 ? {} : { app },
|
|
@@ -1094,6 +1560,8 @@ function resolveToolchain(tool, root, internals = {}) {
|
|
|
1094
1560
|
};
|
|
1095
1561
|
return {
|
|
1096
1562
|
configured: true,
|
|
1563
|
+
guiAvailable,
|
|
1564
|
+
cliAvailable: true,
|
|
1097
1565
|
installPath,
|
|
1098
1566
|
cli,
|
|
1099
1567
|
version,
|
|
@@ -1101,8 +1569,12 @@ function resolveToolchain(tool, root, internals = {}) {
|
|
|
1101
1569
|
...editors
|
|
1102
1570
|
};
|
|
1103
1571
|
}
|
|
1104
|
-
|
|
1572
|
+
const guiAvailable = app !== void 0;
|
|
1573
|
+
const cliAvailable = cli !== void 0;
|
|
1574
|
+
if (!guiAvailable && !cliAvailable) return {
|
|
1105
1575
|
configured: false,
|
|
1576
|
+
guiAvailable,
|
|
1577
|
+
cliAvailable,
|
|
1106
1578
|
installPath,
|
|
1107
1579
|
error: `no solidcraft executable under ${installPath}`
|
|
1108
1580
|
};
|
|
@@ -1110,6 +1582,8 @@ function resolveToolchain(tool, root, internals = {}) {
|
|
|
1110
1582
|
const version = probeTarget === void 0 ? void 0 : internals.probeVersion?.(probeTarget, tool);
|
|
1111
1583
|
return {
|
|
1112
1584
|
configured: true,
|
|
1585
|
+
guiAvailable,
|
|
1586
|
+
cliAvailable,
|
|
1113
1587
|
installPath,
|
|
1114
1588
|
...cli === void 0 ? {} : { cli },
|
|
1115
1589
|
...app === void 0 ? {} : { app },
|
|
@@ -1184,6 +1658,37 @@ function errorWithCode(message, code, status) {
|
|
|
1184
1658
|
status
|
|
1185
1659
|
});
|
|
1186
1660
|
}
|
|
1661
|
+
/** Readable text of a thrown value, without the `Error: ` prefix. */
|
|
1662
|
+
function messageOf(error) {
|
|
1663
|
+
if (error instanceof Error) return error.message;
|
|
1664
|
+
return typeof error === "string" ? error : "unknown error";
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Replace the configured installation paths in a sentence with a placeholder.
|
|
1668
|
+
*
|
|
1669
|
+
* Used for the one text this plugin sends off the machine. §8.2 of the
|
|
1670
|
+
* 3D/SolidCraft task forbids putting local installation paths in the agent
|
|
1671
|
+
* prompt: the provider needs "no solidcraft executable under <path>", not
|
|
1672
|
+
* the user's directory names.
|
|
1673
|
+
*
|
|
1674
|
+
* Replaced by identity rather than by a path-shaped regular expression: the
|
|
1675
|
+
* roots are known here, they may contain spaces and non-ASCII characters, and a
|
|
1676
|
+
* pattern loose enough to catch those would also eat prose like "step/stp".
|
|
1677
|
+
* @param text - a validation message.
|
|
1678
|
+
* @param installed - the installation report the message came from.
|
|
1679
|
+
* @returns the message with every configured path replaced by `<path>`.
|
|
1680
|
+
*/
|
|
1681
|
+
function redactPaths(text, installed) {
|
|
1682
|
+
let redacted = text;
|
|
1683
|
+
for (const info of [installed.kicad, installed.solidcraft]) for (const known of [
|
|
1684
|
+
info.root,
|
|
1685
|
+
info.executable,
|
|
1686
|
+
info.cli,
|
|
1687
|
+
info.pcbEditor,
|
|
1688
|
+
info.schematicEditor
|
|
1689
|
+
]) if (known !== void 0 && known !== "") redacted = redacted.replaceAll(known, "<path>");
|
|
1690
|
+
return redacted;
|
|
1691
|
+
}
|
|
1187
1692
|
/**
|
|
1188
1693
|
* POST one multipart order payload.
|
|
1189
1694
|
*
|
|
@@ -1460,18 +1965,17 @@ var HardwareArtifactService = class {
|
|
|
1460
1965
|
exists: (path) => isFile(path),
|
|
1461
1966
|
probeVersion: (executable) => this.options.probeVersion(executable, "kicad")
|
|
1462
1967
|
});
|
|
1463
|
-
const kicad =
|
|
1464
|
-
configured:
|
|
1968
|
+
const kicad = {
|
|
1969
|
+
configured: kicadResolution.configured,
|
|
1970
|
+
guiAvailable: kicadResolution.guiAvailable,
|
|
1971
|
+
cliAvailable: kicadResolution.cliAvailable,
|
|
1972
|
+
inputFormats: KICAD_INPUT_FORMATS,
|
|
1465
1973
|
...roots.kicadRoot === void 0 ? {} : { root: canonical(roots.kicadRoot) },
|
|
1466
1974
|
...kicadResolution.cli === void 0 ? {} : { cli: kicadResolution.cli },
|
|
1467
1975
|
...kicadResolution.version === void 0 ? {} : { version: kicadResolution.version },
|
|
1468
1976
|
...kicadResolution.projectManager === void 0 ? {} : { projectManager: kicadResolution.projectManager },
|
|
1469
1977
|
...kicadResolution.pcbEditor === void 0 ? {} : { pcbEditor: kicadResolution.pcbEditor },
|
|
1470
|
-
...kicadResolution.schematicEditor === void 0 ? {} : { schematicEditor: kicadResolution.schematicEditor }
|
|
1471
|
-
} : {
|
|
1472
|
-
configured: false,
|
|
1473
|
-
...roots.kicadRoot === void 0 ? {} : { root: canonical(roots.kicadRoot) },
|
|
1474
|
-
...kicadResolution.cli === void 0 ? {} : { cli: kicadResolution.cli },
|
|
1978
|
+
...kicadResolution.schematicEditor === void 0 ? {} : { schematicEditor: kicadResolution.schematicEditor },
|
|
1475
1979
|
...kicadResolution.error === void 0 ? {} : { error: kicadResolution.error }
|
|
1476
1980
|
};
|
|
1477
1981
|
const solidResolution = resolveToolchain("solidcraft", roots.solidcraftRoot, {
|
|
@@ -1480,15 +1984,15 @@ var HardwareArtifactService = class {
|
|
|
1480
1984
|
});
|
|
1481
1985
|
return {
|
|
1482
1986
|
kicad,
|
|
1483
|
-
solidcraft:
|
|
1484
|
-
configured:
|
|
1987
|
+
solidcraft: {
|
|
1988
|
+
configured: solidResolution.configured,
|
|
1989
|
+
guiAvailable: solidResolution.guiAvailable,
|
|
1990
|
+
cliAvailable: solidResolution.cliAvailable,
|
|
1991
|
+
inputFormats: SOLIDCRAFT_INPUT_FORMATS,
|
|
1485
1992
|
...roots.solidcraftRoot === void 0 ? {} : { root: canonical(roots.solidcraftRoot) },
|
|
1486
1993
|
...solidResolution.app === void 0 ? {} : { executable: solidResolution.app },
|
|
1487
1994
|
...solidResolution.cli === void 0 ? {} : { cli: solidResolution.cli },
|
|
1488
|
-
...solidResolution.version === void 0 ? {} : { version: solidResolution.version }
|
|
1489
|
-
} : {
|
|
1490
|
-
configured: false,
|
|
1491
|
-
...roots.solidcraftRoot === void 0 ? {} : { root: canonical(roots.solidcraftRoot) },
|
|
1995
|
+
...solidResolution.version === void 0 ? {} : { version: solidResolution.version },
|
|
1492
1996
|
...solidResolution.error === void 0 ? {} : { error: solidResolution.error }
|
|
1493
1997
|
}
|
|
1494
1998
|
};
|
|
@@ -1503,34 +2007,36 @@ var HardwareArtifactService = class {
|
|
|
1503
2007
|
if (installed.solidcraft.executable !== void 0) env.HUAQIU_SOLIDCRAFT = installed.solidcraft.executable;
|
|
1504
2008
|
return env;
|
|
1505
2009
|
}
|
|
1506
|
-
/**
|
|
2010
|
+
/**
|
|
2011
|
+
* Compact agent context: validated facts only, no project inventory dump.
|
|
2012
|
+
*
|
|
2013
|
+
* Deliberately no executable paths: this text is sent to a model provider, and
|
|
2014
|
+
* §8.2 of the 3D/SolidCraft task forbids leaking local installation paths for
|
|
2015
|
+
* no benefit — the agent never launches anything itself, it asks the Host. What
|
|
2016
|
+
* it does need is what it may claim: whether each half of SolidCraft exists,
|
|
2017
|
+
* which formats each application verifiably opens, and where the user changes
|
|
2018
|
+
* the setting.
|
|
2019
|
+
* @param current - discovery scope to describe, when one applies.
|
|
2020
|
+
* @returns the `<hardware_environment>` block for the system prompt.
|
|
2021
|
+
*/
|
|
1507
2022
|
environmentText(current) {
|
|
1508
2023
|
const installed = this.installations();
|
|
1509
2024
|
const scope = current ?? this.soleDiscovery();
|
|
1510
2025
|
const lines = ["<hardware_environment>"];
|
|
1511
2026
|
lines.push("KiCad:");
|
|
1512
2027
|
lines.push(` configured: ${String(installed.kicad.configured)}`);
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
"schematicEditor"
|
|
1518
|
-
]) {
|
|
1519
|
-
const value = installed.kicad[key];
|
|
1520
|
-
if (value !== void 0) lines.push(` ${key}: ${value}`);
|
|
1521
|
-
}
|
|
1522
|
-
if (installed.kicad.error !== void 0) lines.push(` error: ${installed.kicad.error}`);
|
|
2028
|
+
if (installed.kicad.version !== void 0) lines.push(` version: ${installed.kicad.version}`);
|
|
2029
|
+
lines.push(` gui_launch: ${String(installed.kicad.guiAvailable)}`);
|
|
2030
|
+
lines.push(` input_formats: ${KICAD_INPUT_FORMATS.join(", ")}`);
|
|
2031
|
+
if (installed.kicad.error !== void 0) lines.push(` error: ${redactPaths(installed.kicad.error, installed)}`);
|
|
1523
2032
|
lines.push("SolidCraft:");
|
|
1524
|
-
lines.push(`
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
if (value !== void 0) lines.push(` ${key}: ${value}`);
|
|
1532
|
-
}
|
|
1533
|
-
if (installed.solidcraft.error !== void 0) lines.push(` error: ${installed.solidcraft.error}`);
|
|
2033
|
+
lines.push(` installed: ${String(installed.solidcraft.configured)}`);
|
|
2034
|
+
if (installed.solidcraft.version !== void 0) lines.push(` version: ${installed.solidcraft.version}`);
|
|
2035
|
+
lines.push(` gui_launch: ${String(installed.solidcraft.guiAvailable)}`);
|
|
2036
|
+
lines.push(` cli_available: ${String(installed.solidcraft.cliAvailable)}`);
|
|
2037
|
+
lines.push(` input_formats: ${SOLIDCRAFT_INPUT_FORMATS.join(", ")}`);
|
|
2038
|
+
if (installed.solidcraft.error !== void 0) lines.push(` error: ${redactPaths(installed.solidcraft.error, installed)}`);
|
|
2039
|
+
lines.push(" note: input_formats is what SolidCraft opens natively; do not claim it can open other formats, and do not infer them from the document preview.");
|
|
1534
2040
|
const missing = [!installed.kicad.configured ? "KiCad" : void 0, !installed.solidcraft.configured ? "SolidCraft" : void 0].filter((entry) => entry !== void 0);
|
|
1535
2041
|
if (missing.length > 0) {
|
|
1536
2042
|
lines.push("setup:");
|
|
@@ -1707,18 +2213,38 @@ var HardwareArtifactService = class {
|
|
|
1707
2213
|
order
|
|
1708
2214
|
};
|
|
1709
2215
|
}
|
|
1710
|
-
/**
|
|
1711
|
-
|
|
2216
|
+
/**
|
|
2217
|
+
* Validate and launch a native application without a shell.
|
|
2218
|
+
*
|
|
2219
|
+
* Two applications, one policy: the configured portable executable is used —
|
|
2220
|
+
* never a PATH lookup, never a shell string — the document path travels as one
|
|
2221
|
+
* argv entry, and the call resolves only after the child actually spawned.
|
|
2222
|
+
* A spawn that fails (missing file, permission, bad image) rejects with
|
|
2223
|
+
* `launch-failed` instead of reporting a launch that never happened, which is
|
|
2224
|
+
* what §7.4 of the 3D/SolidCraft task asks for and what `spawn` alone cannot
|
|
2225
|
+
* give: its `error` event arrives after the call returns.
|
|
2226
|
+
* @param request - application, absolute artifact path, and the originating kind.
|
|
2227
|
+
* @returns the command, argv and working directory that were handed to the OS.
|
|
2228
|
+
*/
|
|
2229
|
+
async open(request) {
|
|
1712
2230
|
const path = canonical(request.artifactPath);
|
|
1713
2231
|
if (!existsSync(path)) throw errorWithCode(`artifact does not exist: ${path}`, "missing-artifact", 404);
|
|
1714
2232
|
const installed = this.installations();
|
|
1715
2233
|
const ext = extname(path).toLowerCase();
|
|
1716
2234
|
let command;
|
|
1717
|
-
if (
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
2235
|
+
if (request.application === "solidcraft") {
|
|
2236
|
+
if (!isSolidcraftInput(path)) throw errorWithCode(`SolidCraft does not open ${ext} natively`, "unsupported-artifact", 415);
|
|
2237
|
+
if (!installed.solidcraft.configured) throw errorWithCode(installed.solidcraft.error ?? "the configured SolidCraft installation is not usable", "not-configured", 412);
|
|
2238
|
+
command = installed.solidcraft.executable;
|
|
2239
|
+
if (command === void 0 || !installed.solidcraft.guiAvailable) throw errorWithCode("the configured SolidCraft installation has no GUI executable to launch", "missing-executable", 412);
|
|
2240
|
+
} else {
|
|
2241
|
+
if (!isKicadInput(path)) throw errorWithCode(`unsupported KiCad artifact: ${ext}`, "unsupported-artifact", 415);
|
|
2242
|
+
if (ext === ".kicad_sch") command = installed.kicad.schematicEditor;
|
|
2243
|
+
else if (ext === ".kicad_pcb") command = installed.kicad.pcbEditor;
|
|
2244
|
+
else command = installed.kicad.projectManager;
|
|
2245
|
+
if (command === void 0) throw errorWithCode("the configured KiCad installation has no editor for this artifact", "missing-executable", 412);
|
|
2246
|
+
}
|
|
2247
|
+
if (!isFile(path)) throw errorWithCode(`artifact disappeared before launch: ${path}`, "missing-artifact", 404);
|
|
1722
2248
|
const settings = {
|
|
1723
2249
|
cwd: dirname(path),
|
|
1724
2250
|
detached: true,
|
|
@@ -1726,16 +2252,72 @@ var HardwareArtifactService = class {
|
|
|
1726
2252
|
windowsHide: true,
|
|
1727
2253
|
shell: false
|
|
1728
2254
|
};
|
|
1729
|
-
const
|
|
2255
|
+
const pid = await this.launch(command, [path], settings);
|
|
1730
2256
|
return {
|
|
1731
2257
|
launched: true,
|
|
1732
2258
|
command,
|
|
1733
2259
|
args: [path],
|
|
1734
2260
|
cwd: settings.cwd,
|
|
1735
|
-
...
|
|
2261
|
+
...pid === void 0 ? {} : { pid }
|
|
1736
2262
|
};
|
|
1737
2263
|
}
|
|
1738
2264
|
/**
|
|
2265
|
+
* Spawn one detached GUI process and report only a launch that happened.
|
|
2266
|
+
*
|
|
2267
|
+
* `spawn` reports its failures through an `error` event, so returning its
|
|
2268
|
+
* handle would claim success for a path that does not exist. Waiting for
|
|
2269
|
+
* `spawn` (Node emits it after the OS accepted the exec) is the smallest
|
|
2270
|
+
* contract that keeps that claim honest; the child is then unrefed so the
|
|
2271
|
+
* Host does not own the editor's lifetime and a running instance is never
|
|
2272
|
+
* killed when a document tab closes (§7.4).
|
|
2273
|
+
* @param command - absolute executable path from the validated configuration.
|
|
2274
|
+
* @param args - argv; the document path is one entry, never interpolated.
|
|
2275
|
+
* @param settings - working directory and process options.
|
|
2276
|
+
* @returns the child's pid, when the platform reports one.
|
|
2277
|
+
*/
|
|
2278
|
+
launch(command, args, settings) {
|
|
2279
|
+
return new Promise((resolvePromise, reject) => {
|
|
2280
|
+
let child;
|
|
2281
|
+
try {
|
|
2282
|
+
child = this.options.spawnProcess(command, args, settings);
|
|
2283
|
+
} catch (error) {
|
|
2284
|
+
reject(errorWithCode(`could not start ${command}: ${messageOf(error)}`, "launch-failed", 500));
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
const { once, removeListener } = child;
|
|
2288
|
+
if (once === void 0 || removeListener === void 0) {
|
|
2289
|
+
resolvePromise(child.pid);
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
let settled = false;
|
|
2293
|
+
const finish = (settle) => {
|
|
2294
|
+
if (settled) return;
|
|
2295
|
+
settled = true;
|
|
2296
|
+
clearTimeout(timer);
|
|
2297
|
+
removeListener.call(child, "error", onError);
|
|
2298
|
+
settle();
|
|
2299
|
+
};
|
|
2300
|
+
const onError = (error) => {
|
|
2301
|
+
finish(() => {
|
|
2302
|
+
reject(errorWithCode(`could not start ${command}: ${messageOf(error)}`, "launch-failed", 500));
|
|
2303
|
+
});
|
|
2304
|
+
};
|
|
2305
|
+
const timer = setTimeout(() => {
|
|
2306
|
+
finish(() => {
|
|
2307
|
+
resolvePromise(child.pid);
|
|
2308
|
+
});
|
|
2309
|
+
}, 5e3);
|
|
2310
|
+
timer.unref?.();
|
|
2311
|
+
once.call(child, "error", onError);
|
|
2312
|
+
once.call(child, "spawn", () => {
|
|
2313
|
+
finish(() => {
|
|
2314
|
+
child.unref?.();
|
|
2315
|
+
resolvePromise(child.pid);
|
|
2316
|
+
});
|
|
2317
|
+
});
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
1739
2321
|
* Resolve one artifact path: canonical, real, of an expected type.
|
|
1740
2322
|
*
|
|
1741
2323
|
* There is deliberately **no workspace fence**. This service only runs on the
|
|
@@ -2265,6 +2847,105 @@ var HardwareArtifactService = class {
|
|
|
2265
2847
|
};
|
|
2266
2848
|
}
|
|
2267
2849
|
/**
|
|
2850
|
+
* Read one board's facts for a price, refusing a board with no outline.
|
|
2851
|
+
*
|
|
2852
|
+
* A price is driven by geometry, so a board without an Edge.Cuts outline has
|
|
2853
|
+
* nothing to price: a clear refusal beats a quote for 0 × 0 mm. No KiCad
|
|
2854
|
+
* installation is required here — the facts come from the file itself.
|
|
2855
|
+
*/
|
|
2856
|
+
boardForQuote(boardPath) {
|
|
2857
|
+
const { path } = this.authorize(boardPath);
|
|
2858
|
+
if (extname(path).toLowerCase() !== ".kicad_pcb") throw errorWithCode("a price can only be quoted for a .kicad_pcb board", "unsupported-artifact", 415);
|
|
2859
|
+
const facts = readBoardFacts(readFileSync(path, "utf8"));
|
|
2860
|
+
if (!(facts.widthMm > 0 && facts.heightMm > 0)) throw errorWithCode("the board has no Edge.Cuts outline, so it has no size to price", "quote-needs-outline", 422);
|
|
2861
|
+
return {
|
|
2862
|
+
path,
|
|
2863
|
+
facts
|
|
2864
|
+
};
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* POST one valuation request and decode its JSON.
|
|
2868
|
+
*
|
|
2869
|
+
* The same transport the order path uses, with the failure modes named: an
|
|
2870
|
+
* unreachable endpoint is not a rejected quote, and the Spring 400 the
|
|
2871
|
+
* endpoint answers a form missing a required field with is reported with that
|
|
2872
|
+
* hint instead of a bare status.
|
|
2873
|
+
*/
|
|
2874
|
+
async postQuote(endpoint, body, contentType, signal) {
|
|
2875
|
+
const post = this.config.postOrder ?? defaultPostOrder;
|
|
2876
|
+
let response;
|
|
2877
|
+
try {
|
|
2878
|
+
response = await post(endpoint, {
|
|
2879
|
+
body: Buffer.from(body, "utf8"),
|
|
2880
|
+
contentType,
|
|
2881
|
+
...signal === void 0 ? {} : { signal }
|
|
2882
|
+
});
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
throw errorWithCode(`the price endpoint could not be reached: ${error instanceof Error ? error.message : String(error)}`, "quote-unreachable", 502);
|
|
2885
|
+
}
|
|
2886
|
+
if (response.status < 200 || response.status >= 300) {
|
|
2887
|
+
const snippet = response.text.trim().slice(0, 300);
|
|
2888
|
+
const hint = snippet.includes("\"timestamp\"") ? " — the endpoint rejected the form itself (a required field is missing or malformed)" : "";
|
|
2889
|
+
throw errorWithCode(`the price endpoint rejected the request (HTTP ${String(response.status)})${hint}: ${snippet}`, "quote-rejected", 502);
|
|
2890
|
+
}
|
|
2891
|
+
try {
|
|
2892
|
+
return JSON.parse(response.text);
|
|
2893
|
+
} catch {
|
|
2894
|
+
throw errorWithCode("the price endpoint returned an unreadable response", "quote-unreadable", 502);
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Quote PCB fabrication for one board.
|
|
2899
|
+
*
|
|
2900
|
+
* Anonymous: no login, no order, no upload. The form is `pcbQuoteForm`'s —
|
|
2901
|
+
* this plugin's own order form plus the endpoint's transport block — so the
|
|
2902
|
+
* price is what the order page for this board would show.
|
|
2903
|
+
*/
|
|
2904
|
+
async quotePcb(request) {
|
|
2905
|
+
const { path, facts } = this.boardForQuote(request.boardPath);
|
|
2906
|
+
const form = pcbQuoteForm(facts, {
|
|
2907
|
+
...request.quantity === void 0 ? {} : { quantity: request.quantity },
|
|
2908
|
+
...request.layers === void 0 ? {} : { layers: request.layers },
|
|
2909
|
+
...request.thicknessMm === void 0 ? {} : { thicknessMm: request.thicknessMm },
|
|
2910
|
+
...request.color === void 0 ? {} : { color: request.color },
|
|
2911
|
+
...request.surfaceFinish === void 0 ? {} : { surfaceFinish: request.surfaceFinish }
|
|
2912
|
+
});
|
|
2913
|
+
const quantity = Math.max(1, Math.trunc(Number(form.bcount) || 5));
|
|
2914
|
+
const endpoint = `${this.orderSettings().baseUrl}${QUOTE_PATHS.pcb}`;
|
|
2915
|
+
return {
|
|
2916
|
+
...parsePcbQuote(await this.postQuote(endpoint, new URLSearchParams(form).toString(), "application/x-www-form-urlencoded", request.signal), quantity),
|
|
2917
|
+
boardPath: path,
|
|
2918
|
+
endpoint,
|
|
2919
|
+
form,
|
|
2920
|
+
facts,
|
|
2921
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
/**
|
|
2925
|
+
* Quote SMT assembly for one board.
|
|
2926
|
+
*
|
|
2927
|
+
* Also anonymous, and also without a BOM export: the pad counts and the
|
|
2928
|
+
* distinct value/footprint pairs come from the board's own footprints, which
|
|
2929
|
+
* is the same material count the assembly form would carry.
|
|
2930
|
+
*/
|
|
2931
|
+
async quoteSmt(request) {
|
|
2932
|
+
const { path, facts } = this.boardForQuote(request.boardPath);
|
|
2933
|
+
const form = smtQuoteForm(facts, {
|
|
2934
|
+
...request.quantity === void 0 ? {} : { quantity: request.quantity },
|
|
2935
|
+
...request.sides === void 0 ? {} : { sides: request.sides }
|
|
2936
|
+
});
|
|
2937
|
+
const quantity = Math.max(1, Math.trunc(Number(form.number) || 5));
|
|
2938
|
+
const endpoint = `${this.orderSettings().baseUrl}${QUOTE_PATHS.smt}`;
|
|
2939
|
+
return {
|
|
2940
|
+
...parseSmtQuote(await this.postQuote(endpoint, JSON.stringify(form), "application/json", request.signal), quantity),
|
|
2941
|
+
boardPath: path,
|
|
2942
|
+
endpoint,
|
|
2943
|
+
form,
|
|
2944
|
+
facts,
|
|
2945
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2268
2949
|
* Open one order page in the OS default browser.
|
|
2269
2950
|
*
|
|
2270
2951
|
* This is the only place a URL reaches an external program; the URL is
|
|
@@ -2419,4 +3100,4 @@ function groupBomRows(table) {
|
|
|
2419
3100
|
});
|
|
2420
3101
|
}
|
|
2421
3102
|
//#endregion
|
|
2422
|
-
export {
|
|
3103
|
+
export { ORDER_SOURCE_TID as A, smtOrderUrl as B, validationSummary as C, DEFAULT_ORDER_BASE_URL as D, isKicadInput as E, pcbOrderForm as F, snapHoleTier as H, pcbOrderUrl as I, positionsCsv as L, orderBomRows as M, orderIdsFromUrl as N, DEFAULT_ORDER_PAGE_BASE as O, parsePositions as P, readBoardFacts as R, validateFabricationPackage as S, KICAD_INPUT_FORMATS as T, snapThickness as U, smtOrderUrlFromBackend as V, snapTraceTier as W, parsePcbQuote as _, installRootFromExecutable as a, smtQuoteForm as b, normalizeVersion as c, SOLIDCRAFT_INPUT_FORMATS as d, isSolidcraftInput as f, leadTimeDays as g, QUOTE_PATHS as h, canonicalPath as i, orderBomCsv as j, ORDER_PATHS as k, resolveToolchain as l, DEFAULT_QUOTE_QUANTITY as m, groupBomRows as n, installationRootOf as o, DEFAULT_QUOTE_BASE_URL as p, parseCsv as r, label as s, HardwareArtifactService as t, SOLIDCRAFT_INPUT_EXTENSIONS as u, parseSmtQuote as v, KICAD_INPUT_EXTENSIONS as w, expectedCopperLayers as x, pcbQuoteForm as y, smtOrderForm as z };
|