File size: 2,890 Bytes
729628a
 
 
 
a2bbd94
729628a
 
 
 
 
 
 
 
 
 
 
 
 
d1ac27a
73d9b6f
578518d
e8829d6
729628a
963e554
 
 
 
 
 
 
 
 
 
 
 
 
 
f6a5256
963e554
f6a5256
 
bf8faa9
 
729628a
 
a2bbd94
729628a
 
 
 
 
 
 
 
 
 
 
 
 
d1ac27a
73d9b6f
578518d
e8829d6
729628a
963e554
 
 
 
 
 
 
 
 
 
 
 
 
 
f6a5256
963e554
f6a5256
729628a
f6a5256
bf8faa9
729628a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { createContext, useContext } from 'react';
import type { StreamEvent } from '../types/labeleval';

export type PageId =
  | 'command'
  | 'overview'
  | 'datasets'
  | 'label-generation'
  | 'rare-events'
  | 'quality'
  | 'regression'
  | 'triage'
  | 'review'
  | 'training'
  | 'models'
  | 'evaluation'
  | 'audit'
  | 'pipeline'
  | 'rca'
  | 'raremine'
  | 'hillclimb'
  | 'vitis'
  | 'ssam'
  | 'safety-odd'
  | 'safety-gates'
  | 'safety-evidence'
  | 'safety-ssam'
  | 'safety-calibration'
  | 'safety-discrepancy'
  | 'safety-scenarios'
  | 'safety-search'
  | 'seqeval'
  | 'bevfusion'
  | 'scenario-composer'
  | 'pipeline-builder'
  | 'my-dashboard'
  | 'retro'
  | 'closed-loop-lab'
  | 'launch-readiness'
  | 'studio2'
  | 'legacy'
  | 'production-readiness'
  | 'rotr';

export const ALL_PAGE_IDS: PageId[] = [
  'command',
  'overview',
  'datasets',
  'label-generation',
  'rare-events',
  'quality',
  'regression',
  'triage',
  'review',
  'training',
  'models',
  'evaluation',
  'audit',
  'pipeline',
  'rca',
  'raremine',
  'hillclimb',
  'vitis',
  'ssam',
  'safety-odd',
  'safety-gates',
  'safety-evidence',
  'safety-ssam',
  'safety-calibration',
  'safety-discrepancy',
  'safety-scenarios',
  'safety-search',
  'seqeval',
  'bevfusion',
  'scenario-composer',
  'pipeline-builder',
  'my-dashboard',
  'retro',
  'closed-loop-lab',
  'launch-readiness',
  'studio2',
  'legacy',
  'production-readiness',
  'rotr',
];

/** Maps backend evidence_link.page strings (unknown vocabulary) onto our page ids. */
export function resolvePageId(page: string): PageId {
  const normalized = page.toLowerCase().replace(/_/g, '-');
  if ((ALL_PAGE_IDS as string[]).includes(normalized)) return normalized as PageId;
  const aliases: Record<string, PageId> = {
    'rare-event': 'rare-events',
    rareevents: 'rare-events',
    'human-review': 'review',
    hitl: 'review',
    'review-tasks': 'review',
    'quality-engine': 'quality',
    'label-eval': 'evaluation',
    evaluations: 'evaluation',
    model: 'models',
    dataset: 'datasets',
    train: 'training',
    'pipeline-architecture': 'pipeline',
  };
  return aliases[normalized] ?? 'overview';
}

export interface LabelEvalContextValue {
  activeDatasetId: string | null;
  setActiveDatasetId: (id: string | null) => void;
  /** Latest event from the SSE stream (or the polling fallback). */
  stream: StreamEvent | null;
  page: PageId;
  /** Optional entity id carried by navigation (e.g. review task id). */
  entityId: string | null;
  navigate: (page: PageId, entityId?: string | null) => void;
}

export const LabelEvalContext = createContext<LabelEvalContextValue | null>(null);

export function useLabelEval(): LabelEvalContextValue {
  const ctx = useContext(LabelEvalContext);
  if (!ctx) throw new Error('useLabelEval must be used within the LabelEval provider');
  return ctx;
}