1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts -nocheck
3
+ /* eslint-disable */
4
+
1
5
import { differenceInMilliseconds , isAfter , isBefore } from 'date-fns'
2
6
import { scan } from 'promptl-ai'
3
7
import {
4
8
ApiKey ,
5
- BaseSegmentMetadata ,
6
9
DocumentType ,
7
10
EvaluationType ,
8
11
EvaluationV2 ,
@@ -12,7 +15,6 @@ import {
12
15
SegmentMetadata ,
13
16
SegmentSource ,
14
17
SegmentType ,
15
- SegmentWithDetails ,
16
18
SpanStatus ,
17
19
SpanType ,
18
20
SpanWithDetails ,
@@ -75,101 +77,102 @@ export async function processSegment(
75
77
76
78
const type = state . current ?. type ?? state . segment . type
77
79
78
- const specification = SEGMENT_SPECIFICATIONS [ type ]
79
- if ( ! specification ) {
80
- return Result . error ( new UnprocessableEntityError ( 'Invalid segment type' ) )
81
- }
82
-
83
- let metadata = {
84
- ...( {
85
- traceId : traceId ,
86
- segmentId : id ,
87
- type : type ,
88
- } satisfies BaseSegmentMetadata ) ,
89
- } as SegmentMetadata
90
-
91
- // @ts -expect-error seems typescript cannot infer that state types are the same
92
- const processing = await specification . process ( state , tx )
93
- if ( processing . error ) return Result . error ( processing . error )
94
- metadata = { ...metadata , ...processing . value }
95
-
96
- // Note: edge case when the global document segment is being processed right now for the first time
97
- if ( metadata . type === SegmentType . Document ) {
98
- state . run = { metadata } as SegmentWithDetails < SegmentType . Document >
99
- }
100
-
101
- const computingei = computeExternalId ( state )
102
- if ( computingei . error ) return Result . error ( computingei . error )
103
- const externalId = computingei . value
104
-
105
- const enrichingnm = enrichName ( state )
106
- if ( enrichingnm . error ) return Result . error ( enrichingnm . error )
107
- const name = enrichingnm . value
108
-
109
- const computingsc = computeSource ( state )
110
- if ( computingsc . error ) return Result . error ( computingsc . error )
111
- const source = computingsc . value
112
-
113
- const computingst = computeStatus ( state )
114
- if ( computingst . error ) return Result . error ( computingst . error )
115
- const { status, message } = computingst . value
80
+ // const specification = SEGMENT_SPECIFICATIONS[type]
81
+ // if (!specification) {
82
+ // return Result.error(new UnprocessableEntityError('Invalid segment type'))
83
+ // }
84
+
85
+ // let metadata = {
86
+ // ...({
87
+ // traceId: traceId,
88
+ // segmentId: id,
89
+ // type: type,
90
+ // } satisfies BaseSegmentMetadata),
91
+ // } as SegmentMetadata
92
+
93
+ // // @ts -expect-error seems typescript cannot infer that state types are the same
94
+ // const processing = await specification.process(state, tx)
95
+ // if (processing.error) return Result.error(processing.error)
96
+ // metadata = { ...metadata, ...processing.value }
97
+
98
+ // // Note: edge case when the global document segment is being processed right now for the first time
99
+ // if (metadata.type === SegmentType.Document) {
100
+ // state.run = { metadata } as SegmentWithDetails<SegmentType.Document>
101
+ // }
102
+
103
+ // const computingei = computeExternalId(state)
104
+ // if (computingei.error) return Result.error(computingei.error)
105
+ // const externalId = computingei.value
106
+
107
+ // const enrichingnm = enrichName(state)
108
+ // if (enrichingnm.error) return Result.error(enrichingnm.error)
109
+ // const name = enrichingnm.value
110
+
111
+ // const computingsc = computeSource(state)
112
+ // if (computingsc.error) return Result.error(computingsc.error)
113
+ // const source = computingsc.value
114
+
115
+ // const computingst = computeStatus(state)
116
+ // if (computingst.error) return Result.error(computingst.error)
117
+ // const { status, message } = computingst.value
116
118
117
119
const computinglu = computeLogUuid ( state )
118
120
if ( computinglu . error ) return Result . error ( computinglu . error )
119
121
const logUuid = computinglu . value
120
122
121
- const computingdc = computeDocument ( state )
122
- if ( computingdc . error ) return Result . error ( computingdc . error )
123
- const { commitUuid, documentUuid, documentHash,
124
- documentType, provider, model } = computingdc . value // prettier-ignore
123
+ // const computingdc = computeDocument(state)
124
+ // if (computingdc.error) return Result.error(computingdc.error)
125
+ // const { commitUuid, documentUuid, documentHash,
126
+ // documentType, provider, model } = computingdc.value // prettier-ignore
125
127
126
- const computingeu = computeExperimentUuid ( state )
127
- if ( computingeu . error ) return Result . error ( computingeu . error )
128
- const experimentUuid = computingeu . value
128
+ // const computingeu = computeExperimentUuid(state)
129
+ // if (computingeu.error) return Result.error(computingeu.error)
130
+ // const experimentUuid = computingeu.value
129
131
130
- const computingsa = computeStatistics ( state )
131
- if ( computingsa . error ) return Result . error ( computingsa . error )
132
- const { tokens, cost, duration } = computingsa . value
132
+ // const computingsa = computeStatistics(state)
133
+ // if (computingsa.error) return Result.error(computingsa.error)
134
+ // const { tokens, cost, duration } = computingsa.value
133
135
134
- const computingts = computeTimestamps ( state )
135
- if ( computingts . error ) return Result . error ( computingts . error )
136
- const { startedAt, endedAt } = computingts . value
136
+ // const computingts = computeTimestamps(state)
137
+ // if (computingts.error) return Result.error(computingts.error)
138
+ // const { startedAt, endedAt } = computingts.value
137
139
138
140
const repository = new SegmentsRepository ( args . workspace . id , tx )
139
141
const locking = await repository . lock ( { segmentId : id , traceId } )
140
142
if ( locking . error ) {
141
143
return Result . error ( new ConflictError ( 'Segment processing data race' ) )
142
144
}
143
145
144
- const saving = await saveMetadata ( { metadata, workspace : args . workspace } , disk ) // prettier-ignore
145
- if ( saving . error ) return Result . error ( saving . error )
146
+ // const saving = await saveMetadata({ metadata, workspace: args.workspace }, disk) // prettier-ignore
147
+ // if (saving.error) return Result.error(saving.error)
146
148
149
+ // TODO(tracing): temporal segment fixing patch
147
150
const fields = {
148
151
...( state . current ?? { } ) ,
149
152
id : id ,
150
153
traceId : traceId ,
151
154
parentId : parentId ,
152
155
workspaceId : args . workspace . id ,
153
156
apiKeyId : args . apiKey . id ,
154
- externalId : externalId ,
155
- name : name ,
156
- source : source ,
157
+ externalId : undefined , // externalId,
158
+ name : 'name' , // name,
159
+ source : SegmentSource . API , // source,
157
160
type : type ,
158
- status : status ,
159
- message : message ,
161
+ status : SpanStatus . Ok , // status,
162
+ message : undefined , // message,
160
163
logUuid : logUuid ,
161
- commitUuid : commitUuid ,
162
- documentUuid : documentUuid ,
163
- documentHash : documentHash ,
164
- documentType : documentType ,
165
- experimentUuid : experimentUuid ,
166
- provider : provider ,
167
- model : model ,
168
- tokens : tokens ,
169
- cost : cost ,
170
- duration : duration ,
171
- startedAt : startedAt ,
172
- endedAt : endedAt ,
164
+ commitUuid : '7fdf3f27-ed4e-4710-a8fd-90b4121e2106' , // commitUuid,
165
+ documentUuid : '7fdf3f27-ed4e-4710-a8fd-90b4121e2106' , // documentUuid,
166
+ documentHash : 'documentHash' , // documentHash,
167
+ documentType : DocumentType . Prompt , // documentType,
168
+ experimentUuid : undefined , // experimentUuid,
169
+ provider : 'provider' , // provider,
170
+ model : 'model' , // model,
171
+ tokens : 0 , // tokens,
172
+ cost : 0 , // cost,
173
+ duration : 0 , // duration,
174
+ startedAt : new Date ( ) , // startedAt,
175
+ endedAt : new Date ( ) , // endedAt,
173
176
}
174
177
175
178
const segment = ( await tx
@@ -227,12 +230,15 @@ export async function processSegment(
227
230
await tracingQueue . add ( 'processSegmentJob' , payload , {
228
231
attempts : TRACING_JOBS_MAX_ATTEMPTS ,
229
232
deduplication : {
230
- id : processSegmentJobKey ( payload , { ...segment , metadata } ) ,
233
+ id : processSegmentJobKey ( payload , {
234
+ ...segment ,
235
+ metadata : undefined ,
236
+ } ) ,
231
237
} ,
232
238
} )
233
239
}
234
240
235
- return Result . ok ( { segment : { ...segment , metadata } } )
241
+ return Result . ok ( { segment : { ...segment , metadata : undefined } } )
236
242
} )
237
243
}
238
244
0 commit comments