11import type { CreatableEvent } from "../eventRepository.server" ;
22
3- type StyleEnricher = {
4- name : string ;
5- condition : ( event : CreatableEvent ) => boolean ;
6- enrich : ( event : CreatableEvent ) => Record < string , string > | undefined ;
7- } ;
8-
9- // Define our style enrichers
10- const styleEnrichers : StyleEnricher [ ] = [
11- {
12- name : "GenAI System" ,
13- condition : ( event ) => typeof event . properties [ "gen_ai.system" ] === "string" ,
14- enrich : ( event ) => ( {
15- icon : `tabler-brand-${ event . properties [ "gen_ai.system" ] } ` ,
16- } ) ,
17- } ,
18- {
19- name : "Agent workflow" ,
20- condition : ( event ) =>
21- typeof event . properties [ "name" ] === "string" &&
22- event . properties [ "name" ] . includes ( "Agent workflow" ) ,
23- enrich : ( ) => ( {
24- icon : "tabler-brain" ,
25- } ) ,
26- } ,
27- ] ;
28-
293export function enrichCreatableEvents ( events : CreatableEvent [ ] ) {
304 return events . map ( ( event ) => {
315 return enrichCreatableEvent ( event ) ;
@@ -42,23 +16,22 @@ function enrichCreatableEvent(event: CreatableEvent): CreatableEvent {
4216}
4317
4418function enrichStyle ( event : CreatableEvent ) {
45- // Keep existing style properties as base
4619 const baseStyle = event . style ?? { } ;
20+ const props = event . properties ;
4721
48- // Find the first matching enricher
49- for ( const enricher of styleEnrichers ) {
50- if ( enricher . condition ( event ) ) {
51- const enrichedStyle = enricher . enrich ( event ) ;
52- if ( enrichedStyle ) {
53- return {
54- ... baseStyle ,
55- ... enrichedStyle ,
56- } ;
57- }
58- }
22+ // Direct property access and early returns
23+ // GenAI System check
24+ const system = props [ "gen_ai.system" ] ;
25+ if ( typeof system === "string" ) {
26+ return { ... baseStyle , icon : `tabler-brand- ${ system } ` } ;
27+ }
28+
29+ // Agent workflow check
30+ const name = props [ "name" ] ;
31+ if ( typeof name === "string" && name . includes ( "Agent workflow" ) ) {
32+ return { ... baseStyle , icon : "tabler-brain" } ;
5933 }
6034
61- // Return original style if no enricher matched
6235 return baseStyle ;
6336}
6437
@@ -70,6 +43,16 @@ function repr(value: any): string {
7043}
7144
7245function formatPythonStyle ( template : string , values : Record < string , any > ) : string {
46+ // Early return if template is too long
47+ if ( template . length >= 256 ) {
48+ return template ;
49+ }
50+
51+ // Early return if no template variables present
52+ if ( ! template . includes ( "{" ) ) {
53+ return template ;
54+ }
55+
7356 return template . replace ( / \{ ( [ ^ } ] + ?) (?: ! r ) ? \} / g, ( match , key ) => {
7457 const hasRepr = match . endsWith ( "!r}" ) ;
7558 const actualKey = hasRepr ? key : key ;
0 commit comments