@kruschdev/pascal-plugin-mit-assets 0.0.0-stage → 0.1.0

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.
Files changed (78) hide show
  1. package/ASSETS.md +298 -0
  2. package/LICENSE +21 -0
  3. package/README.md +71 -2
  4. package/dist/agent-operations.d.ts +8 -0
  5. package/dist/agent-operations.js +305 -0
  6. package/dist/agent-tools.d.ts +7 -0
  7. package/dist/agent-tools.js +128 -0
  8. package/dist/audit.d.ts +78 -0
  9. package/dist/bin/pascal-mit-assets.js +5238 -0
  10. package/dist/bom.d.ts +123 -0
  11. package/dist/cad/appliance-mep-builders.d.ts +7 -0
  12. package/dist/cad/furniture-builders.d.ts +9 -0
  13. package/dist/cad/index.d.ts +48 -0
  14. package/dist/cad/index.js +23 -0
  15. package/dist/cad/kitchen-bath-builders.d.ts +9 -0
  16. package/dist/cad/outdoor-fenestration-builders.d.ts +8 -0
  17. package/dist/cad/primitives.d.ts +56 -0
  18. package/dist/cad/props-vehicles-builders.d.ts +8 -0
  19. package/dist/chunk-2qgndrap.js +5200 -0
  20. package/dist/chunk-6hzyh6qv.js +346 -0
  21. package/dist/chunk-f72r2bmp.js +84 -0
  22. package/dist/chunk-hqgm57dv.js +310 -0
  23. package/dist/chunk-kgwk6kan.js +150 -0
  24. package/dist/chunk-raafkn3w.js +286 -0
  25. package/dist/chunk-vzmjt9dz.js +4380 -0
  26. package/dist/chunk-xhkwv6t4.js +5080 -0
  27. package/dist/hdri/index.d.ts +1 -0
  28. package/dist/hdri/index.js +322 -0
  29. package/dist/hdri/sky.d.ts +26 -0
  30. package/dist/index.d.ts +30 -0
  31. package/dist/index.js +198 -0
  32. package/dist/manifest.d.ts +46 -0
  33. package/dist/materials/index.d.ts +10 -0
  34. package/dist/materials/index.js +1464 -0
  35. package/dist/materials/ktx2.d.ts +10 -0
  36. package/dist/materials/noise.d.ts +89 -0
  37. package/dist/materials/patterns.d.ts +15 -0
  38. package/dist/nodes/mit-item.d.ts +76 -0
  39. package/dist/render.d.ts +10 -0
  40. package/dist/render.js +24 -0
  41. package/dist/scripts/build-assets.js +17129 -0
  42. package/dist/sfx/index.d.ts +1 -0
  43. package/dist/sfx/index.js +1223 -0
  44. package/dist/sfx/synth.d.ts +25 -0
  45. package/dist/sku-crosswalk.d.ts +46 -0
  46. package/dist/ui/chat-card.d.ts +7 -0
  47. package/dist/ui/host-panel.d.ts +1 -0
  48. package/dist/ui/inspector-card.d.ts +4 -0
  49. package/dist/ui/schedule-view.d.ts +1 -0
  50. package/package.json +135 -4
  51. package/src/agent-operations.ts +373 -0
  52. package/src/agent-tools.ts +136 -0
  53. package/src/audit.ts +356 -0
  54. package/src/bom.ts +512 -0
  55. package/src/cad/appliance-mep-builders.ts +1336 -0
  56. package/src/cad/furniture-builders.ts +1622 -0
  57. package/src/cad/index.ts +993 -0
  58. package/src/cad/kitchen-bath-builders.ts +1189 -0
  59. package/src/cad/outdoor-fenestration-builders.ts +1499 -0
  60. package/src/cad/primitives.ts +286 -0
  61. package/src/cad/props-vehicles-builders.ts +1065 -0
  62. package/src/hdri/index.ts +5 -0
  63. package/src/hdri/sky.ts +481 -0
  64. package/src/index.ts +127 -0
  65. package/src/manifest.ts +5296 -0
  66. package/src/materials/index.ts +56 -0
  67. package/src/materials/ktx2.ts +138 -0
  68. package/src/materials/noise.ts +417 -0
  69. package/src/materials/patterns.ts +1507 -0
  70. package/src/nodes/mit-item.ts +163 -0
  71. package/src/render.ts +25 -0
  72. package/src/sfx/index.ts +6 -0
  73. package/src/sfx/synth.ts +1495 -0
  74. package/src/sku-crosswalk.ts +3868 -0
  75. package/src/ui/chat-card.tsx +93 -0
  76. package/src/ui/host-panel.tsx +330 -0
  77. package/src/ui/inspector-card.tsx +213 -0
  78. package/src/ui/schedule-view.tsx +188 -0
package/src/bom.ts ADDED
@@ -0,0 +1,512 @@
1
+ /**
2
+ * Priced Multi-Trade Real-SKU Procurement BOM & `pascal-bom/1.1` Fragment Adapter (`src/bom.ts`).
3
+ * Ties every clean-room MIT 3D item and PBR material pack directly into CSI MasterFormat
4
+ * pricing, markup/tax rollups, formula-safe CSV export, and `@kruschdev/pascal-mep-kernel/bom`.
5
+ *
6
+ * Strictly pure TypeScript: zero React, Three.js, viewer, editor, or node:* imports.
7
+ */
8
+
9
+ import {
10
+ type MitBomTrade,
11
+ type MitItemSkuRecord,
12
+ type MitMaterialSkuRecord,
13
+ getMitItemSku,
14
+ getMitMaterialSku,
15
+ } from './sku-crosswalk'
16
+
17
+ export interface MitAssetsBomLine {
18
+ readonly sku: string
19
+ readonly slug: string
20
+ readonly catalogSku: string | null
21
+ readonly catalogRecipeId: string | null
22
+ readonly manufacturer: string
23
+ readonly series: string
24
+ readonly name: string
25
+ readonly trade: MitBomTrade
26
+ readonly csiDivision: string
27
+ readonly retailCategory: string
28
+ readonly retailChannel: string
29
+ readonly unitOfMeasure: string
30
+ readonly quantity: number
31
+ readonly unitPriceUsd: number
32
+ readonly extendedUsd: number
33
+ readonly pricingSource: MitItemSkuRecord['pricingSource']
34
+ readonly nodeIds: readonly string[]
35
+ }
36
+
37
+ export interface MitAssetsBomOptions {
38
+ readonly markupPct?: number
39
+ readonly salesTaxPct?: number
40
+ /** Optional surface material takeoff quantities (e.g. `{ 'wood/wood_parquet_14': 12 }` boxes/sqft). */
41
+ readonly materialQuantities?: Readonly<Record<string, number>>
42
+ /** Also price legacy Pascal `item` nodes whose `asset.src` maps to a known MIT slug. Default: true. */
43
+ readonly includeMappedPascalItems?: boolean
44
+ }
45
+
46
+ export interface MitAssetsBomResult {
47
+ readonly itemCount: number
48
+ readonly uniqueSkuCount: number
49
+ readonly catalogLinkedSkuCount: number
50
+ readonly lines: readonly MitAssetsBomLine[]
51
+ readonly subtotalByTrade: Readonly<Record<string, number>>
52
+ readonly subtotalByCsi: Readonly<Record<string, number>>
53
+ readonly materialSubtotalUsd: number
54
+ readonly markupPct: number
55
+ readonly markupUsd: number
56
+ readonly salesTaxPct: number
57
+ readonly salesTaxUsd: number
58
+ readonly grandTotalUsd: number
59
+ readonly unpricedNodeIds: readonly string[]
60
+ }
61
+
62
+ /**
63
+ * Canonical `pascal-bom/1.1` `PascalBomLine` & `PascalBomFragment` shapes matching
64
+ * `@kruschdev/pascal-mep-kernel/bom` (`mergePascalBoms()` + `assertValidPascalBomDocument()`),
65
+ * keeping `@kruschdev/pascal-plugin-mit-assets` standalone with zero mandatory workspace deps.
66
+ */
67
+ export type MitBomUnit =
68
+ | 'ea'
69
+ | 'lf'
70
+ | 'sf'
71
+ | 'sy'
72
+ | 'cy'
73
+ | 'cf'
74
+ | 'lb'
75
+ | 'gal'
76
+ | 'box'
77
+ | 'bag'
78
+ | 'roll'
79
+ | 'stick'
80
+ | 'sheet'
81
+ | 'panel'
82
+ | 'bundle'
83
+ | 'sq'
84
+ | 'coil'
85
+ | 'ls'
86
+ | 'hr'
87
+
88
+ export interface MitPascalBomFragmentLine {
89
+ readonly lineId: string
90
+ readonly classification: {
91
+ readonly csiMasterFormat: string
92
+ readonly csiDivision: string
93
+ readonly csiDivisionTitle: string
94
+ readonly uniFormat: string
95
+ readonly trade: MitBomTrade
96
+ readonly category: string
97
+ readonly retailCategory?: string
98
+ }
99
+ readonly identity: {
100
+ readonly sku: string
101
+ readonly name: string
102
+ readonly manufacturer?: string
103
+ readonly series?: string
104
+ readonly cadSlug?: string
105
+ }
106
+ readonly cost: {
107
+ readonly quantity: number
108
+ readonly wastePct: number
109
+ readonly unit: MitBomUnit
110
+ readonly unitLabel?: string
111
+ readonly unitMaterialUsd: number
112
+ readonly extendedMaterialUsd: number
113
+ readonly laborHoursPerUnit: number
114
+ readonly extendedLaborHours: number
115
+ readonly laborRateUsd: number
116
+ readonly extendedLaborUsd: number
117
+ readonly unitEquipmentUsd: number
118
+ readonly extendedEquipmentUsd: number
119
+ readonly extendedTotalUsd: number
120
+ }
121
+ readonly provenance: {
122
+ readonly sourcePlugin: 'custom'
123
+ readonly costScope: 'finish-sku'
124
+ readonly nodeIds: readonly string[]
125
+ readonly levels: readonly string[]
126
+ readonly rooms: readonly string[]
127
+ }
128
+ readonly partRef: {
129
+ readonly canonicalPartId: string
130
+ readonly ontologyConcept: string
131
+ }
132
+ }
133
+
134
+ export interface MitPascalBomFragment {
135
+ readonly schemaVersion: 'pascal-bom/1.1'
136
+ readonly plugin: 'custom'
137
+ readonly pluginVersion: '0.1.0'
138
+ readonly laborIncluded: false
139
+ readonly lines: readonly MitPascalBomFragmentLine[]
140
+ readonly diagnostics: readonly {
141
+ readonly severity: 'warning'
142
+ readonly code: 'UNKNOWN_SKU_NODE'
143
+ readonly plugin: 'custom'
144
+ readonly message: string
145
+ readonly nodeIds: readonly string[]
146
+ }[]
147
+ }
148
+
149
+ const CSI_TITLES: Readonly<Record<string, string>> = {
150
+ '03': 'Concrete',
151
+ '04': 'Masonry',
152
+ '05': 'Metals',
153
+ '06': 'Wood, Plastics, and Composites',
154
+ '07': 'Thermal and Moisture Protection',
155
+ '08': 'Openings',
156
+ '09': 'Finishes',
157
+ '10': 'Specialties',
158
+ '11': 'Equipment',
159
+ '12': 'Furnishings',
160
+ '21': 'Fire Suppression',
161
+ '22': 'Plumbing',
162
+ '23': 'Heating, Ventilating, and Air Conditioning (HVAC)',
163
+ '26': 'Electrical',
164
+ '27': 'Communications',
165
+ '28': 'Electronic Safety and Security',
166
+ '32': 'Exterior Improvements',
167
+ }
168
+
169
+ const CSI_UNIFORMAT: Readonly<Record<string, string>> = {
170
+ '03': 'A1010',
171
+ '04': 'B2010',
172
+ '05': 'B1010',
173
+ '06': 'B1010',
174
+ '07': 'B3010',
175
+ '08': 'B2020',
176
+ '09': 'C3010',
177
+ '10': 'C1030',
178
+ '11': 'E1090',
179
+ '12': 'E2010',
180
+ '21': 'D4010',
181
+ '22': 'D2010',
182
+ '23': 'D3040',
183
+ '26': 'D5020',
184
+ '27': 'D5030',
185
+ '28': 'D5030',
186
+ '32': 'G2040',
187
+ }
188
+
189
+ function normalizeUnit(raw: string): { unit: MitBomUnit; unitLabel?: string } {
190
+ const lower = raw.trim().toLowerCase()
191
+ if (lower === 'ea' || lower === 'pc' || lower === 'pcs' || lower === 'unit') return { unit: 'ea' }
192
+ if (lower === 'sf' || lower === 'sqft' || lower === 'sq ft') return { unit: 'sf' }
193
+ if (lower === 'sq' || lower === 'square') return { unit: 'sq' }
194
+ if (lower === 'box' || lower === 'case') return { unit: 'box' }
195
+ if (lower === 'bundle') return { unit: 'bundle' }
196
+ if (lower === 'sheet') return { unit: 'sheet' }
197
+ if (lower === 'panel') return { unit: 'panel' }
198
+ if (lower === 'lf') return { unit: 'lf' }
199
+ if (lower === 'sy') return { unit: 'sy' }
200
+ if (lower === 'cy') return { unit: 'cy' }
201
+ if (lower === 'gal') return { unit: 'gal' }
202
+ if (lower === 'bag') return { unit: 'bag' }
203
+ if (lower === 'roll') return { unit: 'roll' }
204
+ return { unit: 'ea', unitLabel: raw }
205
+ }
206
+
207
+ const SUPABASE_SLUG_RE = /supabase\.co\/storage\/v1\/object\/public\/items\/system\/([^/]+)\//i
208
+ const LOCAL_SLUG_RE = /(?:^|\/)items\/([^/]+)\/model\.glb$/i
209
+ const PROCEDURAL_SLUG_RE = /^procedural:\/\/mit-assets\/([^/]+)$/i
210
+
211
+ function round2(n: number): number {
212
+ return Math.round(n * 100) / 100
213
+ }
214
+
215
+ function csvCell(value: string | number): string {
216
+ const raw = String(value ?? '')
217
+ const safe = /^[\s]*[=+\-@\t\r\n|]/.test(raw) ? `'${raw}` : raw
218
+ if (/[",\n\r]/.test(safe)) return `"${safe.replace(/"/g, '""')}"`
219
+ return safe
220
+ }
221
+
222
+ function resolveNodeSlug(
223
+ node: Record<string, unknown>,
224
+ includeMappedPascalItems: boolean,
225
+ ): { slug: string | null; hasUnmappedSrc: boolean } {
226
+ if (node.type === 'mit-assets:item') {
227
+ const slug = typeof node.slug === 'string' && node.slug.trim() ? node.slug.trim() : null
228
+ return { slug, hasUnmappedSrc: slug === null }
229
+ }
230
+ if (!includeMappedPascalItems) return { slug: null, hasUnmappedSrc: false }
231
+ const asset = node.asset && typeof node.asset === 'object' ? (node.asset as Record<string, unknown>) : null
232
+ if (node.type !== 'item' && !asset) return { slug: null, hasUnmappedSrc: false }
233
+ const src = typeof asset?.src === 'string' ? asset.src : typeof node.src === 'string' ? node.src : null
234
+ if (!src || !src.trim()) return { slug: null, hasUnmappedSrc: false }
235
+ const cleanSrc = src.split(/[?#]/, 1)[0] ?? src
236
+ const slug =
237
+ cleanSrc.match(PROCEDURAL_SLUG_RE)?.[1] ??
238
+ cleanSrc.match(SUPABASE_SLUG_RE)?.[1] ??
239
+ cleanSrc.match(LOCAL_SLUG_RE)?.[1] ??
240
+ null
241
+ return { slug, hasUnmappedSrc: slug === null }
242
+ }
243
+
244
+ /**
245
+ * Aggregate placed `mit-assets:item` nodes (plus optional mapped Pascal `item` nodes and
246
+ * material takeoff quantities) into a CSI MasterFormat priced BOM.
247
+ */
248
+ export function buildMitAssetsBom(
249
+ nodes: Readonly<Record<string, unknown>>,
250
+ options: MitAssetsBomOptions = {},
251
+ ): MitAssetsBomResult {
252
+ const markupPct = Number.isFinite(options.markupPct) ? Math.max(0, options.markupPct ?? 0) : 0
253
+ const salesTaxPct = Number.isFinite(options.salesTaxPct) ? Math.max(0, options.salesTaxPct ?? 0) : 0
254
+ const includeMappedPascalItems = options.includeMappedPascalItems !== false
255
+
256
+ const buckets = new Map<
257
+ string,
258
+ {
259
+ rec: MitItemSkuRecord | MitMaterialSkuRecord
260
+ slug: string
261
+ quantity: number
262
+ unitPriceUsd: number
263
+ nodeIds: string[]
264
+ }
265
+ >()
266
+ const unpricedNodeIds: string[] = []
267
+ let itemCount = 0
268
+
269
+ for (const [nodeId, raw] of Object.entries(nodes)) {
270
+ if (!raw || typeof raw !== 'object') continue
271
+ const node = raw as Record<string, unknown>
272
+ if (node.visible === false) continue
273
+
274
+ const { slug, hasUnmappedSrc } = resolveNodeSlug(node, includeMappedPascalItems)
275
+ if (!slug) {
276
+ if (hasUnmappedSrc) unpricedNodeIds.push(nodeId)
277
+ continue
278
+ }
279
+
280
+ const skuRec = getMitItemSku(slug)
281
+ if (!skuRec) {
282
+ unpricedNodeIds.push(nodeId)
283
+ continue
284
+ }
285
+
286
+ const qty =
287
+ typeof node.quantity === 'number' && Number.isFinite(node.quantity) && node.quantity > 0
288
+ ? Math.max(1, Math.round(node.quantity))
289
+ : 1
290
+ const unitPrice =
291
+ typeof node.unitPriceOverrideUsd === 'number' &&
292
+ Number.isFinite(node.unitPriceOverrideUsd) &&
293
+ node.unitPriceOverrideUsd >= 0
294
+ ? round2(node.unitPriceOverrideUsd)
295
+ : skuRec.estUnitPriceUsd
296
+
297
+ const bucketKey = `${skuRec.sku}::${unitPrice}`
298
+ const existing = buckets.get(bucketKey)
299
+ if (existing) {
300
+ existing.quantity += qty
301
+ existing.nodeIds.push(nodeId)
302
+ } else {
303
+ buckets.set(bucketKey, {
304
+ rec: skuRec,
305
+ slug,
306
+ quantity: qty,
307
+ unitPriceUsd: unitPrice,
308
+ nodeIds: [nodeId],
309
+ })
310
+ }
311
+ itemCount += qty
312
+ }
313
+
314
+ // Optional material surface takeoffs
315
+ if (options.materialQuantities) {
316
+ for (const [materialId, rawQty] of Object.entries(options.materialQuantities)) {
317
+ if (!Number.isFinite(rawQty) || rawQty <= 0) continue
318
+ const matRec = getMitMaterialSku(materialId)
319
+ if (!matRec) {
320
+ unpricedNodeIds.push(`material:${materialId}`)
321
+ continue
322
+ }
323
+ const qty = Math.round(rawQty * 100) / 100
324
+ if (qty <= 0) continue
325
+ const bucketKey = `mat::${matRec.sku}::${matRec.estUnitPriceUsd}`
326
+ const existing = buckets.get(bucketKey)
327
+ if (existing) {
328
+ existing.quantity = Math.round((existing.quantity + qty) * 100) / 100
329
+ existing.nodeIds.push(`material:${materialId}`)
330
+ } else {
331
+ buckets.set(bucketKey, {
332
+ rec: matRec,
333
+ slug: materialId,
334
+ quantity: qty,
335
+ unitPriceUsd: matRec.estUnitPriceUsd,
336
+ nodeIds: [`material:${materialId}`],
337
+ })
338
+ }
339
+ itemCount += 1
340
+ }
341
+ }
342
+
343
+ const lines: MitAssetsBomLine[] = []
344
+ const subtotalByTrade: Record<string, number> = {}
345
+ const subtotalByCsi: Record<string, number> = {}
346
+ let materialSubtotalUsd = 0
347
+ let catalogLinkedSkuCount = 0
348
+
349
+ for (const b of buckets.values()) {
350
+ const extendedUsd = round2(b.quantity * b.unitPriceUsd)
351
+ materialSubtotalUsd = round2(materialSubtotalUsd + extendedUsd)
352
+ subtotalByTrade[b.rec.trade] = round2((subtotalByTrade[b.rec.trade] ?? 0) + extendedUsd)
353
+ subtotalByCsi[b.rec.csiDivision] = round2((subtotalByCsi[b.rec.csiDivision] ?? 0) + extendedUsd)
354
+ if (b.rec.pricingSource === 'pascal-plugin-catalog') catalogLinkedSkuCount += 1
355
+
356
+ lines.push({
357
+ sku: b.rec.sku,
358
+ slug: b.slug,
359
+ catalogSku: b.rec.catalogSku,
360
+ catalogRecipeId: b.rec.catalogRecipeId,
361
+ manufacturer: b.rec.manufacturer,
362
+ series: b.rec.series,
363
+ name: b.rec.productName,
364
+ trade: b.rec.trade,
365
+ csiDivision: b.rec.csiDivision,
366
+ retailCategory: b.rec.retailCategory,
367
+ retailChannel: b.rec.retailChannel,
368
+ unitOfMeasure: b.rec.unitOfMeasure,
369
+ quantity: b.quantity,
370
+ unitPriceUsd: b.unitPriceUsd,
371
+ extendedUsd,
372
+ pricingSource: b.rec.pricingSource,
373
+ nodeIds: b.nodeIds,
374
+ })
375
+ }
376
+
377
+ lines.sort((a, b) => a.csiDivision.localeCompare(b.csiDivision) || a.sku.localeCompare(b.sku))
378
+
379
+ const markupUsd = round2(materialSubtotalUsd * (markupPct / 100))
380
+ const preTax = round2(materialSubtotalUsd + markupUsd)
381
+ const salesTaxUsd = round2(preTax * (salesTaxPct / 100))
382
+ const grandTotalUsd = round2(preTax + salesTaxUsd)
383
+
384
+ return {
385
+ itemCount,
386
+ uniqueSkuCount: lines.length,
387
+ catalogLinkedSkuCount,
388
+ lines,
389
+ subtotalByTrade,
390
+ subtotalByCsi,
391
+ materialSubtotalUsd,
392
+ markupPct,
393
+ markupUsd,
394
+ salesTaxPct,
395
+ salesTaxUsd,
396
+ grandTotalUsd,
397
+ unpricedNodeIds,
398
+ }
399
+ }
400
+
401
+ export function toMitAssetsPascalBom(bom: MitAssetsBomResult): MitPascalBomFragment {
402
+ return {
403
+ schemaVersion: 'pascal-bom/1.1',
404
+ plugin: 'custom',
405
+ pluginVersion: '0.1.0',
406
+ laborIncluded: false,
407
+ lines: bom.lines.map((line) => {
408
+ const csiCompact = line.csiDivision.replace(/\s+/g, '')
409
+ const csiDiv2 = csiCompact.slice(0, 2) || '12'
410
+ const skuUpper = line.sku.trim().toUpperCase()
411
+ const { unit, unitLabel } = normalizeUnit(line.unitOfMeasure)
412
+ return {
413
+ lineId: `custom:finish-sku:${skuUpper}:${csiCompact}`,
414
+ classification: {
415
+ csiMasterFormat: line.csiDivision,
416
+ csiDivision: csiDiv2,
417
+ csiDivisionTitle: CSI_TITLES[csiDiv2] ?? 'Furnishings',
418
+ uniFormat: CSI_UNIFORMAT[csiDiv2] ?? 'E2010',
419
+ trade: line.trade,
420
+ category: line.retailCategory || line.trade,
421
+ retailCategory: line.retailCategory,
422
+ },
423
+ identity: {
424
+ sku: line.sku,
425
+ name: line.name,
426
+ ...(line.manufacturer ? { manufacturer: line.manufacturer } : {}),
427
+ ...(line.series ? { series: line.series } : {}),
428
+ cadSlug: line.slug,
429
+ },
430
+ cost: {
431
+ quantity: line.quantity,
432
+ wastePct: 0,
433
+ unit,
434
+ ...(unitLabel ? { unitLabel } : {}),
435
+ unitMaterialUsd: line.unitPriceUsd,
436
+ extendedMaterialUsd: line.extendedUsd,
437
+ laborHoursPerUnit: 0,
438
+ extendedLaborHours: 0,
439
+ laborRateUsd: 0,
440
+ extendedLaborUsd: 0,
441
+ unitEquipmentUsd: 0,
442
+ extendedEquipmentUsd: 0,
443
+ extendedTotalUsd: line.extendedUsd,
444
+ },
445
+ provenance: {
446
+ sourcePlugin: 'custom',
447
+ costScope: 'finish-sku',
448
+ nodeIds: [...line.nodeIds],
449
+ levels: [],
450
+ rooms: [],
451
+ },
452
+ partRef: {
453
+ canonicalPartId: `part:${csiCompact}:${skuUpper}`,
454
+ ontologyConcept: `concept:csi:${csiCompact}`,
455
+ },
456
+ }
457
+ }),
458
+ diagnostics:
459
+ bom.unpricedNodeIds.length > 0
460
+ ? [
461
+ {
462
+ severity: 'warning',
463
+ code: 'UNKNOWN_SKU_NODE',
464
+ plugin: 'custom',
465
+ message: `${bom.unpricedNodeIds.length} node(s) could not be matched to a real-world SKU.`,
466
+ nodeIds: bom.unpricedNodeIds,
467
+ },
468
+ ]
469
+ : [],
470
+ }
471
+ }
472
+
473
+ export function buildMitAssetsPascalBom(
474
+ nodes: Readonly<Record<string, unknown>>,
475
+ options?: MitAssetsBomOptions,
476
+ ): MitPascalBomFragment {
477
+ return toMitAssetsPascalBom(buildMitAssetsBom(nodes, options))
478
+ }
479
+
480
+ export function formatMitAssetsBomCsv(bom: MitAssetsBomResult): string {
481
+ const header = [
482
+ 'CSI Division',
483
+ 'Trade',
484
+ 'SKU',
485
+ 'Catalog SKU',
486
+ 'Manufacturer',
487
+ 'Product Name',
488
+ 'Pricing Source',
489
+ 'Unit',
490
+ 'Qty',
491
+ 'Unit Price (USD)',
492
+ 'Extended (USD)',
493
+ ]
494
+ const rows = bom.lines.map((l) =>
495
+ [
496
+ l.csiDivision,
497
+ l.trade,
498
+ l.sku,
499
+ l.catalogSku ?? '',
500
+ l.manufacturer,
501
+ l.name,
502
+ l.pricingSource,
503
+ l.unitOfMeasure,
504
+ l.quantity,
505
+ l.unitPriceUsd.toFixed(2),
506
+ l.extendedUsd.toFixed(2),
507
+ ]
508
+ .map(csvCell)
509
+ .join(','),
510
+ )
511
+ return [header.map(csvCell).join(','), ...rows].join('\n')
512
+ }