schema.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. export * as SessionSchema from "./schema"
  2. import { Schema } from "effect"
  3. import { Location } from "../location"
  4. import { ModelV2 } from "../model"
  5. import { ProjectV2 } from "../project"
  6. import { externalID, type ExternalID, RelativePath, optionalOmitUndefined, withStatics } from "../schema"
  7. import { Identifier } from "../util/identifier"
  8. import { V2Schema } from "../v2-schema"
  9. import { AgentV2 } from "../agent"
  10. export const ID = Schema.String.check(Schema.isStartsWith("ses")).pipe(
  11. Schema.brand("SessionID"),
  12. withStatics((schema) => {
  13. const create = () => schema.make("ses_" + Identifier.descending())
  14. return {
  15. create,
  16. descending: (id?: string) => (id === undefined ? create() : schema.make(id)),
  17. fromExternal: (input: ExternalID) => schema.make(externalID("ses", input)),
  18. }
  19. }),
  20. )
  21. export type ID = typeof ID.Type
  22. export class Info extends Schema.Class<Info>("SessionV2.Info")({
  23. id: ID,
  24. parentID: ID.pipe(optionalOmitUndefined),
  25. projectID: ProjectV2.ID,
  26. agent: AgentV2.ID.pipe(Schema.optional),
  27. model: ModelV2.Ref.pipe(Schema.optional),
  28. cost: Schema.Finite,
  29. tokens: Schema.Struct({
  30. input: Schema.Finite,
  31. output: Schema.Finite,
  32. reasoning: Schema.Finite,
  33. cache: Schema.Struct({
  34. read: Schema.Finite,
  35. write: Schema.Finite,
  36. }),
  37. }),
  38. time: Schema.Struct({
  39. created: V2Schema.DateTimeUtcFromMillis,
  40. updated: V2Schema.DateTimeUtcFromMillis,
  41. archived: V2Schema.DateTimeUtcFromMillis.pipe(Schema.optional),
  42. }),
  43. title: Schema.String,
  44. location: Location.Ref,
  45. subpath: RelativePath.pipe(Schema.optional),
  46. }) {}