|
|
@@ -10,59 +10,106 @@ export namespace Message {
|
|
|
})),
|
|
|
)
|
|
|
|
|
|
- export class File extends Schema.Class<File>("Message.File")({
|
|
|
- url: Schema.String,
|
|
|
+ export class Source extends Schema.Class<Source>("Message.Source")({
|
|
|
+ start: Schema.Number,
|
|
|
+ end: Schema.Number,
|
|
|
+ text: Schema.String,
|
|
|
+ }) {}
|
|
|
+
|
|
|
+ export class FileAttachment extends Schema.Class<FileAttachment>("Message.File.Attachment")({
|
|
|
+ uri: Schema.String,
|
|
|
mime: Schema.String,
|
|
|
+ name: Schema.String.pipe(Schema.optional),
|
|
|
+ description: Schema.String.pipe(Schema.optional),
|
|
|
+ source: Source.pipe(Schema.optional),
|
|
|
}) {
|
|
|
static create(url: string) {
|
|
|
- return new File({
|
|
|
- url,
|
|
|
+ return new FileAttachment({
|
|
|
+ uri: url,
|
|
|
mime: "text/plain",
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- export class UserContent extends Schema.Class<UserContent>("Message.User.Content")({
|
|
|
- text: Schema.String,
|
|
|
- synthetic: Schema.Boolean.pipe(Schema.optional),
|
|
|
- agent: Schema.String.pipe(Schema.optional),
|
|
|
- files: Schema.Array(File).pipe(Schema.optional),
|
|
|
+ export class AgentAttachment extends Schema.Class<AgentAttachment>("Message.Agent.Attachment")({
|
|
|
+ name: Schema.String,
|
|
|
+ source: Source.pipe(Schema.optional),
|
|
|
}) {}
|
|
|
|
|
|
export class User extends Schema.Class<User>("Message.User")({
|
|
|
id: ID,
|
|
|
type: Schema.Literal("user"),
|
|
|
+ text: Schema.String,
|
|
|
+ files: Schema.Array(FileAttachment).pipe(Schema.optional),
|
|
|
+ agents: Schema.Array(AgentAttachment).pipe(Schema.optional),
|
|
|
time: Schema.Struct({
|
|
|
created: Schema.DateTimeUtc,
|
|
|
}),
|
|
|
- content: UserContent,
|
|
|
}) {
|
|
|
- static create(content: Schema.Schema.Type<typeof UserContent>) {
|
|
|
+ static create(input: { text: User["text"]; files?: User["files"]; agents?: User["agents"] }) {
|
|
|
const msg = new User({
|
|
|
id: ID.create(),
|
|
|
type: "user",
|
|
|
+ ...input,
|
|
|
time: {
|
|
|
created: Effect.runSync(DateTime.now),
|
|
|
},
|
|
|
- content,
|
|
|
})
|
|
|
return msg
|
|
|
}
|
|
|
-
|
|
|
- static file(url: string) {
|
|
|
- return new File({
|
|
|
- url,
|
|
|
- mime: "text/plain",
|
|
|
- })
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- export namespace User {}
|
|
|
-}
|
|
|
+ export class Synthetic extends Schema.Class<Synthetic>("Message.Synthetic")({
|
|
|
+ id: ID,
|
|
|
+ type: Schema.Literal("synthetic"),
|
|
|
+ text: Schema.String,
|
|
|
+ time: Schema.Struct({
|
|
|
+ created: Schema.DateTimeUtc,
|
|
|
+ }),
|
|
|
+ }) {}
|
|
|
|
|
|
-const msg = Message.User.create({
|
|
|
- text: "Hello world",
|
|
|
- files: [Message.File.create("file://example.com/file.txt")],
|
|
|
-})
|
|
|
+ export class Request extends Schema.Class<Request>("Message.Request")({
|
|
|
+ id: ID,
|
|
|
+ type: Schema.Literal("start"),
|
|
|
+ model: Schema.Struct({
|
|
|
+ id: Schema.String,
|
|
|
+ providerID: Schema.String,
|
|
|
+ variant: Schema.String.pipe(Schema.optional),
|
|
|
+ }),
|
|
|
+ time: Schema.Struct({
|
|
|
+ created: Schema.DateTimeUtc,
|
|
|
+ }),
|
|
|
+ }) {}
|
|
|
+
|
|
|
+ export class Text extends Schema.Class<Text>("Message.Text")({
|
|
|
+ id: ID,
|
|
|
+ type: Schema.Literal("text"),
|
|
|
+ text: Schema.String,
|
|
|
+ time: Schema.Struct({
|
|
|
+ created: Schema.DateTimeUtc,
|
|
|
+ completed: Schema.DateTimeUtc.pipe(Schema.optional),
|
|
|
+ }),
|
|
|
+ }) {}
|
|
|
|
|
|
-console.log(JSON.stringify(msg, null, 2))
|
|
|
+ export class Complete extends Schema.Class<Complete>("Message.Complete")({
|
|
|
+ id: ID,
|
|
|
+ type: Schema.Literal("complete"),
|
|
|
+ time: Schema.Struct({
|
|
|
+ created: Schema.DateTimeUtc,
|
|
|
+ }),
|
|
|
+ cost: Schema.Number,
|
|
|
+ tokens: Schema.Struct({
|
|
|
+ total: Schema.Number,
|
|
|
+ input: Schema.Number,
|
|
|
+ output: Schema.Number,
|
|
|
+ reasoning: Schema.Number,
|
|
|
+ cache: Schema.Struct({
|
|
|
+ read: Schema.Number,
|
|
|
+ write: Schema.Number,
|
|
|
+ }),
|
|
|
+ }),
|
|
|
+ }) {}
|
|
|
+
|
|
|
+ export const Info = Schema.Union([User, Text])
|
|
|
+ export type Info = Schema.Schema.Type<typeof Info>
|
|
|
+}
|