@burdenoff/microfe-movethewheels 2026.1107.7 → 2026.1108.2

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 (28) hide show
  1. package/dist/components/ForecastModelsPanel.js +132 -0
  2. package/dist/components/InventoryCoverPanel.js +401 -0
  3. package/dist/components/UpcomingDemandPanel.js +70 -65
  4. package/dist/generated/wspace-operations.d.ts +25 -0
  5. package/dist/generated/wspace-types.d.ts +3467 -134
  6. package/dist/hooks/useDemandForecast.js +1 -1
  7. package/dist/hooks/useForecastModelChoices.js +57 -0
  8. package/dist/hooks/useInventoryCoverPlan.js +70 -0
  9. package/dist/movethewheels/components/ForecastModelsPanel.d.ts +4 -0
  10. package/dist/movethewheels/components/InventoryCoverPanel.d.ts +24 -0
  11. package/dist/movethewheels/hooks/useDemandForecast.d.ts +9 -0
  12. package/dist/movethewheels/hooks/useForecastModelChoices.d.ts +34 -0
  13. package/dist/movethewheels/hooks/useInventoryCoverPlan.d.ts +80 -0
  14. package/dist/node_modules/lucide-react/dist/esm/icons/sigma.js +8 -0
  15. package/dist/pages/AnalyticsPage.js +83 -81
  16. package/dist/pages/InventoryPage.js +219 -214
  17. package/package.json +1 -1
  18. package/src/generated/wspace-operations.ts +13 -4
  19. package/src/generated/wspace-types.ts +3812 -134
  20. package/src/movethewheels/components/ForecastModelsPanel.tsx +188 -0
  21. package/src/movethewheels/components/InventoryCoverPanel.tsx +449 -0
  22. package/src/movethewheels/components/UpcomingDemandPanel.tsx +9 -2
  23. package/src/movethewheels/hooks/useDemandForecast.ts +13 -0
  24. package/src/movethewheels/hooks/useForecastModelChoices.ts +138 -0
  25. package/src/movethewheels/hooks/useInventoryCoverPlan.ts +250 -0
  26. package/src/movethewheels/pages/AnalyticsPage.tsx +7 -2
  27. package/src/movethewheels/pages/InventoryPage.tsx +8 -0
  28. package/src/operations/wspace/movethewheels/queries/forecast.graphql +22 -1
@@ -9,6 +9,15 @@ import { executeGraphQL } from '../utils/graphqlClient';
9
9
  * admin console exposes `recalculateDemandForecasts` separately.
10
10
  */
11
11
 
12
+ /**
13
+ * The forecast model behind a row: the moving-average heuristic, or (once a
14
+ * lane or customer has 26 closed weeks and the model wins the back-test)
15
+ * Holt linear or Holt-Winters exponential smoothing. HEURISTIC_GROWTH_RATE is
16
+ * reserved and never produced.
17
+ */
18
+ export type DemandForecastModel =
19
+ 'HEURISTIC_MOVING_AVG' | 'HEURISTIC_GROWTH_RATE' | 'HOLT_LINEAR' | 'HOLT_WINTERS';
20
+
12
21
  export interface ForecastPoint {
13
22
  scopeType: 'LANE' | 'CUSTOMER';
14
23
  scopeKey: string;
@@ -21,6 +30,8 @@ export interface ForecastPoint {
21
30
  actualVolume: number | null;
22
31
  actualRevenue: number | null;
23
32
  confidence: number;
33
+ /** The model that produced the row (BOFF-10925). */
34
+ model: DemandForecastModel;
24
35
  }
25
36
 
26
37
  export interface ForecastVariance {
@@ -60,6 +71,7 @@ const FORECAST_QUERY = `
60
71
  actualVolume
61
72
  actualRevenue
62
73
  confidence
74
+ model
63
75
  }
64
76
  demandForecastByCustomer(weeks: $weeks) {
65
77
  scopeType
@@ -72,6 +84,7 @@ const FORECAST_QUERY = `
72
84
  actualVolume
73
85
  actualRevenue
74
86
  confidence
87
+ model
75
88
  }
76
89
  laneVariance: demandForecastVariance(scopeType: LANE, limit: $varianceLimit) {
77
90
  scopeType
@@ -0,0 +1,138 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+
3
+ import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
4
+ import { executeGraphQL } from '../utils/graphqlClient';
5
+
6
+ import type { DemandForecastModel } from './useDemandForecast';
7
+
8
+ /**
9
+ * Forecast model choices (BOFF-10925): which model forecasts each lane and
10
+ * customer, with every candidate's back-test error (MAPE), so the choice can
11
+ * be checked. Loaded separately from the forecast itself so a failure here
12
+ * never hides the upcoming demand.
13
+ */
14
+
15
+ export interface ForecastModelScore {
16
+ model: DemandForecastModel;
17
+ seasonLengthWeeks: number | null;
18
+ /** Mean absolute percentage error on weekly volume; 0.25 = 25%. */
19
+ mape: number | null;
20
+ holdoutWeeks: number;
21
+ selected: boolean;
22
+ }
23
+
24
+ export interface ForecastModelChoice {
25
+ scopeType: 'LANE' | 'CUSTOMER';
26
+ scopeKey: string;
27
+ scopeLabel: string;
28
+ historyWeeks: number;
29
+ selectedModel: DemandForecastModel;
30
+ reason: string;
31
+ evaluatedAt: string;
32
+ candidates: ForecastModelScore[];
33
+ }
34
+
35
+ interface UseForecastModelChoicesResult {
36
+ laneChoices: ForecastModelChoice[];
37
+ customerChoices: ForecastModelChoice[];
38
+ isLoading: boolean;
39
+ error: Error | null;
40
+ refetch: () => void;
41
+ }
42
+
43
+ const CHOICE_FIELDS = `
44
+ scopeType
45
+ scopeKey
46
+ scopeLabel
47
+ historyWeeks
48
+ selectedModel
49
+ reason
50
+ evaluatedAt
51
+ candidates {
52
+ model
53
+ seasonLengthWeeks
54
+ mape
55
+ holdoutWeeks
56
+ selected
57
+ }
58
+ `;
59
+
60
+ const MODEL_CHOICES_QUERY = `
61
+ query GetMovethewheelsForecastModelChoices($limit: Int!) {
62
+ laneChoices: demandForecastModelChoices(scopeType: LANE, limit: $limit) {
63
+ ${CHOICE_FIELDS}
64
+ }
65
+ customerChoices: demandForecastModelChoices(scopeType: CUSTOMER, limit: $limit) {
66
+ ${CHOICE_FIELDS}
67
+ }
68
+ }
69
+ `;
70
+
71
+ export function useForecastModelChoices(limit = 5): UseForecastModelChoicesResult {
72
+ const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
73
+ useMoveTheWheels();
74
+ const [laneChoices, setLaneChoices] = useState<ForecastModelChoice[]>([]);
75
+ const [customerChoices, setCustomerChoices] = useState<ForecastModelChoice[]>([]);
76
+ // Start in the loading state: the first fetch runs in an effect, and the
77
+ // panel must not flash "No forecasts yet" before it does.
78
+ const [isLoading, setIsLoading] = useState(true);
79
+ const [error, setError] = useState<Error | null>(null);
80
+ // Only the latest request may update state, so a response that arrives
81
+ // after a workspace switch (or a newer refetch) is dropped.
82
+ const latestRequest = useRef(0);
83
+
84
+ const graphQLOptions = useMemo(
85
+ () => ({
86
+ apiGatewayUrl,
87
+ authToken,
88
+ workspaceToken,
89
+ workspaceId,
90
+ tenantId,
91
+ actorId: currentUser?.id,
92
+ }),
93
+ [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
94
+ );
95
+
96
+ const load = useCallback(async () => {
97
+ const request = ++latestRequest.current;
98
+ setIsLoading(true);
99
+ setError(null);
100
+ try {
101
+ const data = await executeGraphQL<{
102
+ laneChoices: ForecastModelChoice[];
103
+ customerChoices: ForecastModelChoice[];
104
+ }>(graphQLOptions, MODEL_CHOICES_QUERY, { limit });
105
+ if (request !== latestRequest.current) {
106
+ return;
107
+ }
108
+ setLaneChoices(data.laneChoices ?? []);
109
+ setCustomerChoices(data.customerChoices ?? []);
110
+ } catch (fetchError) {
111
+ if (request !== latestRequest.current) {
112
+ return;
113
+ }
114
+ setError(
115
+ fetchError instanceof Error ? fetchError : new Error('Failed to load forecast models')
116
+ );
117
+ } finally {
118
+ if (request === latestRequest.current) {
119
+ setIsLoading(false);
120
+ }
121
+ }
122
+ }, [graphQLOptions, limit]);
123
+
124
+ useEffect(() => {
125
+ void load();
126
+ return () => {
127
+ // Invalidate the in-flight request when the options change or the
128
+ // panel unmounts.
129
+ latestRequest.current += 1;
130
+ };
131
+ }, [load]);
132
+
133
+ const refetch = useCallback(() => {
134
+ void load();
135
+ }, [load]);
136
+
137
+ return { laneChoices, customerChoices, isLoading, error, refetch };
138
+ }
@@ -0,0 +1,250 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+
3
+ import { useMoveTheWheels } from '../providers/MoveTheWheelsProvider';
4
+ import { executeGraphQL } from '../utils/graphqlClient';
5
+
6
+ /**
7
+ * Inventory planning (BOFF-10926). Runs the read-only `inventoryCoverPlan`
8
+ * query: weeks of stock cover per warehouse and SKU against forecast
9
+ * outbound demand, with the projected stock-out week and a suggested
10
+ * reorder quantity.
11
+ */
12
+
13
+ export type CoverStatus =
14
+ 'OUT_OF_STOCK' | 'AT_RISK' | 'REORDER' | 'HEALTHY' | 'NOT_ENOUGH_HISTORY' | 'NO_DEMAND';
15
+
16
+ export type DemandStatus = 'FORECAST' | 'NOT_ENOUGH_HISTORY' | 'NO_DEMAND';
17
+
18
+ /** Statuses that ask the planner to act, most urgent first. */
19
+ export const ACTION_STATUSES: CoverStatus[] = ['OUT_OF_STOCK', 'AT_RISK', 'REORDER'];
20
+
21
+ export interface CoverPlanRequest {
22
+ warehouseId: string | null;
23
+ leadTimeWeeks: number;
24
+ targetCoverWeeks: number;
25
+ demandChangePct: number;
26
+ /** Only rows that need action; the summary always counts every row. */
27
+ actionOnly: boolean;
28
+ }
29
+
30
+ export interface CoverPlanRow {
31
+ warehouseId: string;
32
+ warehouseName: string;
33
+ warehouseCode: string;
34
+ cargoItemId: string;
35
+ sku: string;
36
+ name: string;
37
+ onHand: number;
38
+ damaged: number;
39
+ usableStock: number;
40
+ reorderPoint: number | null;
41
+ safetyStock: number | null;
42
+ demandStatus: DemandStatus;
43
+ weeksOfHistory: number;
44
+ weeklyUnits: number[];
45
+ currentWeekUnits: number;
46
+ baselineWeeklyDemand: number | null;
47
+ forecastWeeklyDemand: number | null;
48
+ weeksOfCover: number | null;
49
+ projectedStockOutWeek: string | null;
50
+ stockOutBeforeLeadTime: boolean;
51
+ suggestedReorderQuantity: number | null;
52
+ status: CoverStatus;
53
+ }
54
+
55
+ export interface CoverPlanSummary {
56
+ totalItems: number;
57
+ outOfStock: number;
58
+ atRisk: number;
59
+ reorder: number;
60
+ healthy: number;
61
+ notEnoughHistory: number;
62
+ noDemand: number;
63
+ totalSuggestedReorderQuantity: number;
64
+ }
65
+
66
+ export interface CoverPlan {
67
+ generatedAt: string;
68
+ historyStart: string;
69
+ historyEnd: string;
70
+ historyWeeks: number;
71
+ warehouseId: string | null;
72
+ leadTimeWeeks: number;
73
+ targetCoverWeeks: number;
74
+ demandChangePct: number;
75
+ summary: CoverPlanSummary;
76
+ unattributedUnits: number;
77
+ unattributedJobs: number;
78
+ truncated: boolean;
79
+ matchingItems: number;
80
+ rows: CoverPlanRow[];
81
+ }
82
+
83
+ const COVER_PLAN_QUERY = `
84
+ query GetMovethewheelsInventoryCoverPlan($input: InventoryCoverPlanInput) {
85
+ inventoryCoverPlan(input: $input) {
86
+ generatedAt
87
+ historyStart
88
+ historyEnd
89
+ historyWeeks
90
+ warehouseId
91
+ leadTimeWeeks
92
+ targetCoverWeeks
93
+ demandChangePct
94
+ summary {
95
+ totalItems
96
+ outOfStock
97
+ atRisk
98
+ reorder
99
+ healthy
100
+ notEnoughHistory
101
+ noDemand
102
+ totalSuggestedReorderQuantity
103
+ }
104
+ unattributedUnits
105
+ unattributedJobs
106
+ truncated
107
+ matchingItems
108
+ rows {
109
+ warehouseId
110
+ warehouseName
111
+ warehouseCode
112
+ cargoItemId
113
+ sku
114
+ name
115
+ onHand
116
+ damaged
117
+ usableStock
118
+ reorderPoint
119
+ safetyStock
120
+ demandStatus
121
+ weeksOfHistory
122
+ weeklyUnits
123
+ currentWeekUnits
124
+ baselineWeeklyDemand
125
+ forecastWeeklyDemand
126
+ weeksOfCover
127
+ projectedStockOutWeek
128
+ stockOutBeforeLeadTime
129
+ suggestedReorderQuantity
130
+ status
131
+ }
132
+ }
133
+ }
134
+ `;
135
+
136
+ /** Rows the panel asks for; the summary still counts every position. */
137
+ export const COVER_PLAN_ROW_LIMIT = 200;
138
+
139
+ export const DEFAULT_COVER_REQUEST: CoverPlanRequest = {
140
+ warehouseId: null,
141
+ leadTimeWeeks: 2,
142
+ targetCoverWeeks: 6,
143
+ demandChangePct: 0,
144
+ actionOnly: false,
145
+ };
146
+
147
+ interface UseInventoryCoverPlanResult {
148
+ plan: CoverPlan | null;
149
+ isLoading: boolean;
150
+ error: Error | null;
151
+ /** Run a plan; the latest request wins if several overlap. */
152
+ run: (request: CoverPlanRequest) => void;
153
+ }
154
+
155
+ export function useInventoryCoverPlan(
156
+ initial: CoverPlanRequest = DEFAULT_COVER_REQUEST
157
+ ): UseInventoryCoverPlanResult {
158
+ const { apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser } =
159
+ useMoveTheWheels();
160
+ const [plan, setPlan] = useState<CoverPlan | null>(null);
161
+ // The plan is fetched on mount, so start in the loading state to show the
162
+ // skeleton on the first render instead of an empty panel.
163
+ const [isLoading, setIsLoading] = useState(true);
164
+ const [error, setError] = useState<Error | null>(null);
165
+ const latest = useRef(0);
166
+ // The in-flight request, aborted when a newer one starts or on unmount.
167
+ const inFlight = useRef<AbortController | null>(null);
168
+ // Re-run the user's last request (not the initial one) when the auth
169
+ // context changes, so a token refresh never resets their settings.
170
+ const lastRequest = useRef(initial);
171
+
172
+ const graphQLOptions = useMemo(
173
+ () => ({
174
+ apiGatewayUrl,
175
+ authToken,
176
+ workspaceToken,
177
+ workspaceId,
178
+ tenantId,
179
+ actorId: currentUser?.id,
180
+ }),
181
+ [apiGatewayUrl, authToken, workspaceToken, workspaceId, tenantId, currentUser?.id]
182
+ );
183
+
184
+ const load = useCallback(
185
+ async (request: CoverPlanRequest) => {
186
+ lastRequest.current = request;
187
+ const id = latest.current + 1;
188
+ latest.current = id;
189
+ inFlight.current?.abort();
190
+ const controller = new AbortController();
191
+ inFlight.current = controller;
192
+ setIsLoading(true);
193
+ setError(null);
194
+ try {
195
+ const data = await executeGraphQL<{ inventoryCoverPlan: CoverPlan }>(
196
+ { ...graphQLOptions, signal: controller.signal },
197
+ COVER_PLAN_QUERY,
198
+ {
199
+ input: {
200
+ warehouseId: request.warehouseId,
201
+ leadTimeWeeks: request.leadTimeWeeks,
202
+ targetCoverWeeks: request.targetCoverWeeks,
203
+ demandChangePct: request.demandChangePct,
204
+ statuses: request.actionOnly ? ACTION_STATUSES : null,
205
+ limit: COVER_PLAN_ROW_LIMIT,
206
+ },
207
+ }
208
+ );
209
+ if (latest.current === id) {
210
+ setPlan(data.inventoryCoverPlan);
211
+ }
212
+ } catch (fetchError) {
213
+ if (latest.current === id && !controller.signal.aborted) {
214
+ setError(
215
+ fetchError instanceof Error
216
+ ? fetchError
217
+ : new Error('Failed to load the stock cover plan')
218
+ );
219
+ }
220
+ } finally {
221
+ if (latest.current === id) {
222
+ setIsLoading(false);
223
+ }
224
+ }
225
+ },
226
+ [graphQLOptions]
227
+ );
228
+
229
+ useEffect(() => {
230
+ void load(lastRequest.current);
231
+ }, [load]);
232
+
233
+ useEffect(
234
+ () => () => {
235
+ // Invalidate and cancel whatever is in flight when the panel unmounts.
236
+ latest.current += 1;
237
+ inFlight.current?.abort();
238
+ },
239
+ []
240
+ );
241
+
242
+ const run = useCallback(
243
+ (request: CoverPlanRequest) => {
244
+ void load(request);
245
+ },
246
+ [load]
247
+ );
248
+
249
+ return { plan, isLoading, error, run };
250
+ }
@@ -14,6 +14,7 @@ import { Card, CardContent, CardHeader, CardTitle, Progress, Button } from '../c
14
14
  import { TrendChart, VolumeBar, StatusDonut, type DonutSlice } from '../components/charts';
15
15
  import { UpcomingDemandPanel } from '../components/UpcomingDemandPanel';
16
16
  import { ScenarioPlanningPanel } from '../components/ScenarioPlanningPanel';
17
+ import { ForecastModelsPanel } from '../components/ForecastModelsPanel';
17
18
  import { CarbonFootprintPanel } from '../components/CarbonFootprintPanel';
18
19
  import { EmphasisPanel, PagePurpose } from '@burdenoff/fe-libs/ui';
19
20
  import { useAnalytics, useOrderAnalytics, useFleetAnalytics } from '../hooks/useAnalytics';
@@ -142,8 +143,8 @@ export default function AnalyticsPage() {
142
143
  </CardContent>
143
144
  </Card>
144
145
 
145
- {/* Upcoming demand (BOFF-4393) — heuristic forecast, surfaces only
146
- when the workspace has enough history (>=4 weeks). */}
146
+ {/* Upcoming demand (BOFF-4393) — surfaces only when the workspace has
147
+ enough history (>=4 weeks); see ForecastModelsPanel for the model. */}
147
148
  <UpcomingDemandPanel
148
149
  laneForecast={laneForecast}
149
150
  customerForecast={customerForecast}
@@ -154,6 +155,10 @@ export default function AnalyticsPage() {
154
155
  onRetry={refetchForecast}
155
156
  />
156
157
 
158
+ {/* Forecast models (BOFF-10925) — which model forecasts each lane and
159
+ customer, with the back-test errors behind the choice. */}
160
+ <ForecastModelsPanel />
161
+
157
162
  {/* Scenario planning and capacity vs demand (BOFF-10761) — what-if
158
163
  scenarios on the lane forecast compared against fleet capacity. */}
159
164
  <ScenarioPlanningPanel />
@@ -24,6 +24,7 @@ import { MetricCard, MetricGrid, MetricCardSkeleton } from '../components/Metric
24
24
  import { DataTable, type Column } from '../components/DataTable';
25
25
  import { StatusBadge } from '../components/StatusBadge';
26
26
  import { Notice, useNotice } from '../components/Notice';
27
+ import { InventoryCoverPanel } from '../components/InventoryCoverPanel';
27
28
  import {
28
29
  AdjustStockDialog,
29
30
  ReceiveStockDialog,
@@ -135,6 +136,10 @@ export default function InventoryPage() {
135
136
  limit: pageSize,
136
137
  offset: pageIndex * pageSize,
137
138
  });
139
+ const coverWarehouses = useMemo(
140
+ () => warehouses.map((warehouse) => ({ id: warehouse.id, name: warehouse.name })),
141
+ [warehouses]
142
+ );
138
143
  const { stats, refetch: refetchStats } = useInventoryStats();
139
144
  const {
140
145
  transactions,
@@ -454,6 +459,9 @@ export default function InventoryPage() {
454
459
  </EmphasisPanel>
455
460
  )}
456
461
 
462
+ {/* Inventory planning (BOFF-10926): weeks of cover against forecast outbound demand. */}
463
+ <InventoryCoverPanel warehouses={coverWarehouses} />
464
+
457
465
  {/* Stock position + ledger. The table is the per-warehouse stock line;
458
466
  the side panel is the real movement history from Query.inventoryTransactions. */}
459
467
  <div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
@@ -1,4 +1,4 @@
1
- # Demand forecasting (BOFF-4393) — query operations against the
1
+ # Demand forecasting (BOFF-4393, BOFF-10925) — query operations against the
2
2
  # wspace-movethewheels-svc DemandForecast surface. Read-side only on the
3
3
  # UI; recalculation is triggered from the admin console via a separate
4
4
  # mutation that is not wired into the MFE yet.
@@ -15,6 +15,7 @@ query GetMovethewheelsDemandForecastByLane($weeks: Int!) {
15
15
  actualVolume
16
16
  actualRevenue
17
17
  confidence
18
+ model
18
19
  }
19
20
  }
20
21
 
@@ -30,6 +31,7 @@ query GetMovethewheelsDemandForecastByCustomer($weeks: Int!) {
30
31
  actualVolume
31
32
  actualRevenue
32
33
  confidence
34
+ model
33
35
  }
34
36
  }
35
37
 
@@ -48,3 +50,22 @@ query GetMovethewheelsDemandForecastVariance($scopeType: DemandForecastScope!, $
48
50
  revenueVariance
49
51
  }
50
52
  }
53
+
54
+ query GetMovethewheelsDemandForecastModelChoices($scopeType: DemandForecastScope!, $limit: Int!) {
55
+ demandForecastModelChoices(scopeType: $scopeType, limit: $limit) {
56
+ scopeType
57
+ scopeKey
58
+ scopeLabel
59
+ historyWeeks
60
+ selectedModel
61
+ reason
62
+ evaluatedAt
63
+ candidates {
64
+ model
65
+ seasonLengthWeeks
66
+ mape
67
+ holdoutWeeks
68
+ selected
69
+ }
70
+ }
71
+ }