1
1
import type { CreatableEvent } from "../eventRepository.server" ;
2
2
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
-
29
3
export function enrichCreatableEvents ( events : CreatableEvent [ ] ) {
30
4
return events . map ( ( event ) => {
31
5
return enrichCreatableEvent ( event ) ;
@@ -42,23 +16,22 @@ function enrichCreatableEvent(event: CreatableEvent): CreatableEvent {
42
16
}
43
17
44
18
function enrichStyle ( event : CreatableEvent ) {
45
- // Keep existing style properties as base
46
19
const baseStyle = event . style ?? { } ;
20
+ const props = event . properties ;
47
21
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" } ;
59
33
}
60
34
61
- // Return original style if no enricher matched
62
35
return baseStyle ;
63
36
}
64
37
@@ -70,6 +43,16 @@ function repr(value: any): string {
70
43
}
71
44
72
45
function 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
+
73
56
return template . replace ( / \{ ( [ ^ } ] + ?) (?: ! r ) ? \} / g, ( match , key ) => {
74
57
const hasRepr = match . endsWith ( "!r}" ) ;
75
58
const actualKey = hasRepr ? key : key ;
0 commit comments