@huaqiu/hardware-artifacts 0.7.13 → 0.7.14
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 +53 -10
- package/lib/index.mjs +80 -8
- package/lib/routes.d.mts +14 -3
- package/lib/routes.mjs +205 -10
- package/lib/service-CtVn7z8b.d.mts +568 -0
- package/lib/service-Yrc2C_eo.mjs +2005 -0
- package/lib/service.d.mts +2 -226
- package/lib/service.mjs +1 -837
- package/package.json +3 -2
- package/src/index.ts +117 -8
- package/src/order.ts +778 -0
- package/src/routes.ts +221 -10
- package/src/service.ts +692 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/hardware-artifacts",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Hardware Engineering host capability: deterministic artifact discovery, installation resolution, native application launch and compact agent context.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"dsh": "^0.2.2-rc.1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@deepseek-ai/schemastery": "^3.18.1"
|
|
26
|
+
"@deepseek-ai/schemastery": "^3.18.1",
|
|
27
|
+
"fflate": "^0.8.2"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"@deepseek-ai/cordis": "^4.0.1",
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { HardwareArtifactService } from './service.js'
|
|
|
14
14
|
export type {
|
|
15
15
|
ArtifactKind,
|
|
16
16
|
DiscoveryResult,
|
|
17
|
+
FabricationResult,
|
|
17
18
|
HardwareArtifact,
|
|
18
19
|
HardwareProject,
|
|
19
20
|
HardwareArtifactsOptions,
|
|
@@ -22,22 +23,71 @@ export type {
|
|
|
22
23
|
NativeApplication,
|
|
23
24
|
OpenArtifactRequest,
|
|
24
25
|
OpenArtifactResult,
|
|
26
|
+
OrderConfigInfo,
|
|
27
|
+
PlaceOrderRequest,
|
|
28
|
+
PlaceOrderResult,
|
|
25
29
|
} from './service.js'
|
|
26
30
|
export { HardwareArtifactService } from './service.js'
|
|
31
|
+
export {
|
|
32
|
+
DEFAULT_ORDER_BASE_URL, DEFAULT_ORDER_PAGE_BASE, ORDER_PATHS, ORDER_SOURCE_TID, orderBomCsv,
|
|
33
|
+
orderBomRows, orderIdsFromUrl, parsePositions, pcbOrderForm, pcbOrderUrl, positionsCsv,
|
|
34
|
+
readBoardFacts, smtOrderForm, smtOrderUrl, smtOrderUrlFromBackend, snapHoleTier, snapThickness,
|
|
35
|
+
snapTraceTier,
|
|
36
|
+
} from './order.js'
|
|
37
|
+
export type { BoardFacts, PositionRow } from './order.js'
|
|
27
38
|
export { createHardwareHandler, HARDWARE_ROUTE_PREFIX } from './routes.js'
|
|
39
|
+
export type { HardwareHandlerOptions, WorkspaceResolver } from './routes.js'
|
|
28
40
|
|
|
29
41
|
export const name = '@huaqiu/hardware-artifacts'
|
|
30
42
|
export const inject = ['webServer', 'systemPrompt'] as const
|
|
31
43
|
|
|
32
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* User-scoped installation settings persisted by DSH's host-backed config.
|
|
46
|
+
*
|
|
47
|
+
* Every field is `.volatile()`: DSH's settings service only projects volatile
|
|
48
|
+
* fields into editable forms, and only volatile writes are persisted to the
|
|
49
|
+
* active profile patch. A non-volatile field here would make the Hardware
|
|
50
|
+
* Engineering settings page read-only by construction.
|
|
51
|
+
*/
|
|
33
52
|
export const Config = Schema.object({
|
|
34
|
-
kicadRoot: Schema.string().default(''),
|
|
35
|
-
solidcraftRoot: Schema.string().default(''),
|
|
53
|
+
kicadRoot: Schema.string().default('').volatile(),
|
|
54
|
+
solidcraftRoot: Schema.string().default('').volatile(),
|
|
55
|
+
/** Set by the first-run wizard once setup was completed or skipped. */
|
|
56
|
+
onboardingComplete: Schema.boolean().default(false).volatile(),
|
|
57
|
+
/**
|
|
58
|
+
* Place-order origin. Empty uses `HUAQIU_ORDER_BASE_URL`, then the Huaqiu
|
|
59
|
+
* host. It is only the transport target; it does not imply the endpoint
|
|
60
|
+
* supports the order contract.
|
|
61
|
+
*/
|
|
62
|
+
orderBaseUrl: Schema.string().default('').volatile(),
|
|
63
|
+
/**
|
|
64
|
+
* Huaqiu access token for the assembly endpoint. Volatile so it stays in the
|
|
65
|
+
* profile patch and never reaches the client bundle.
|
|
66
|
+
*/
|
|
67
|
+
accessToken: Schema.string().default('').volatile(),
|
|
36
68
|
})
|
|
37
69
|
|
|
70
|
+
/**
|
|
71
|
+
* A schema field value: a plain value, or the stable reference a volatile
|
|
72
|
+
* field resolves to (`{ get(): T }`, see `@deepseek-ai/cosmokit`).
|
|
73
|
+
*/
|
|
74
|
+
export type ConfigValue<T> = T | { get(): T }
|
|
75
|
+
|
|
38
76
|
export interface HardwareArtifactsPluginConfig {
|
|
39
|
-
readonly kicadRoot?: string
|
|
40
|
-
readonly solidcraftRoot?: string
|
|
77
|
+
readonly kicadRoot?: ConfigValue<string>
|
|
78
|
+
readonly solidcraftRoot?: ConfigValue<string>
|
|
79
|
+
readonly onboardingComplete?: ConfigValue<boolean>
|
|
80
|
+
readonly orderBaseUrl?: ConfigValue<string>
|
|
81
|
+
readonly accessToken?: ConfigValue<string>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Read one config field, resolving a volatile reference at call time. */
|
|
85
|
+
function readConfig<T>(value: ConfigValue<T> | undefined): T | undefined {
|
|
86
|
+
if (value === undefined) return undefined
|
|
87
|
+
if (typeof value === 'object' && value !== null && typeof (value as { get?: unknown }).get === 'function') {
|
|
88
|
+
return (value as { get(): T }).get()
|
|
89
|
+
}
|
|
90
|
+
return value as T
|
|
41
91
|
}
|
|
42
92
|
|
|
43
93
|
declare module '@deepseek-ai/cordis' {
|
|
@@ -57,9 +107,68 @@ interface SystemPromptFace {
|
|
|
57
107
|
}
|
|
58
108
|
|
|
59
109
|
export function apply(ctx: Context, config: HardwareArtifactsPluginConfig = {}): void {
|
|
110
|
+
/**
|
|
111
|
+
* Read one optional host service without declaring it in `inject`.
|
|
112
|
+
*
|
|
113
|
+
* `hardwareArtifacts` must stay usable — and unit-testable — in a profile
|
|
114
|
+
* where auth, sessions or a sandbox policy are absent; each caller degrades
|
|
115
|
+
* on its own instead of the whole plugin refusing to mount.
|
|
116
|
+
*/
|
|
117
|
+
const hostService = <T>(name: string): T | undefined => {
|
|
118
|
+
const get = (ctx as Context & { get?: (name: string) => unknown }).get
|
|
119
|
+
return typeof get === 'function' ? get.call(ctx, name) as T | undefined : undefined
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The signed-in Huaqiu session, when the auth plugin is mounted.
|
|
124
|
+
*
|
|
125
|
+
* Read lazily rather than declared in `inject`: only the order path needs the
|
|
126
|
+
* token.
|
|
127
|
+
*/
|
|
128
|
+
const huaqiuAuth = (): { auth?: { getAccessToken?: () => Promise<string | null> } } | undefined =>
|
|
129
|
+
hostService<{ auth?: { getAccessToken?: () => Promise<string | null> } }>('huaqiuAuth')
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Workspace root of one DSH session, from the host's own session header.
|
|
133
|
+
*
|
|
134
|
+
* This is what makes authorization survive a workspace switch: the base for
|
|
135
|
+
* a read comes from the session the request names, so another session's
|
|
136
|
+
* discovery cannot revoke it. Falling back to the sandbox policy root keeps
|
|
137
|
+
* a session without a header usable instead of unauthorized.
|
|
138
|
+
*/
|
|
139
|
+
const sessionWorkspace = async (sessionId: string): Promise<string | undefined> => {
|
|
140
|
+
const live = hostService<{ get?: (id: string) => { header?: { cwd?: string } } | undefined }>('sessions')
|
|
141
|
+
?.get?.(sessionId)?.header?.cwd
|
|
142
|
+
if (live !== undefined) return live
|
|
143
|
+
try {
|
|
144
|
+
const stored = await hostService<{
|
|
145
|
+
stat?: (id: string) => Promise<{ header?: { cwd?: string } } | undefined>
|
|
146
|
+
}>('sessionPersistence')?.stat?.(sessionId)
|
|
147
|
+
if (stored?.header?.cwd !== undefined) return stored.header.cwd
|
|
148
|
+
} catch {
|
|
149
|
+
// A session the persistence layer cannot answer for is not an error here.
|
|
150
|
+
}
|
|
151
|
+
return hostService<{ workspaceRoot?: string }>('sandboxPolicy')?.workspaceRoot
|
|
152
|
+
}
|
|
153
|
+
|
|
60
154
|
const service = new HardwareArtifactService({
|
|
61
|
-
|
|
62
|
-
|
|
155
|
+
// The accessor keeps the service on the live profile config reference:
|
|
156
|
+
// a settings write is visible to the next validation without a restart.
|
|
157
|
+
settings: () => ({
|
|
158
|
+
kicadRoot: readConfig(config.kicadRoot),
|
|
159
|
+
solidcraftRoot: readConfig(config.solidcraftRoot),
|
|
160
|
+
orderBaseUrl: readConfig(config.orderBaseUrl),
|
|
161
|
+
accessToken: readConfig(config.accessToken),
|
|
162
|
+
}),
|
|
163
|
+
// hqpcb is a Huaqiu business: the login that authenticates the eda.cn API
|
|
164
|
+
// is the token the order page expects. An explicit config token still wins.
|
|
165
|
+
authToken: async () => {
|
|
166
|
+
try {
|
|
167
|
+
return (await huaqiuAuth()?.auth?.getAccessToken?.()) ?? null
|
|
168
|
+
} catch {
|
|
169
|
+
return null
|
|
170
|
+
}
|
|
171
|
+
},
|
|
63
172
|
})
|
|
64
173
|
ctx.effect(() => ctx.provide('hardwareArtifacts', service))
|
|
65
174
|
|
|
@@ -67,7 +176,7 @@ export function apply(ctx: Context, config: HardwareArtifactsPluginConfig = {}):
|
|
|
67
176
|
ctx.effect(() => ctx.webServer.register({
|
|
68
177
|
kind: 'prefix',
|
|
69
178
|
path: HARDWARE_ROUTE_PREFIX,
|
|
70
|
-
handler: createHardwareHandler(service),
|
|
179
|
+
handler: createHardwareHandler(service, { resolveWorkspace: sessionWorkspace }),
|
|
71
180
|
}), 'hardware-artifacts: local read/launch routes')
|
|
72
181
|
}
|
|
73
182
|
|