File size: 1,865 Bytes
89a2873 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import { Schema } from "effect"
import { optional } from "./schema"
import { statics } from "./schema"
export interface Source extends Schema.Schema.Type<typeof Source> {}
export const Source = Schema.Struct({
start: Schema.Finite,
end: Schema.Finite,
text: Schema.String,
}).annotate({ identifier: "Prompt.Source" })
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
export const FileAttachment = Schema.Struct({
uri: Schema.String,
mime: Schema.String,
name: Schema.String.pipe(optional),
description: Schema.String.pipe(optional),
source: Source.pipe(optional),
})
.annotate({ identifier: "Prompt.FileAttachment" })
.pipe(
statics((schema) => ({
create: (input: FileAttachment) =>
schema.make({
uri: input.uri,
mime: input.mime,
name: input.name,
description: input.description,
source: input.source,
}),
})),
)
export interface AgentAttachment extends Schema.Schema.Type<typeof AgentAttachment> {}
export const AgentAttachment = Schema.Struct({
name: Schema.String,
source: Source.pipe(optional),
}).annotate({ identifier: "Prompt.AgentAttachment" })
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}
export const Prompt = Schema.Struct({
text: Schema.String,
files: Schema.Array(FileAttachment).pipe(optional),
agents: Schema.Array(AgentAttachment).pipe(optional),
})
.annotate({ identifier: "Prompt" })
.pipe(
statics((schema) => ({
equivalence: Schema.toEquivalence(schema),
fromUserMessage: (input: Pick<Prompt, "text" | "files" | "agents">) =>
schema.make({
text: input.text,
...(input.files === undefined ? {} : { files: input.files }),
...(input.agents === undefined ? {} : { agents: input.agents }),
}),
})),
)
|