@@ -10,59 +10,106 @@ export namespace Message {
1010 } ) ) ,
1111 )
1212
13- export class File extends Schema . Class < File > ( "Message.File" ) ( {
14- url : Schema . String ,
13+ export class Source extends Schema . Class < Source > ( "Message.Source" ) ( {
14+ start : Schema . Number ,
15+ end : Schema . Number ,
16+ text : Schema . String ,
17+ } ) { }
18+
19+ export class FileAttachment extends Schema . Class < FileAttachment > ( "Message.File.Attachment" ) ( {
20+ uri : Schema . String ,
1521 mime : Schema . String ,
22+ name : Schema . String . pipe ( Schema . optional ) ,
23+ description : Schema . String . pipe ( Schema . optional ) ,
24+ source : Source . pipe ( Schema . optional ) ,
1625 } ) {
1726 static create ( url : string ) {
18- return new File ( {
19- url,
27+ return new FileAttachment ( {
28+ uri : url ,
2029 mime : "text/plain" ,
2130 } )
2231 }
2332 }
2433
25- export class UserContent extends Schema . Class < UserContent > ( "Message.User.Content" ) ( {
26- text : Schema . String ,
27- synthetic : Schema . Boolean . pipe ( Schema . optional ) ,
28- agent : Schema . String . pipe ( Schema . optional ) ,
29- files : Schema . Array ( File ) . pipe ( Schema . optional ) ,
34+ export class AgentAttachment extends Schema . Class < AgentAttachment > ( "Message.Agent.Attachment" ) ( {
35+ name : Schema . String ,
36+ source : Source . pipe ( Schema . optional ) ,
3037 } ) { }
3138
3239 export class User extends Schema . Class < User > ( "Message.User" ) ( {
3340 id : ID ,
3441 type : Schema . Literal ( "user" ) ,
42+ text : Schema . String ,
43+ files : Schema . Array ( FileAttachment ) . pipe ( Schema . optional ) ,
44+ agents : Schema . Array ( AgentAttachment ) . pipe ( Schema . optional ) ,
3545 time : Schema . Struct ( {
3646 created : Schema . DateTimeUtc ,
3747 } ) ,
38- content : UserContent ,
3948 } ) {
40- static create ( content : Schema . Schema . Type < typeof UserContent > ) {
49+ static create ( input : { text : User [ "text" ] ; files ?: User [ "files" ] ; agents ?: User [ "agents" ] } ) {
4150 const msg = new User ( {
4251 id : ID . create ( ) ,
4352 type : "user" ,
53+ ...input ,
4454 time : {
4555 created : Effect . runSync ( DateTime . now ) ,
4656 } ,
47- content,
4857 } )
4958 return msg
5059 }
51-
52- static file ( url : string ) {
53- return new File ( {
54- url,
55- mime : "text/plain" ,
56- } )
57- }
5860 }
5961
60- export namespace User { }
61- }
62+ export class Synthetic extends Schema . Class < Synthetic > ( "Message.Synthetic" ) ( {
63+ id : ID ,
64+ type : Schema . Literal ( "synthetic" ) ,
65+ text : Schema . String ,
66+ time : Schema . Struct ( {
67+ created : Schema . DateTimeUtc ,
68+ } ) ,
69+ } ) { }
6270
63- const msg = Message . User . create ( {
64- text : "Hello world" ,
65- files : [ Message . File . create ( "file://example.com/file.txt" ) ] ,
66- } )
71+ export class Request extends Schema . Class < Request > ( "Message.Request" ) ( {
72+ id : ID ,
73+ type : Schema . Literal ( "start" ) ,
74+ model : Schema . Struct ( {
75+ id : Schema . String ,
76+ providerID : Schema . String ,
77+ variant : Schema . String . pipe ( Schema . optional ) ,
78+ } ) ,
79+ time : Schema . Struct ( {
80+ created : Schema . DateTimeUtc ,
81+ } ) ,
82+ } ) { }
83+
84+ export class Text extends Schema . Class < Text > ( "Message.Text" ) ( {
85+ id : ID ,
86+ type : Schema . Literal ( "text" ) ,
87+ text : Schema . String ,
88+ time : Schema . Struct ( {
89+ created : Schema . DateTimeUtc ,
90+ completed : Schema . DateTimeUtc . pipe ( Schema . optional ) ,
91+ } ) ,
92+ } ) { }
6793
68- console . log ( JSON . stringify ( msg , null , 2 ) )
94+ export class Complete extends Schema . Class < Complete > ( "Message.Complete" ) ( {
95+ id : ID ,
96+ type : Schema . Literal ( "complete" ) ,
97+ time : Schema . Struct ( {
98+ created : Schema . DateTimeUtc ,
99+ } ) ,
100+ cost : Schema . Number ,
101+ tokens : Schema . Struct ( {
102+ total : Schema . Number ,
103+ input : Schema . Number ,
104+ output : Schema . Number ,
105+ reasoning : Schema . Number ,
106+ cache : Schema . Struct ( {
107+ read : Schema . Number ,
108+ write : Schema . Number ,
109+ } ) ,
110+ } ) ,
111+ } ) { }
112+
113+ export const Info = Schema . Union ( [ User , Text ] )
114+ export type Info = Schema . Schema . Type < typeof Info >
115+ }
0 commit comments