feat(core): resolve prompt attachments
This commit is contained in:
parent
c13f06c30c
commit
4d100de194
29 changed files with 610 additions and 426 deletions
|
|
@ -27,6 +27,6 @@ export { Pty } from "./pty.js"
|
|||
export { PtyTicket } from "./pty-ticket.js"
|
||||
export { Question } from "./question.js"
|
||||
export { Workspace } from "./workspace.js"
|
||||
export { Prompt, Source, FileAttachment, AgentAttachment } from "./prompt.js"
|
||||
export { Prompt, PromptMention, FileSource, FileAttachment, AgentAttachment } from "./prompt.js"
|
||||
export { PromptInput } from "./prompt-input.js"
|
||||
export * from "./schema.js"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export * as PromptInput from "./prompt-input.js"
|
||||
|
||||
import { Schema } from "effect"
|
||||
import { AgentAttachment, Source } from "./prompt.js"
|
||||
import { AgentAttachment, PromptMention } from "./prompt.js"
|
||||
import { optional, statics } from "./schema.js"
|
||||
|
||||
export interface FileAttachment extends Schema.Schema.Type<typeof FileAttachment> {}
|
||||
|
|
@ -9,7 +9,7 @@ export const FileAttachment = Schema.Struct({
|
|||
uri: Schema.String,
|
||||
name: Schema.String.pipe(optional),
|
||||
description: Schema.String.pipe(optional),
|
||||
source: Source.pipe(optional),
|
||||
mention: PromptMention.pipe(optional),
|
||||
})
|
||||
.annotate({ identifier: "PromptInput.FileAttachment" })
|
||||
.pipe(
|
||||
|
|
|
|||
|
|
@ -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> {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue