Download packages/app/src/context/global-sync/session-load.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/context/global-sync/session-load.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/context/global-sync/session-load.ts
-
curl -L -o session-load.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/context/global-sync/session-load.ts
1.29 kB
| import type { SessionApi } from "@opencode-ai/client/promise" | |
| import { normalizeSessionInfo } from "@/utils/session" | |
| import type { OpencodeClient } from "@opencode-ai/sdk/v2/client" | |
| export async function loadRootSessions(input: { api: Pick<SessionApi, "list">; directory: string; limit: number }) { | |
| const result = await input.api.list({ | |
| directory: input.directory, | |
| parentID: null, | |
| limit: input.limit, | |
| order: "desc", | |
| }) | |
| return { | |
| data: result.data.map(normalizeSessionInfo), | |
| limit: input.limit, | |
| limited: true, | |
| } as const | |
| } | |
| export async function loadRootSessionsV1(input: { client: OpencodeClient; directory: string; limit: number }) { | |
| try { | |
| const result = await input.client.session.list({ directory: input.directory, roots: true, limit: input.limit }) | |
| return { data: result.data, limit: input.limit, limited: true } as const | |
| } catch { | |
| const result = await input.client.session.list({ directory: input.directory, roots: true }) | |
| return { data: result.data, limit: input.limit, limited: false } as const | |
| } | |
| } | |
| export function estimateRootSessionTotal(input: { count: number; limit: number; limited: boolean }) { | |
| if (!input.limited) return input.count | |
| if (input.count < input.limit) return input.count | |
| return input.count + 1 | |
| } | |