info.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { DateTime } from "effect"
  2. import { AgentV2 } from "../agent"
  3. import { Location } from "../location"
  4. import { ModelV2 } from "../model"
  5. import { ProjectV2 } from "../project"
  6. import { ProviderV2 } from "../provider"
  7. import { AbsolutePath, RelativePath } from "../schema"
  8. import { WorkspaceV2 } from "../workspace"
  9. import { SessionSchema } from "./schema"
  10. import { SessionTable } from "./sql"
  11. import { SessionMessage } from "./message"
  12. import { Snapshot } from "../snapshot"
  13. export function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.Info {
  14. return SessionSchema.Info.make({
  15. id: SessionSchema.ID.make(row.id),
  16. projectID: ProjectV2.ID.make(row.project_id),
  17. title: row.title,
  18. parentID: row.parent_id ? SessionSchema.ID.make(row.parent_id) : undefined,
  19. agent: row.agent ? AgentV2.ID.make(row.agent) : undefined,
  20. model: row.model
  21. ? {
  22. id: ModelV2.ID.make(row.model.id),
  23. providerID: ProviderV2.ID.make(row.model.providerID),
  24. variant: ModelV2.VariantID.make(row.model.variant ?? "default"),
  25. }
  26. : undefined,
  27. cost: row.cost,
  28. tokens: {
  29. input: row.tokens_input,
  30. output: row.tokens_output,
  31. reasoning: row.tokens_reasoning,
  32. cache: {
  33. read: row.tokens_cache_read,
  34. write: row.tokens_cache_write,
  35. },
  36. },
  37. location: Location.Ref.make({
  38. directory: AbsolutePath.make(row.directory),
  39. workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined,
  40. }),
  41. subpath: row.path ? RelativePath.make(row.path) : undefined,
  42. revert: row.revert ? { ...row.revert, messageID: SessionMessage.ID.make(row.revert.messageID) } : undefined,
  43. time: {
  44. created: DateTime.makeUnsafe(row.time_created),
  45. updated: DateTime.makeUnsafe(row.time_updated),
  46. archived: row.time_archived ? DateTime.makeUnsafe(row.time_archived) : undefined,
  47. },
  48. })
  49. }