session-load.ts 751 B

12345678910111213141516171819202122232425
  1. import type { RootLoadArgs } from "./types"
  2. export async function loadRootSessionsWithFallback(input: RootLoadArgs) {
  3. try {
  4. const result = await input.list({ directory: input.directory, roots: true, limit: input.limit })
  5. return {
  6. data: result.data,
  7. limit: input.limit,
  8. limited: true,
  9. } as const
  10. } catch {
  11. const result = await input.list({ directory: input.directory, roots: true })
  12. return {
  13. data: result.data,
  14. limit: input.limit,
  15. limited: false,
  16. } as const
  17. }
  18. }
  19. export function estimateRootSessionTotal(input: { count: number; limit: number; limited: boolean }) {
  20. if (!input.limited) return input.count
  21. if (input.count < input.limit) return input.count
  22. return input.count + 1
  23. }