44 StreamEventTypes ,
55 traceContextSchema ,
66} from '@latitude-data/constants'
7- import { messageSchema } from '@latitude-data/core/constants'
87
98export const languageModelUsageSchema = z . object ( {
109 completionTokens : z . number ( ) . optional ( ) ,
@@ -15,11 +14,131 @@ export const languageModelUsageSchema = z.object({
1514export const toolCallSchema = z . object ( {
1615 id : z . string ( ) ,
1716 name : z . string ( ) ,
18- arguments : z . record ( z . string ( ) , z . any ( ) ) ,
17+ arguments : z . record ( z . string ( ) , z . unknown ( ) ) . openapi ( {
18+ type : 'object' ,
19+ additionalProperties : true ,
20+ description : 'Tool call arguments as key-value pairs' ,
21+ } ) ,
22+ } )
23+
24+ const textContentSchema = z . object ( {
25+ type : z . literal ( 'text' ) ,
26+ text : z . string ( ) ,
27+ } )
28+
29+ const imageContentSchema = z . object ( {
30+ type : z . literal ( 'image' ) ,
31+ image : z
32+ . string ( )
33+ . or ( z . instanceof ( Uint8Array ) )
34+ . or ( z . instanceof ( ArrayBuffer ) )
35+ . or ( z . instanceof ( URL ) )
36+ . openapi ( {
37+ type : 'string' ,
38+ description :
39+ 'Image data as string (URL, base64), Uint8Array, ArrayBuffer, or URL object' ,
40+ format : 'binary' ,
41+ } ) ,
42+ mimeType : z . string ( ) . optional ( ) ,
43+ } )
44+
45+ const fileContentSchema = z . object ( {
46+ type : z . literal ( 'file' ) ,
47+ file : z
48+ . string ( )
49+ . or ( z . instanceof ( Uint8Array ) )
50+ . or ( z . instanceof ( ArrayBuffer ) )
51+ . or ( z . instanceof ( URL ) )
52+ . openapi ( {
53+ type : 'string' ,
54+ description :
55+ 'File data as string (URL, base64), Uint8Array, ArrayBuffer, or URL object' ,
56+ format : 'binary' ,
57+ } ) ,
58+ mimeType : z . string ( ) ,
59+ } )
60+
61+ const toolCallContentSchema = z . object ( {
62+ type : z . literal ( 'tool-call' ) ,
63+ toolCallId : z . string ( ) ,
64+ toolName : z . string ( ) ,
65+ args : z . record ( z . string ( ) , z . unknown ( ) ) . openapi ( {
66+ type : 'object' ,
67+ additionalProperties : true ,
68+ description : 'Tool call arguments as key-value pairs' ,
69+ } ) ,
1970} )
2071
21- export const configSchema = z . record ( z . string ( ) , z . any ( ) )
22- export const providerLogSchema = z . record ( z . string ( ) , z . any ( ) )
72+ const toolResultContentSchema = z . object ( {
73+ type : z . literal ( 'tool-result' ) ,
74+ toolCallId : z . string ( ) ,
75+ toolName : z . string ( ) ,
76+ result : z . unknown ( ) . openapi ( {
77+ type : 'object' ,
78+ additionalProperties : true ,
79+ description : 'Tool result as any JSON-serializable value' ,
80+ } ) ,
81+ isError : z . boolean ( ) . optional ( ) ,
82+ } )
83+
84+ export const messageSchema = z
85+ . object ( {
86+ role : z . literal ( 'system' ) ,
87+ content : z . string ( ) . or ( z . array ( textContentSchema ) ) ,
88+ } )
89+ . or (
90+ z . object ( {
91+ role : z . literal ( 'user' ) ,
92+ content : z
93+ . string ( )
94+ . or (
95+ z . array (
96+ textContentSchema . or ( imageContentSchema ) . or ( fileContentSchema ) ,
97+ ) ,
98+ ) ,
99+ name : z . string ( ) . optional ( ) ,
100+ } ) ,
101+ )
102+ . or (
103+ z . object ( {
104+ role : z . literal ( 'assistant' ) ,
105+ content : z
106+ . string ( )
107+ . or ( z . array ( textContentSchema . or ( toolCallContentSchema ) ) ) ,
108+ toolCalls : z
109+ . array (
110+ z . object ( {
111+ id : z . string ( ) ,
112+ name : z . string ( ) ,
113+ arguments : z . record ( z . string ( ) , z . unknown ( ) ) . openapi ( {
114+ type : 'object' ,
115+ additionalProperties : true ,
116+ description : 'Tool call arguments as key-value pairs' ,
117+ } ) ,
118+ } ) ,
119+ )
120+ . optional ( ) ,
121+ } ) ,
122+ )
123+ . or (
124+ z . object ( {
125+ role : z . literal ( 'tool' ) ,
126+ content : z . array ( toolResultContentSchema ) ,
127+ } ) ,
128+ )
129+
130+ export const messagesSchema = z . array ( messageSchema )
131+
132+ export const configSchema = z . record ( z . string ( ) , z . any ( ) ) . openapi ( {
133+ type : 'object' ,
134+ additionalProperties : true ,
135+ description : 'Configuration as key-value pairs' ,
136+ } )
137+ export const providerLogSchema = z . record ( z . string ( ) , z . any ( ) ) . openapi ( {
138+ type : 'object' ,
139+ additionalProperties : true ,
140+ description : 'Provider log as key-value pairs' ,
141+ } )
23142export const chainStepResponseSchema = z . discriminatedUnion ( 'streamType' , [
24143 z . object ( {
25144 streamType : z . literal ( 'text' ) ,
@@ -31,7 +150,11 @@ export const chainStepResponseSchema = z.discriminatedUnion('streamType', [
31150 } ) ,
32151 z . object ( {
33152 streamType : z . literal ( 'object' ) ,
34- object : z . any ( ) ,
153+ object : z . any ( ) . openapi ( {
154+ type : 'object' ,
155+ additionalProperties : true ,
156+ description : 'Stream object data (any JSON-serializable value)' ,
157+ } ) ,
35158 text : z . string ( ) ,
36159 usage : languageModelUsageSchema ,
37160 documentLogUuid : z . string ( ) . optional ( ) ,
@@ -58,7 +181,11 @@ export const chainEventDtoResponseSchema = z.discriminatedUnion('streamType', [
58181export const legacyChainEventDtoSchema = z . discriminatedUnion ( 'event' , [
59182 z . object ( {
60183 event : z . literal ( StreamEventTypes . Provider ) ,
61- data : z . record ( z . string ( ) , z . any ( ) ) ,
184+ data : z . record ( z . string ( ) , z . any ( ) ) . openapi ( {
185+ type : 'object' ,
186+ additionalProperties : true ,
187+ description : 'Provider event data as key-value pairs' ,
188+ } ) ,
62189 } ) ,
63190 z . object ( {
64191 event : z . literal ( StreamEventTypes . Latitude ) ,
@@ -79,7 +206,11 @@ export const legacyChainEventDtoSchema = z.discriminatedUnion('event', [
79206 type : z . literal ( LegacyChainEventTypes . Complete ) ,
80207 config : configSchema ,
81208 messages : z . array ( messageSchema ) . optional ( ) ,
82- object : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) ,
209+ object : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) . openapi ( {
210+ type : 'object' ,
211+ additionalProperties : true ,
212+ description : 'Complete event object data as key-value pairs' ,
213+ } ) ,
83214 response : chainEventDtoResponseSchema ,
84215 uuid : z . string ( ) . optional ( ) ,
85216 } ) ,
0 commit comments