pub struct ContextContribution {
pub source_name: String,
pub elements: Vec<ContextElement>,
pub app: Option<String>,
pub window: Option<String>,
pub stream_status: StreamStatus,
}Expand description
Generic source contribution accepted by ContextMerger.
Fields§
§source_name: String§elements: Vec<ContextElement>§app: Option<String>§window: Option<String>§stream_status: StreamStatusImplementations§
Source§impl ContextContribution
impl ContextContribution
Sourcepub fn new(
source_name: impl Into<String>,
elements: Vec<ContextElement>,
) -> Self
pub fn new( source_name: impl Into<String>, elements: Vec<ContextElement>, ) -> Self
Examples found in repository?
examples/dump_context.rs (lines 12-37)
10fn main() {
11 let mut merger = ContextMerger::new().with_defaults("Example App", "Main");
12 merger.push(ContextContribution::new(
13 "test_source",
14 vec![ContextElement {
15 id: "button:submit".into(),
16 label: Some("Submit".into()),
17 description: None,
18 element_type: "button".into(),
19 value: None,
20 bounds: Some(Bounds {
21 x: 100,
22 y: 200,
23 width: 120,
24 height: 32,
25 }),
26 state: ElementState {
27 focused: true,
28 ..Default::default()
29 },
30 parent_id: None,
31 actions: Vec::new(),
32 confidence: 0.0,
33 source: ContextSource::NativeApi,
34 content_role: ContentRole::Interactive,
35 properties: Default::default(),
36 }],
37 ));
38
39 let ctx = merger.build();
40 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
41
42 let reference = ctx.elements[0].to_reference(1920, 1080);
43 let resolved = cel_context::resolve_reference(&ctx, &reference);
44 println!(
45 "resolved reference: {:?}",
46 resolved.map(|el| el.id.as_str())
47 );
48
49 let mut watchdog = ContextWatchdog::new();
50 assert!(watchdog.tick(&ctx, true).is_empty());
51
52 let mut changed = ctx.clone();
53 changed.elements[0].state.focused = false;
54 let events = watchdog.tick(&changed, true);
55 println!("watchdog events: {events:?}");
56}More examples
examples/context_snapshot.rs (lines 19-42)
14fn main() {
15 let json_output = std::env::args().any(|arg| arg == "--json");
16
17 let mut merger = ContextMerger::new().with_defaults("Example CRM", "Customer Detail");
18 merger.push(
19 ContextContribution::new(
20 "crm_api",
21 vec![
22 element(
23 "crm:title",
24 "heading",
25 "Customer: Acme Corp",
26 ContextSource::NativeApi,
27 None,
28 ),
29 element(
30 "crm:button:save",
31 "button",
32 "Save changes",
33 ContextSource::NativeApi,
34 Some(Bounds {
35 x: 720,
36 y: 64,
37 width: 128,
38 height: 36,
39 }),
40 ),
41 ],
42 )
43 .with_app("Example CRM")
44 .with_window("Customer Detail")
45 .with_stream_status(StreamStatus {
46 accessibility: false,
47 display: false,
48 network: false,
49 signals: false,
50 vision: false,
51 audio_capture: false,
52 }),
53 );
54 merger.push(ContextContribution::new(
55 "browser_dom",
56 vec![element(
57 "dom:input:notes",
58 "textbox",
59 "Internal notes",
60 ContextSource::Cdp,
61 Some(Bounds {
62 x: 160,
63 y: 420,
64 width: 520,
65 height: 120,
66 }),
67 )],
68 ));
69
70 let ctx = merger.build();
71
72 if json_output {
73 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
74 return;
75 }
76
77 println!("=== CEL Context Snapshot ===");
78 println!("App: {}", ctx.app);
79 println!("Window: {}", ctx.window);
80 println!("Timestamp: {} ms", ctx.timestamp_ms);
81 println!("Elements: {}", ctx.elements.len());
82 println!();
83
84 for (i, elem) in ctx.elements.iter().enumerate() {
85 let label = elem.label.as_deref().unwrap_or("(no label)");
86 let bounds = elem
87 .bounds
88 .as_ref()
89 .map(|b| format!("[{},{} {}x{}]", b.x, b.y, b.width, b.height))
90 .unwrap_or_else(|| "(no bounds)".into());
91 println!(
92 " {:>2}. [{:.2}] {:12} {:22} {} {:?}",
93 i + 1,
94 elem.confidence,
95 elem.element_type,
96 label,
97 bounds,
98 elem.source
99 );
100 }
101}Sourcepub fn with_app(self, app: impl Into<String>) -> Self
pub fn with_app(self, app: impl Into<String>) -> Self
Examples found in repository?
examples/context_snapshot.rs (line 43)
14fn main() {
15 let json_output = std::env::args().any(|arg| arg == "--json");
16
17 let mut merger = ContextMerger::new().with_defaults("Example CRM", "Customer Detail");
18 merger.push(
19 ContextContribution::new(
20 "crm_api",
21 vec![
22 element(
23 "crm:title",
24 "heading",
25 "Customer: Acme Corp",
26 ContextSource::NativeApi,
27 None,
28 ),
29 element(
30 "crm:button:save",
31 "button",
32 "Save changes",
33 ContextSource::NativeApi,
34 Some(Bounds {
35 x: 720,
36 y: 64,
37 width: 128,
38 height: 36,
39 }),
40 ),
41 ],
42 )
43 .with_app("Example CRM")
44 .with_window("Customer Detail")
45 .with_stream_status(StreamStatus {
46 accessibility: false,
47 display: false,
48 network: false,
49 signals: false,
50 vision: false,
51 audio_capture: false,
52 }),
53 );
54 merger.push(ContextContribution::new(
55 "browser_dom",
56 vec![element(
57 "dom:input:notes",
58 "textbox",
59 "Internal notes",
60 ContextSource::Cdp,
61 Some(Bounds {
62 x: 160,
63 y: 420,
64 width: 520,
65 height: 120,
66 }),
67 )],
68 ));
69
70 let ctx = merger.build();
71
72 if json_output {
73 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
74 return;
75 }
76
77 println!("=== CEL Context Snapshot ===");
78 println!("App: {}", ctx.app);
79 println!("Window: {}", ctx.window);
80 println!("Timestamp: {} ms", ctx.timestamp_ms);
81 println!("Elements: {}", ctx.elements.len());
82 println!();
83
84 for (i, elem) in ctx.elements.iter().enumerate() {
85 let label = elem.label.as_deref().unwrap_or("(no label)");
86 let bounds = elem
87 .bounds
88 .as_ref()
89 .map(|b| format!("[{},{} {}x{}]", b.x, b.y, b.width, b.height))
90 .unwrap_or_else(|| "(no bounds)".into());
91 println!(
92 " {:>2}. [{:.2}] {:12} {:22} {} {:?}",
93 i + 1,
94 elem.confidence,
95 elem.element_type,
96 label,
97 bounds,
98 elem.source
99 );
100 }
101}Sourcepub fn with_window(self, window: impl Into<String>) -> Self
pub fn with_window(self, window: impl Into<String>) -> Self
Examples found in repository?
examples/context_snapshot.rs (line 44)
14fn main() {
15 let json_output = std::env::args().any(|arg| arg == "--json");
16
17 let mut merger = ContextMerger::new().with_defaults("Example CRM", "Customer Detail");
18 merger.push(
19 ContextContribution::new(
20 "crm_api",
21 vec![
22 element(
23 "crm:title",
24 "heading",
25 "Customer: Acme Corp",
26 ContextSource::NativeApi,
27 None,
28 ),
29 element(
30 "crm:button:save",
31 "button",
32 "Save changes",
33 ContextSource::NativeApi,
34 Some(Bounds {
35 x: 720,
36 y: 64,
37 width: 128,
38 height: 36,
39 }),
40 ),
41 ],
42 )
43 .with_app("Example CRM")
44 .with_window("Customer Detail")
45 .with_stream_status(StreamStatus {
46 accessibility: false,
47 display: false,
48 network: false,
49 signals: false,
50 vision: false,
51 audio_capture: false,
52 }),
53 );
54 merger.push(ContextContribution::new(
55 "browser_dom",
56 vec![element(
57 "dom:input:notes",
58 "textbox",
59 "Internal notes",
60 ContextSource::Cdp,
61 Some(Bounds {
62 x: 160,
63 y: 420,
64 width: 520,
65 height: 120,
66 }),
67 )],
68 ));
69
70 let ctx = merger.build();
71
72 if json_output {
73 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
74 return;
75 }
76
77 println!("=== CEL Context Snapshot ===");
78 println!("App: {}", ctx.app);
79 println!("Window: {}", ctx.window);
80 println!("Timestamp: {} ms", ctx.timestamp_ms);
81 println!("Elements: {}", ctx.elements.len());
82 println!();
83
84 for (i, elem) in ctx.elements.iter().enumerate() {
85 let label = elem.label.as_deref().unwrap_or("(no label)");
86 let bounds = elem
87 .bounds
88 .as_ref()
89 .map(|b| format!("[{},{} {}x{}]", b.x, b.y, b.width, b.height))
90 .unwrap_or_else(|| "(no bounds)".into());
91 println!(
92 " {:>2}. [{:.2}] {:12} {:22} {} {:?}",
93 i + 1,
94 elem.confidence,
95 elem.element_type,
96 label,
97 bounds,
98 elem.source
99 );
100 }
101}Sourcepub fn with_stream_status(self, status: StreamStatus) -> Self
pub fn with_stream_status(self, status: StreamStatus) -> Self
Examples found in repository?
examples/context_snapshot.rs (lines 45-52)
14fn main() {
15 let json_output = std::env::args().any(|arg| arg == "--json");
16
17 let mut merger = ContextMerger::new().with_defaults("Example CRM", "Customer Detail");
18 merger.push(
19 ContextContribution::new(
20 "crm_api",
21 vec![
22 element(
23 "crm:title",
24 "heading",
25 "Customer: Acme Corp",
26 ContextSource::NativeApi,
27 None,
28 ),
29 element(
30 "crm:button:save",
31 "button",
32 "Save changes",
33 ContextSource::NativeApi,
34 Some(Bounds {
35 x: 720,
36 y: 64,
37 width: 128,
38 height: 36,
39 }),
40 ),
41 ],
42 )
43 .with_app("Example CRM")
44 .with_window("Customer Detail")
45 .with_stream_status(StreamStatus {
46 accessibility: false,
47 display: false,
48 network: false,
49 signals: false,
50 vision: false,
51 audio_capture: false,
52 }),
53 );
54 merger.push(ContextContribution::new(
55 "browser_dom",
56 vec![element(
57 "dom:input:notes",
58 "textbox",
59 "Internal notes",
60 ContextSource::Cdp,
61 Some(Bounds {
62 x: 160,
63 y: 420,
64 width: 520,
65 height: 120,
66 }),
67 )],
68 ));
69
70 let ctx = merger.build();
71
72 if json_output {
73 println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
74 return;
75 }
76
77 println!("=== CEL Context Snapshot ===");
78 println!("App: {}", ctx.app);
79 println!("Window: {}", ctx.window);
80 println!("Timestamp: {} ms", ctx.timestamp_ms);
81 println!("Elements: {}", ctx.elements.len());
82 println!();
83
84 for (i, elem) in ctx.elements.iter().enumerate() {
85 let label = elem.label.as_deref().unwrap_or("(no label)");
86 let bounds = elem
87 .bounds
88 .as_ref()
89 .map(|b| format!("[{},{} {}x{}]", b.x, b.y, b.width, b.height))
90 .unwrap_or_else(|| "(no bounds)".into());
91 println!(
92 " {:>2}. [{:.2}] {:12} {:22} {} {:?}",
93 i + 1,
94 elem.confidence,
95 elem.element_type,
96 label,
97 bounds,
98 elem.source
99 );
100 }
101}Trait Implementations§
Source§impl Clone for ContextContribution
impl Clone for ContextContribution
Source§fn clone(&self) -> ContextContribution
fn clone(&self) -> ContextContribution
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContextContribution
impl Debug for ContextContribution
Source§impl Default for ContextContribution
impl Default for ContextContribution
Source§fn default() -> ContextContribution
fn default() -> ContextContribution
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ContextContribution
impl RefUnwindSafe for ContextContribution
impl Send for ContextContribution
impl Sync for ContextContribution
impl Unpin for ContextContribution
impl UnsafeUnpin for ContextContribution
impl UnwindSafe for ContextContribution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more