diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index e2f456997..3a92cbeae 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -230,8 +230,7 @@ export namespace Session { info: MessageV2.Info parts: MessageV2.Part[] }[] - const list = Storage.list("session/message/" + sessionID) - for await (const p of list) { + for (const p of await Storage.list("session/message/" + sessionID)) { const read = await Storage.readJSON(p) result.push({ info: read, @@ -248,7 +247,7 @@ export namespace Session { export async function parts(sessionID: string, messageID: string) { const result = [] as MessageV2.Part[] - for await (const item of Storage.list("session/part/" + sessionID + "/" + messageID)) { + for (const item of await Storage.list("session/part/" + sessionID + "/" + messageID)) { const read = await Storage.readJSON(item) result.push(read) } @@ -257,7 +256,7 @@ export namespace Session { } export async function* list() { - for await (const item of Storage.list("session/info")) { + for (const item of await Storage.list("session/info")) { const sessionID = path.basename(item, ".json") yield get(sessionID) } @@ -265,7 +264,7 @@ export namespace Session { export async function children(parentID: string) { const result = [] as Session.Info[] - for await (const item of Storage.list("session/info")) { + for (const item of await Storage.list("session/info")) { const sessionID = path.basename(item, ".json") const session = await get(sessionID) if (session.parentID !== parentID) continue diff --git a/packages/opencode/src/storage/storage.ts b/packages/opencode/src/storage/storage.ts index 22876ee40..442ce82b0 100644 --- a/packages/opencode/src/storage/storage.ts +++ b/packages/opencode/src/storage/storage.ts @@ -121,18 +121,19 @@ export namespace Storage { } const glob = new Bun.Glob("**/*") - export async function* list(prefix: string) { + export async function list(prefix: string) { const dir = await state().then((x) => x.dir) try { - for await (const item of glob.scan({ - cwd: path.join(dir, prefix), - onlyFiles: true, - })) { - const result = path.join(prefix, item.slice(0, -5)) - yield result - } + const result = await Array.fromAsync( + glob.scan({ + cwd: path.join(dir, prefix), + onlyFiles: true, + }), + ) + result.sort() + return result } catch { - return + return [] } } }