feat(core): resolve prompt attachments

This commit is contained in:
Dax Raad 2026-07-06 15:04:23 -04:00
commit 4d100de194
29 changed files with 610 additions and 426 deletions

View file

@ -2,33 +2,46 @@ import { Schema } from "effect"
import { optional } from "./schema.js"
import { statics } from "./schema.js"
export interface Source extends Schema.Schema.Type<typeof Source> {}
export const Source = Schema.Struct({
export interface PromptMention extends Schema.Schema.Type<typeof PromptMention> {}
export const PromptMention = Schema.Struct({
start: Schema.Finite,
end: Schema.Finite,
text: Schema.String,
}).annotate({ identifier: "Prompt.Source" })
}).annotate({ identifier: "Prompt.Mention" })
export const FileSource = Schema.Union([
Schema.Struct({ type: Schema.Literal("inline") }),
Schema.Struct({ type: Schema.Literal("uri"), uri: Schema.String }),
])
.pipe(Schema.toTaggedUnion("type"))
.annotate({ identifier: "Prompt.FileSource" })
export type FileSource = typeof FileSource.Type
export const Base64 = Schema.String.check(
Schema.isPattern(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/),
).annotate({ identifier: "Prompt.Base64" })
export type Base64 = typeof Base64.Type
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
export const FileAttachment = Schema.Struct({
uri: Schema.String,
data: Base64,
mime: Schema.String,
content: Schema.String.pipe(optional),
source: FileSource,
name: Schema.String.pipe(optional),
description: Schema.String.pipe(optional),
source: Source.pipe(optional),
mention: PromptMention.pipe(optional),
})
.annotate({ identifier: "Prompt.FileAttachment" })
.pipe(
statics((schema) => ({
create: (input: FileAttachment) =>
schema.make({
uri: input.uri,
data: input.data,
mime: input.mime,
content: input.content,
source: input.source,
name: input.name,
description: input.description,
source: input.source,
mention: input.mention,
}),
})),
)
@ -36,7 +49,7 @@ export const FileAttachment = Schema.Struct({
export interface AgentAttachment extends Schema.Schema.Type<typeof AgentAttachment> {}
export const AgentAttachment = Schema.Struct({
name: Schema.String,
source: Source.pipe(optional),
mention: PromptMention.pipe(optional),
}).annotate({ identifier: "Prompt.AgentAttachment" })
export interface Prompt extends Schema.Schema.Type<typeof Prompt> {}