prompt.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import * as Schema from "effect/Schema"
  2. export class Source extends Schema.Class<Source>("Prompt.Source")({
  3. start: Schema.Finite,
  4. end: Schema.Finite,
  5. text: Schema.String,
  6. }) {}
  7. export class FileAttachment extends Schema.Class<FileAttachment>("Prompt.FileAttachment")({
  8. uri: Schema.String,
  9. mime: Schema.String,
  10. name: Schema.String.pipe(Schema.optional),
  11. description: Schema.String.pipe(Schema.optional),
  12. source: Source.pipe(Schema.optional),
  13. }) {
  14. static create(input: FileAttachment) {
  15. return new FileAttachment({
  16. uri: input.uri,
  17. mime: input.mime,
  18. name: input.name,
  19. description: input.description,
  20. source: input.source,
  21. })
  22. }
  23. }
  24. export class AgentAttachment extends Schema.Class<AgentAttachment>("Prompt.AgentAttachment")({
  25. name: Schema.String,
  26. source: Source.pipe(Schema.optional),
  27. }) {}
  28. export class ReferenceAttachment extends Schema.Class<ReferenceAttachment>("Prompt.ReferenceAttachment")({
  29. name: Schema.String,
  30. kind: Schema.Literals(["local", "git", "invalid"]),
  31. uri: Schema.String.pipe(Schema.optional),
  32. repository: Schema.String.pipe(Schema.optional),
  33. branch: Schema.String.pipe(Schema.optional),
  34. target: Schema.String.pipe(Schema.optional),
  35. targetUri: Schema.String.pipe(Schema.optional),
  36. problem: Schema.String.pipe(Schema.optional),
  37. source: Source.pipe(Schema.optional),
  38. }) {}
  39. export class Prompt extends Schema.Class<Prompt>("Prompt")({
  40. text: Schema.String,
  41. files: Schema.Array(FileAttachment).pipe(Schema.optional),
  42. agents: Schema.Array(AgentAttachment).pipe(Schema.optional),
  43. references: Schema.Array(ReferenceAttachment).pipe(Schema.optional),
  44. }) {
  45. static readonly equivalence = Schema.toEquivalence(Prompt)
  46. static fromUserMessage(input: Pick<Prompt, "text" | "files" | "agents" | "references">) {
  47. return new Prompt({
  48. text: input.text,
  49. ...(input.files === undefined ? {} : { files: input.files }),
  50. ...(input.agents === undefined ? {} : { agents: input.agents }),
  51. ...(input.references === undefined ? {} : { references: input.references }),
  52. })
  53. }
  54. }