Skip to content

Commit f3febe2

Browse files
committed
delete unused fields
1 parent d9d866e commit f3febe2

File tree

17 files changed

+314
-375
lines changed

17 files changed

+314
-375
lines changed

engine/baml-compiler/src/viz.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use baml_vm::VizNodeMeta;
44
/// Representation of a viz node during compilation.
55
#[derive(Clone, Debug)]
66
pub struct VizNode {
7+
pub node_id: u32,
78
pub id: String,
89
pub parent: Option<String>,
910
pub node_type: RuntimeNodeType,
@@ -40,6 +41,7 @@ impl VizNodes {
4041
self.nodes
4142
.into_iter()
4243
.map(|node| VizNodeMeta {
44+
node_id: node.node_id,
4345
id: node.id,
4446
parent: node.parent,
4547
node_type: node.node_type,

engine/baml-compiler/src/viz_builder.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,36 @@ struct Builder {
125125
function_name: String,
126126
frames: Vec<Frame>,
127127
nodes: VizNodes,
128+
next_node_id: u32,
128129
}
129130

130131
impl Builder {
131132
fn new(function_name: &str) -> Self {
132-
let mut nodes = VizNodes::new();
133+
let mut builder = Self {
134+
function_name: function_name.to_string(),
135+
frames: Vec::new(),
136+
nodes: VizNodes::new(),
137+
next_node_id: 0,
138+
};
139+
133140
let segment = PathSegment::FunctionRoot { ordinal: 0 };
134141
let lexical_id = encode_segments(function_name, &[segment.clone()]);
135-
nodes.push(VizNode {
142+
let node_id = builder.allocate_node_id();
143+
builder.nodes.push(VizNode {
144+
node_id,
136145
id: lexical_id.clone(),
137146
parent: None,
138147
node_type: RuntimeNodeType::FunctionRoot,
139148
label: function_name.to_string(),
140149
header_level: None,
141150
});
142151

143-
Self {
144-
function_name: function_name.to_string(),
145-
frames: vec![Frame::new(
146-
FrameEntry::FunctionRoot,
147-
Some(segment),
148-
lexical_id,
149-
)],
150-
nodes,
151-
}
152+
builder.frames.push(Frame::new(
153+
FrameEntry::FunctionRoot,
154+
Some(segment),
155+
lexical_id,
156+
));
157+
builder
152158
}
153159

154160
fn finish(self) -> VizNodes {
@@ -169,6 +175,12 @@ impl Builder {
169175
encode_segments(&self.function_name, &segments)
170176
}
171177

178+
fn allocate_node_id(&mut self) -> u32 {
179+
let id = self.next_node_id;
180+
self.next_node_id += 1;
181+
id
182+
}
183+
172184
fn push_child(&mut self, node: VizNode, entry: FrameEntry, segment: PathSegment) {
173185
let lexical_id = node.id.clone();
174186
let parent_index = self.frames.len() - 1;
@@ -318,6 +330,7 @@ impl Builder {
318330
let lexical_id = self.build_lexical_id(&segment);
319331
let parent = self.current_parent_lexical();
320332
let node = VizNode {
333+
node_id: self.allocate_node_id(),
321334
id: lexical_id.clone(),
322335
parent,
323336
node_type: RuntimeNodeType::BranchGroup,
@@ -361,6 +374,7 @@ impl Builder {
361374
let lexical_id = self.build_lexical_id(&segment);
362375
let parent = self.current_parent_lexical();
363376
let node = VizNode {
377+
node_id: self.allocate_node_id(),
364378
id: lexical_id.clone(),
365379
parent,
366380
node_type: RuntimeNodeType::BranchArm,
@@ -390,6 +404,7 @@ impl Builder {
390404
let lexical_id = self.build_lexical_id(&segment);
391405
let parent = self.current_parent_lexical();
392406
let node = VizNode {
407+
node_id: self.allocate_node_id(),
393408
id: lexical_id.clone(),
394409
parent,
395410
node_type: RuntimeNodeType::Loop,
@@ -421,6 +436,7 @@ impl Builder {
421436
let lexical_id = self.build_lexical_id(&segment);
422437
let parent = self.current_parent_lexical();
423438
let node = VizNode {
439+
node_id: self.allocate_node_id(),
424440
id: lexical_id.clone(),
425441
parent,
426442
node_type: RuntimeNodeType::OtherScope,
@@ -445,6 +461,7 @@ impl Builder {
445461
let lexical_id = self.build_lexical_id(&segment);
446462
let parent = self.current_parent_lexical();
447463
let node = VizNode {
464+
node_id: self.allocate_node_id(),
448465
id: lexical_id.clone(),
449466
parent,
450467
node_type: RuntimeNodeType::HeaderContextEnter,

engine/baml-compiler/src/watch/watch_event.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn shared_noop_handler() -> SharedWatchHandler {
8989
#[derive(Debug, Clone)]
9090
pub enum WatchBamlValue {
9191
Value(BamlValueWithMeta<WatchValueMetadata>),
92-
Header(HeaderContext),
92+
VizExecHeader(HeaderContext),
9393
VizExecState(VizExecEvent),
9494
StreamStart(StreamId),
9595
StreamUpdate(StreamId, BamlValueWithMeta<WatchValueMetadata>),
@@ -138,7 +138,7 @@ impl fmt::Display for WatchNotification {
138138
write!(f, "{}", value.clone().value())
139139
}
140140
},
141-
WatchBamlValue::Header(header) => {
141+
WatchBamlValue::VizExecHeader(header) => {
142142
write!(
143143
f,
144144
"(header L{level}) {function}.{title}",
@@ -154,9 +154,9 @@ impl fmt::Display for WatchNotification {
154154
};
155155
write!(
156156
f,
157-
"(context {delta}) {function}.{segment}",
158-
function = self.function_name,
159-
segment = event.path_segment.encode()
157+
"(context {delta}) n{node_id} {lexical}",
158+
node_id = event.node_id,
159+
lexical = event.lexical_id
160160
)
161161
}
162162
WatchBamlValue::StreamStart(stream_id) => {
@@ -209,7 +209,7 @@ impl WatchNotification {
209209

210210
pub fn new_block(header: HeaderContext, function_name: String) -> Self {
211211
Self {
212-
value: WatchBamlValue::Header(header),
212+
value: WatchBamlValue::VizExecHeader(header),
213213
variable_name: None,
214214
channel_name: None,
215215
function_name,

engine/baml-runtime/tests/viz-runtime.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ use serde_json::Value;
1616
#[derive(Debug, Clone, Serialize)]
1717
struct EventRecord {
1818
kind: String,
19-
function: String,
20-
variable: Option<String>,
21-
channel: Option<String>,
22-
stream_id: Option<String>,
19+
lexical_id: Option<String>,
2320
header: Option<HeaderEvent>,
2421
viz_event: Option<VizExecEvent>,
25-
value: Option<Value>,
26-
is_stream: bool,
2722
}
2823

2924
#[derive(Debug, Clone, Serialize)]
@@ -159,7 +154,7 @@ fn build_watch_handler(
159154

160155
let mut reducer_guard = reducer.lock().unwrap();
161156
let (updates, state_after) = if let Some(viz_event) = event.viz_event.as_ref() {
162-
let updates = reducer_guard.apply(&event.function, viz_event);
157+
let updates = reducer_guard.apply(viz_event);
163158
let state_after = reducer_guard.dump();
164159
(updates, state_after)
165160
} else {
@@ -176,42 +171,28 @@ fn build_watch_handler(
176171
}
177172

178173
fn to_event_record(notification: &WatchNotification) -> EventRecord {
179-
let (kind, stream_id, viz_event) = match &notification.value {
180-
WatchBamlValue::Value(_) => ("value".to_string(), None, None),
181-
WatchBamlValue::Header(_) => ("header".to_string(), None, None),
182-
WatchBamlValue::VizExecState(event) => {
183-
("viz_exec_state".to_string(), None, Some(event.clone()))
184-
}
185-
WatchBamlValue::StreamStart(id) => ("stream_start".to_string(), Some(id.clone()), None),
186-
WatchBamlValue::StreamUpdate(id, _) => {
187-
("stream_update".to_string(), Some(id.clone()), None)
188-
}
189-
WatchBamlValue::StreamEnd(id) => ("stream_end".to_string(), Some(id.clone()), None),
174+
let (kind, viz_event, lexical_id) = match &notification.value {
175+
WatchBamlValue::VizExecHeader(_) => ("viz_exec_header".to_string(), None, None),
176+
WatchBamlValue::VizExecState(event) => (
177+
"viz_exec_state".to_string(),
178+
Some(event.clone()),
179+
Some(event.lexical_id.clone()),
180+
),
181+
_ => ("other".to_string(), None, None),
190182
};
191183

192184
let header = match &notification.value {
193-
WatchBamlValue::Header(h) => Some(HeaderEvent {
185+
WatchBamlValue::VizExecHeader(h) => Some(HeaderEvent {
194186
level: h.level,
195187
title: h.title.clone(),
196188
}),
197189
_ => None,
198190
};
199191

200-
let value = match &notification.value {
201-
WatchBamlValue::Value(v) => serde_json::to_value(v.clone().value()).ok(),
202-
WatchBamlValue::StreamUpdate(_, v) => serde_json::to_value(v.clone().value()).ok(),
203-
_ => None,
204-
};
205-
206192
EventRecord {
207193
kind,
208-
function: notification.function_name.clone(),
209-
variable: notification.variable_name.clone(),
210-
channel: notification.channel_name.clone(),
211-
stream_id,
194+
lexical_id,
212195
header,
213196
viz_event,
214-
value,
215-
is_stream: notification.is_stream,
216197
}
217198
}

0 commit comments

Comments
 (0)