@@ -102,14 +102,15 @@ function computeModelIter(
102
102
103
103
const childrenModel = childrenOf ( block )
104
104
. filter ( nonNullable )
105
- . flatMap ( ( child ) => computeModelIter ( child , root ) )
105
+ . flatMap ( ( child : PdlBlock ) => computeModelIter ( child , root ) )
106
106
107
107
// Correct for anomalies in the trace where a child may have an
108
108
// earlier end timestamp than its children. See
109
109
// https://github.com/IBM/prompt-declaration-language/pull/683
110
110
if ( root ) {
111
111
const maxEnd = childrenModel . reduce (
112
- ( maxEnd , child ) => Math . max ( maxEnd , child . block . pdl__timing . end_nanos ) ,
112
+ ( maxEnd : number , child : TimelineRow ) =>
113
+ Math . max ( maxEnd , child . block . pdl__timing . end_nanos ) ,
113
114
0 ,
114
115
)
115
116
root . block . pdl__timing . end_nanos = Math . max (
@@ -122,35 +123,40 @@ function computeModelIter(
122
123
}
123
124
124
125
export function childrenOf ( block : NonScalarPdlBlock ) {
125
- return match ( block )
126
- . with ( { kind : "model" } , ( data ) => [ /*data.input,*/ data . pdl__result ] )
127
- . with ( { kind : "code" } , ( data ) => [ data . pdl__result ] )
128
- . with ( { kind : "get" } , ( data ) => [ data . pdl__result ] )
129
- . with ( { kind : "data" } , ( data ) => [ data . pdl__result ] )
130
- . with ( { kind : "if" , if : { pdl__result : P . _ } } , ( data ) =>
131
- data . if . pdl__result ? [ data . then ] : [ data . else ] ,
132
- )
133
- . with ( { kind : "if" } , ( data ) => [ data . then , data . else ] )
134
- . with ( { kind : "match" } , ( data ) => [ data . with ] ) // TODO
135
- . with ( { kind : "read" } , ( data ) => [ data . pdl__result ] )
136
- . with ( { kind : "include" } , ( data ) => [ data . pdl__trace ?? data . pdl__result ] )
137
- . with ( { kind : "import" } , ( data ) => [ data . pdl__trace ?? data . pdl__result ] )
138
- . with ( { kind : "function" } , ( ) => [ ] )
139
- . with ( { kind : "call" } , ( data ) => [ data . pdl__trace ?? data . pdl__result ] )
140
- . with ( { kind : "text" } , ( data ) => [ data . text ] )
141
- . with ( { kind : "lastOf" } , ( data ) => [ data . lastOf ] )
142
- . with ( { kind : "array" } , ( data ) => [ data . array ] )
143
- . with ( { kind : "object" } , ( data ) => [ data . object ] )
144
- . with ( { kind : "message" } , ( data ) => [ data . content ] )
145
- . with ( { kind : "repeat" } , ( data ) => [ data . pdl__trace ?? data . repeat ] )
146
- . with ( { kind : "empty" } , ( data ) =>
147
- data . defs ? Object . values ( data . defs ) : [ ] ,
148
- )
149
- . with ( { kind : "error" } , ( ) => [ ] ) // TODO show errors in trace
150
- . with ( { kind : undefined } , ( ) => [ ] )
151
- . exhaustive ( )
152
- . flat ( )
153
- . filter ( nonNullable )
126
+ return (
127
+ match ( block )
128
+ . with ( { kind : "model" } , ( data ) => [ /*data.input,*/ data . pdl__result ] )
129
+ . with ( { kind : "code" } , ( data ) => [ data . pdl__result ] )
130
+ . with ( { kind : "get" } , ( data ) => [ data . pdl__result ] )
131
+ . with ( { kind : "data" } , ( data ) => [ data . pdl__result ] )
132
+ . with ( { kind : "if" , if : { pdl__result : P . _ } } , ( data ) =>
133
+ data . if . pdl__result ? [ data . then ] : [ data . else ] ,
134
+ )
135
+ . with ( { kind : "if" } , ( data ) => [ data . then , data . else ] )
136
+ . with ( { kind : "match" } , ( data ) => [ data . with ] ) // TODO
137
+ . with ( { kind : "read" } , ( data ) => [ data . pdl__result ] )
138
+ . with ( { kind : "include" } , ( data ) => [
139
+ data . pdl__trace ?? data . pdl__result ,
140
+ ] )
141
+ . with ( { kind : "import" } , ( data ) => [ data . pdl__trace ?? data . pdl__result ] )
142
+ . with ( { kind : "function" } , ( ) => [ ] )
143
+ . with ( { kind : "call" } , ( data ) => [ data . pdl__trace ?? data . pdl__result ] )
144
+ . with ( { kind : "text" } , ( data ) => [ data . text ] )
145
+ . with ( { kind : "lastOf" } , ( data ) => [ data . lastOf ] )
146
+ . with ( { kind : "array" } , ( data ) => [ data . array ] )
147
+ . with ( { kind : "object" } , ( data ) => [ data . object ] )
148
+ . with ( { kind : "message" } , ( data ) => [ data . content ] )
149
+ . with ( { kind : "repeat" } , ( data ) => [ data . pdl__trace ?? data . repeat ] )
150
+ . with ( { kind : "empty" } , ( data ) =>
151
+ data . defs ? Object . values ( data . defs ) : [ ] ,
152
+ )
153
+ . with ( { kind : "error" } , ( ) => [ ] ) // TODO show errors in trace
154
+ . with ( { kind : undefined } , ( ) => [ ] )
155
+ // @ts -expect-error: TODO
156
+ . exhaustive ( )
157
+ . flat ( )
158
+ . filter ( nonNullable )
159
+ )
154
160
}
155
161
156
162
function positionOf ( row : TimelineRow ) : Position {
0 commit comments