@medicine-wheel/app 0.4.4 → 0.4.6

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.
@@ -32,6 +32,7 @@ import {
32
32
  persistGraphLayoutStore,
33
33
  saveNamedGraphLayout,
34
34
  selectGraphLayout,
35
+ upsertActiveGraphLayout,
35
36
  upsertCurrentGraphLayout,
36
37
  type GraphLayoutStore,
37
38
  } from "@/lib/graph-layout-storage";
@@ -187,19 +188,23 @@ export default function GraphPage() {
187
188
 
188
189
  const handleNodePositionsChange = useCallback(
189
190
  (positions: MWGraphNodePositions) => {
190
- saveLayoutStore(upsertCurrentGraphLayout(layoutStoreRef.current, positions));
191
+ saveLayoutStore(upsertActiveGraphLayout(layoutStoreRef.current, positions));
191
192
  },
192
193
  [saveLayoutStore],
193
194
  );
194
195
 
195
196
  const saveNamedLayout = useCallback(() => {
196
- const name = layoutName.trim();
197
+ const active = getActiveGraphLayout(layoutStoreRef.current);
198
+ const name =
199
+ layoutName.trim() ||
200
+ (active.id !== CURRENT_GRAPH_LAYOUT_ID ? active.name : "");
201
+
197
202
  if (!name) {
198
203
  toast.error("Name the disposition first");
199
204
  return;
200
205
  }
201
206
 
202
- const positions = getActiveGraphLayout(layoutStoreRef.current).positions;
207
+ const positions = active.positions;
203
208
  if (Object.keys(positions).length === 0) {
204
209
  toast.error("Move a node before saving");
205
210
  return;
@@ -329,7 +334,11 @@ export default function GraphPage() {
329
334
  onKeyDown={(event) => {
330
335
  if (event.key === "Enter") saveNamedLayout();
331
336
  }}
332
- placeholder="Name disposition"
337
+ placeholder={
338
+ activeLayout.id === CURRENT_GRAPH_LAYOUT_ID
339
+ ? "Name disposition"
340
+ : activeLayout.name
341
+ }
333
342
  className="min-w-0 flex-1 rounded-md border border-white/10 bg-white/5 px-3 py-2 text-sm text-white placeholder:text-gray-500"
334
343
  />
335
344
  <button
@@ -3,6 +3,7 @@
3
3
  import { useEffect, useState } from "react";
4
4
  import type { FormEvent } from "react";
5
5
  import { type MedicineWheelCycle, DIRECTION_COLORS, type DirectionName } from "@/lib/types";
6
+ import { extractCycles } from "@/lib/cycle-response";
6
7
  import { toast } from "sonner";
7
8
 
8
9
  export default function CyclesPage() {
@@ -11,7 +12,10 @@ export default function CyclesPage() {
11
12
  const [expandedId, setExpandedId] = useState<string | null>(null);
12
13
 
13
14
  useEffect(() => {
14
- fetch("/api/narrative/cycles").then((r) => r.json()).then((d) => setCycles(Array.isArray(d) ? d : [])).catch(() => setCycles([]));
15
+ fetch("/api/narrative/cycles")
16
+ .then((r) => r.json())
17
+ .then((d) => setCycles(extractCycles(d)))
18
+ .catch(() => setCycles([]));
15
19
  }, []);
16
20
 
17
21
  async function createCycle(e: FormEvent<HTMLFormElement>) {
@@ -23,7 +27,7 @@ export default function CyclesPage() {
23
27
  toast.success("Cycle created");
24
28
  setShowForm(false);
25
29
  const data = await fetch("/api/narrative/cycles").then((r) => r.json());
26
- setCycles(Array.isArray(data) ? data : []);
30
+ setCycles(extractCycles(data));
27
31
  } else { toast.error("Failed"); }
28
32
  }
29
33
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { useEffect, useState } from "react";
4
4
  import { type NarrativeBeat, type MedicineWheelCycle, DIRECTION_COLORS, type DirectionName } from "@/lib/types";
5
+ import { extractCycles } from "@/lib/cycle-response";
5
6
 
6
7
  export default function NarrativePage() {
7
8
  const [beats, setBeats] = useState<NarrativeBeat[]>([]);
@@ -10,7 +11,7 @@ export default function NarrativePage() {
10
11
 
11
12
  useEffect(() => {
12
13
  Promise.all([fetch("/api/narrative/beats").then((r) => r.json()), fetch("/api/narrative/cycles").then((r) => r.json())])
13
- .then(([b, c]) => { setBeats(Array.isArray(b) ? b : []); setCycles(Array.isArray(c) ? c : []); })
14
+ .then(([b, c]) => { setBeats(Array.isArray(b) ? b : []); setCycles(extractCycles(c)); })
14
15
  .catch(() => {});
15
16
  }, []);
16
17
 
@@ -0,0 +1,66 @@
1
+ import type { DirectionName, MedicineWheelCycle } from "./types";
2
+
3
+ interface CycleListResponse {
4
+ cycles?: unknown;
5
+ }
6
+
7
+ export type ApiMedicineWheelCycle = MedicineWheelCycle & {
8
+ archived?: boolean;
9
+ };
10
+
11
+ const DIRECTION_NAMES = new Set<DirectionName>(["east", "south", "west", "north"]);
12
+
13
+ function asNonNegativeInteger(value: unknown): number {
14
+ return typeof value === "number" && Number.isFinite(value) && value >= 0
15
+ ? Math.trunc(value)
16
+ : 0;
17
+ }
18
+
19
+ function asUnitInterval(value: unknown): number {
20
+ return typeof value === "number" && Number.isFinite(value)
21
+ ? Math.max(0, Math.min(1, value))
22
+ : 0;
23
+ }
24
+
25
+ export function normalizeMedicineWheelCycle(value: unknown): ApiMedicineWheelCycle | null {
26
+ if (!value || typeof value !== "object") return null;
27
+
28
+ const cycle = value as Record<string, unknown>;
29
+ if (typeof cycle.id !== "string" || typeof cycle.research_question !== "string") {
30
+ return null;
31
+ }
32
+
33
+ return {
34
+ id: cycle.id,
35
+ research_question: cycle.research_question,
36
+ start_date:
37
+ typeof cycle.start_date === "string"
38
+ ? cycle.start_date
39
+ : new Date(0).toISOString(),
40
+ current_direction:
41
+ typeof cycle.current_direction === "string" &&
42
+ DIRECTION_NAMES.has(cycle.current_direction as DirectionName)
43
+ ? (cycle.current_direction as DirectionName)
44
+ : "east",
45
+ beats: Array.isArray(cycle.beats)
46
+ ? cycle.beats.filter((beatId): beatId is string => typeof beatId === "string")
47
+ : [],
48
+ ceremonies_conducted: asNonNegativeInteger(cycle.ceremonies_conducted),
49
+ relations_mapped: asNonNegativeInteger(cycle.relations_mapped),
50
+ wilson_alignment: asUnitInterval(cycle.wilson_alignment),
51
+ ocap_compliant: cycle.ocap_compliant === true,
52
+ ...(cycle.archived === true ? { archived: true } : {}),
53
+ };
54
+ }
55
+
56
+ export function extractCycles(response: unknown): ApiMedicineWheelCycle[] {
57
+ const candidate = Array.isArray(response)
58
+ ? response
59
+ : response && typeof response === "object" && Array.isArray((response as CycleListResponse).cycles)
60
+ ? ((response as CycleListResponse).cycles as unknown[])
61
+ : [];
62
+
63
+ return candidate
64
+ .map(normalizeMedicineWheelCycle)
65
+ .filter((cycle): cycle is ApiMedicineWheelCycle => cycle !== null);
66
+ }
@@ -219,6 +219,42 @@ export function upsertCurrentGraphLayout(
219
219
  };
220
220
  }
221
221
 
222
+ export function upsertActiveGraphLayout(
223
+ store: GraphLayoutStore,
224
+ positions: MWGraphNodePositions,
225
+ updatedAt: string = nowIso(),
226
+ ): GraphLayoutStore {
227
+ const activeLayout = getActiveGraphLayout(store);
228
+ const mergedPositions = sanitizeGraphPositions({
229
+ ...activeLayout.positions,
230
+ ...positions,
231
+ });
232
+ const updatedLayout: GraphLayoutDisposition = {
233
+ ...activeLayout,
234
+ positions: mergedPositions,
235
+ updatedAt,
236
+ nodeCount: Object.keys(mergedPositions).length,
237
+ };
238
+
239
+ if (updatedLayout.id === CURRENT_GRAPH_LAYOUT_ID) {
240
+ const savedLayouts = store.layouts.filter((layout) => layout.id !== CURRENT_GRAPH_LAYOUT_ID);
241
+
242
+ return {
243
+ version: GRAPH_LAYOUT_STORE_VERSION,
244
+ activeLayoutId: CURRENT_GRAPH_LAYOUT_ID,
245
+ layouts: [updatedLayout, ...savedLayouts],
246
+ };
247
+ }
248
+
249
+ return {
250
+ version: GRAPH_LAYOUT_STORE_VERSION,
251
+ activeLayoutId: updatedLayout.id,
252
+ layouts: store.layouts.map((layout) =>
253
+ layout.id === updatedLayout.id ? updatedLayout : layout,
254
+ ),
255
+ };
256
+ }
257
+
222
258
  export function saveNamedGraphLayout(
223
259
  store: GraphLayoutStore,
224
260
  name: string,
package/lib/store.ts CHANGED
@@ -22,6 +22,7 @@ import type {
22
22
  MedicineWheelCycle,
23
23
  } from '@/lib/types';
24
24
 
25
+ import { extractCycles, normalizeMedicineWheelCycle } from './cycle-response';
25
26
  import { getJsonlStore } from './jsonl-store';
26
27
 
27
28
  // JSONL store for sync operations (used by seeding and legacy code paths)
@@ -151,7 +152,7 @@ export function createBeat(data: Omit<NarrativeBeat, 'id' | 'timestamp'> & { id?
151
152
 
152
153
  export function getAllCycles(): MedicineWheelCycle[] {
153
154
  const { active, archived } = store.getAllCycles();
154
- return [...active, ...archived] as unknown as MedicineWheelCycle[];
155
+ return extractCycles([...active, ...archived]);
155
156
  }
156
157
 
157
158
  export function createCycle(data: { research_question: string; current_direction?: string }): MedicineWheelCycle {
@@ -168,7 +169,7 @@ export function createCycle(data: { research_question: string; current_direction
168
169
  ocap_compliant: false,
169
170
  };
170
171
  store.createCycle(cycle as any);
171
- return cycle;
172
+ return normalizeMedicineWheelCycle(cycle) ?? cycle;
172
173
  }
173
174
 
174
175
  // ── Seed Data ──
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medicine-wheel/app",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Medicine Wheel — Interactive visual layer for Indigenous relational research with Four Directions, ceremonies, and narrative arcs",
5
5
  "bin": {
6
6
  "mw": "dist/cli/mw.js",
@@ -74,24 +74,24 @@
74
74
  "release:major": "npm run version:major && npm run publish:all && npm run release:commit"
75
75
  },
76
76
  "dependencies": {
77
- "@medicine-wheel/ceremony-protocol": "^0.4.4",
78
- "@medicine-wheel/community-review": "^0.4.4",
79
- "@medicine-wheel/consent-lifecycle": "^0.4.4",
80
- "@medicine-wheel/data-store": "^0.4.4",
81
- "@medicine-wheel/data-store-postgres": "^0.4.4",
82
- "@medicine-wheel/fire-keeper": "^0.4.4",
83
- "@medicine-wheel/graph-viz": "^0.4.4",
84
- "@medicine-wheel/importance-unit": "^0.4.4",
85
- "@medicine-wheel/mcp": "^4.4.2",
86
- "@medicine-wheel/narrative-engine": "^0.4.4",
87
- "@medicine-wheel/ontology-core": "^0.4.4",
88
- "@medicine-wheel/prompt-decomposition": "^0.4.4",
89
- "@medicine-wheel/relational-index": "^0.4.4",
90
- "@medicine-wheel/relational-query": "^0.4.4",
91
- "@medicine-wheel/session-reader": "^0.4.4",
92
- "@medicine-wheel/storage-provider": "^0.4.4",
93
- "@medicine-wheel/transformation-tracker": "^0.4.4",
94
- "@medicine-wheel/ui-components": "^0.4.4",
77
+ "@medicine-wheel/ceremony-protocol": "^0.4.6",
78
+ "@medicine-wheel/community-review": "^0.4.6",
79
+ "@medicine-wheel/consent-lifecycle": "^0.4.6",
80
+ "@medicine-wheel/data-store": "^0.4.6",
81
+ "@medicine-wheel/data-store-postgres": "^0.4.6",
82
+ "@medicine-wheel/fire-keeper": "^0.4.6",
83
+ "@medicine-wheel/graph-viz": "^0.4.6",
84
+ "@medicine-wheel/importance-unit": "^0.4.6",
85
+ "@medicine-wheel/mcp": "^4.4.5",
86
+ "@medicine-wheel/narrative-engine": "^0.4.6",
87
+ "@medicine-wheel/ontology-core": "^0.4.6",
88
+ "@medicine-wheel/prompt-decomposition": "^0.4.6",
89
+ "@medicine-wheel/relational-index": "^0.4.6",
90
+ "@medicine-wheel/relational-query": "^0.4.6",
91
+ "@medicine-wheel/session-reader": "^0.4.6",
92
+ "@medicine-wheel/storage-provider": "^0.4.6",
93
+ "@medicine-wheel/transformation-tracker": "^0.4.6",
94
+ "@medicine-wheel/ui-components": "^0.4.6",
95
95
  "@neondatabase/serverless": "^0.10.0",
96
96
  "clsx": "^2.1.1",
97
97
  "lucide-react": "^0.475.0",