@huaqiu/dsh-engineering-workbench 0.7.27 → 0.7.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/lib/client.js +1883 -1348
- package/lib/host.mjs +89 -7
- package/package.json +3 -2
package/lib/host.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { execFile } from "node:child_process";
|
|
3
|
-
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { lstat, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { tmpdir } from "node:os";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { promisify } from "node:util";
|
|
7
8
|
import { createRequire as createRequire$1 } from "module";
|
|
8
|
-
import { randomUUID } from "node:crypto";
|
|
9
9
|
//#region \0rolldown/runtime.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
@@ -7555,6 +7555,7 @@ async function quoteBoard(kind, text, quantity, signal) {
|
|
|
7555
7555
|
const TOOL = "hardware_open_workbench";
|
|
7556
7556
|
const MODES = [
|
|
7557
7557
|
"design",
|
|
7558
|
+
"mechanical",
|
|
7558
7559
|
"review",
|
|
7559
7560
|
"manufacture"
|
|
7560
7561
|
];
|
|
@@ -7562,8 +7563,7 @@ function validRequest(value) {
|
|
|
7562
7563
|
return !!value && MODES.includes(value.view) && (value.designTool === void 0 || value.view === "design" && [
|
|
7563
7564
|
"schematic",
|
|
7564
7565
|
"pcb",
|
|
7565
|
-
"3d"
|
|
7566
|
-
"mechanical"
|
|
7566
|
+
"3d"
|
|
7567
7567
|
].includes(value.designTool)) && (value.action === void 0 || ["open", "suggest"].includes(value.action)) && [
|
|
7568
7568
|
value.path,
|
|
7569
7569
|
value.project,
|
|
@@ -7577,7 +7577,7 @@ const inject = ["tools"];
|
|
|
7577
7577
|
function apply$1(ctx) {
|
|
7578
7578
|
ctx.effect(() => ctx.tools.register({
|
|
7579
7579
|
name: TOOL,
|
|
7580
|
-
description: "Open the engineering workbench in the current conversation’s right pane. Use only when the user asks to open, show, compare or locate an engineering artifact. Choose design for a schematic/PCB, review for side-by-side, manufacture for BOM. Never use for general questions. This is navigation only and does not place orders. Supply the project when multiple KiCad projects exist.",
|
|
7580
|
+
description: "Open the engineering workbench in the current conversation’s right pane. Use only when the user asks to open, show, compare or locate an engineering artifact. Choose design for a schematic/PCB, mechanical for enclosure or part models, review for side-by-side, manufacture for BOM. Never use for general questions. This is navigation only and does not place orders. Supply the project when multiple KiCad projects exist.",
|
|
7581
7581
|
parameters: {
|
|
7582
7582
|
type: "object",
|
|
7583
7583
|
additionalProperties: false,
|
|
@@ -7624,6 +7624,22 @@ function apply$1(ctx) {
|
|
|
7624
7624
|
}), "workbench navigation tool");
|
|
7625
7625
|
}
|
|
7626
7626
|
//#endregion
|
|
7627
|
+
//#region src/bom-snapshot.ts
|
|
7628
|
+
const object = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
7629
|
+
const optionalNumber = (x) => x == null || typeof x === "number" && Number.isFinite(x);
|
|
7630
|
+
const optionalString = (x) => x == null || typeof x === "string";
|
|
7631
|
+
function candidate(x) {
|
|
7632
|
+
return object(x) && typeof x.mpn === "string" && typeof x.manufacturerId === "string" && optionalString(x.manufacturer) && optionalString(x.package) && optionalString(x.huaqiuPn) && Array.isArray(x.offers) && x.offers.every((o) => object(o) && optionalString(o.vendor) && optionalString(o.sku) && optionalNumber(o.stock) && optionalNumber(o.moq) && Array.isArray(o.priceBreaks) && o.priceBreaks.every((t) => object(t) && optionalNumber(t.breakMin) && optionalNumber(t.breakMax) && object(t.prices) && optionalNumber(t.prices.rmb) && optionalNumber(t.prices.cny)));
|
|
7633
|
+
}
|
|
7634
|
+
function validSnapshot(x) {
|
|
7635
|
+
if (!object(x) || x.schema !== 1 || typeof x.quantity !== "number" || !Number.isInteger(x.quantity) || x.quantity < 1 || x.quantity > 1e5 || typeof x.queriedAt !== "string" || typeof x.boardKey !== "string" || !object(x.quotes) || typeof x.quotes.pcb !== "string" || typeof x.quotes.smt !== "string" || !Array.isArray(x.lines)) return false;
|
|
7636
|
+
return x.lines.every((line) => {
|
|
7637
|
+
if (!object(line) || !object(line.row)) return false;
|
|
7638
|
+
const r = line.row;
|
|
7639
|
+
return Array.isArray(r.references) && r.references.every((v) => typeof v === "string") && typeof r.value === "string" && typeof r.footprint === "string" && typeof r.dnp === "boolean" && typeof r.quantity === "number" && Number.isSafeInteger(r.quantity) && object(r.fields) && Object.values(r.fields).every((v) => typeof v === "string") && optionalString(line.error) && (line.candidates === void 0 || Array.isArray(line.candidates) && line.candidates.every(candidate) && typeof line.selection === "number" && Number.isInteger(line.selection) && line.selection >= -1 && line.selection < line.candidates.length);
|
|
7640
|
+
});
|
|
7641
|
+
}
|
|
7642
|
+
//#endregion
|
|
7627
7643
|
//#region src/manufacturing-host.mjs
|
|
7628
7644
|
const run = promisify(execFile);
|
|
7629
7645
|
const route = "/api/v1/engineering-workbench/manufacture";
|
|
@@ -7639,6 +7655,49 @@ const fields = [
|
|
|
7639
7655
|
"Huaqiu PN",
|
|
7640
7656
|
"华秋料号"
|
|
7641
7657
|
];
|
|
7658
|
+
const pendingSaves = /* @__PURE__ */ new Map();
|
|
7659
|
+
async function readSavedBom(file) {
|
|
7660
|
+
let info;
|
|
7661
|
+
try {
|
|
7662
|
+
info = await lstat(file);
|
|
7663
|
+
} catch (e) {
|
|
7664
|
+
if (e.code === "ENOENT") return null;
|
|
7665
|
+
throw e;
|
|
7666
|
+
}
|
|
7667
|
+
if (!info.isFile() || info.size > 25165824) throw new Error("BOM 保存文件无效或过大。");
|
|
7668
|
+
const saved = JSON.parse(await readFile(file, "utf8"));
|
|
7669
|
+
if (!validSnapshot(saved) || typeof saved.version !== "string" || typeof saved.savedAt !== "string") throw new Error("BOM 保存文件格式无效。");
|
|
7670
|
+
return saved;
|
|
7671
|
+
}
|
|
7672
|
+
async function saveBom(file, snapshot, expectedVersion) {
|
|
7673
|
+
if (!validSnapshot(snapshot)) throw new Error("BOM 数据格式无效,请刷新并重试。");
|
|
7674
|
+
const key = process.platform === "win32" ? file.toLowerCase() : file;
|
|
7675
|
+
const write = (pendingSaves.get(key) ?? Promise.resolve()).catch(() => {}).then(async () => {
|
|
7676
|
+
if (((await readSavedBom(file))?.version ?? null) !== expectedVersion) throw new Error("此 BOM 已在其他窗口更新,请重新打开后再保存。");
|
|
7677
|
+
const version = randomUUID(), savedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7678
|
+
const temp = file + "." + version + ".tmp";
|
|
7679
|
+
try {
|
|
7680
|
+
await writeFile(temp, JSON.stringify({
|
|
7681
|
+
...snapshot,
|
|
7682
|
+
version,
|
|
7683
|
+
savedAt
|
|
7684
|
+
}), "utf8");
|
|
7685
|
+
await rename(temp, file);
|
|
7686
|
+
} finally {
|
|
7687
|
+
await rm(temp, { force: true });
|
|
7688
|
+
}
|
|
7689
|
+
return {
|
|
7690
|
+
version,
|
|
7691
|
+
savedAt
|
|
7692
|
+
};
|
|
7693
|
+
});
|
|
7694
|
+
pendingSaves.set(key, write);
|
|
7695
|
+
try {
|
|
7696
|
+
return await write;
|
|
7697
|
+
} finally {
|
|
7698
|
+
if (pendingSaves.get(key) === write) pendingSaves.delete(key);
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7642
7701
|
async function exportText(service, source, kind, signal) {
|
|
7643
7702
|
const cli = service.installations().kicad?.cli;
|
|
7644
7703
|
if (!cli) throw new Error("请在「设置 → 硬件工程」配置 KiCad。");
|
|
@@ -7767,7 +7826,30 @@ async function manufacture(ctx, input, signal) {
|
|
|
7767
7826
|
artifactPath: path,
|
|
7768
7827
|
signal
|
|
7769
7828
|
});
|
|
7770
|
-
if (
|
|
7829
|
+
if (source.kind === "schematic" && (operation === "bom" || operation === "save-bom")) {
|
|
7830
|
+
const file = source.path + ".hq-bom.json";
|
|
7831
|
+
if (operation === "save-bom") return saveBom(file, input.snapshot, input.version);
|
|
7832
|
+
let saved = null, warning = "";
|
|
7833
|
+
try {
|
|
7834
|
+
saved = await readSavedBom(file);
|
|
7835
|
+
} catch (e) {
|
|
7836
|
+
warning = "无法读取已保存的 BOM。" + e.message;
|
|
7837
|
+
}
|
|
7838
|
+
try {
|
|
7839
|
+
return {
|
|
7840
|
+
...await exportText(hardware, source, "bom", signal),
|
|
7841
|
+
saved,
|
|
7842
|
+
warning
|
|
7843
|
+
};
|
|
7844
|
+
} catch (e) {
|
|
7845
|
+
if (!saved || signal.aborted) throw e;
|
|
7846
|
+
return {
|
|
7847
|
+
rows: saved.lines.map((l) => l.row),
|
|
7848
|
+
saved,
|
|
7849
|
+
warning: "无法重新生成原理图 BOM,当前显示上次保存的版本。" + e.message
|
|
7850
|
+
};
|
|
7851
|
+
}
|
|
7852
|
+
}
|
|
7771
7853
|
if (source.kind !== "pcb") throw new Error("请选择 PCB 文件。");
|
|
7772
7854
|
if (operation === "positions") return exportText(hardware, source, "positions", signal);
|
|
7773
7855
|
if (["pcb", "smt"].includes(operation) && Number.isSafeInteger(quantity) && quantity >= 1 && quantity <= 1e5) return quoteBoard(operation, source.text, quantity, signal);
|
|
@@ -7806,4 +7888,4 @@ function apply(ctx) {
|
|
|
7806
7888
|
}), "manufacturing preview and quotes"));
|
|
7807
7889
|
}
|
|
7808
7890
|
//#endregion
|
|
7809
|
-
export { apply, inject, manufacture, name, searchOffers };
|
|
7891
|
+
export { apply, inject, manufacture, name, saveBom, searchOffers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/dsh-engineering-workbench",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "华秋工程工作台 · 设计、评审与制造",
|
|
6
6
|
"main": "./lib/host.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"inject": [
|
|
20
20
|
"@deepseek-ai/dsh-client-ui-slots",
|
|
21
21
|
"@deepseek-ai/dsh-client-ui-sidebar-right",
|
|
22
|
-
"@deepseek-ai/dsh-client-ui-conversation"
|
|
22
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
23
|
+
"@deepseek-ai/dsh-api-workspace-files"
|
|
23
24
|
]
|
|
24
25
|
}
|
|
25
26
|
},
|