mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(frontend): adapt session list to OpenCode v1.16.0 API response changes (#252)
* fix(frontend): adapt session list to OpenCode v1.16.0 API response changes * fix: support both old and new /api/session response formats
This commit is contained in:
1 parent
ce4fd6e22b
commit
9479e1f662
2 files changed
+85
-4
No files matched your search
@@ -44,6 +44,45 @@ describe('OpenCodeClient', () => {
|
||||
})
|
||||
|
||||
describe('listSessionsPage', () => {
|
||||
it('handles v1.16.0+ API response format with data envelope and nested location', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: [
|
||||
{
|
||||
id: 'ses_v2_1',
|
||||
projectID: 'proj_v2',
|
||||
parentID: 'parent_v2',
|
||||
title: 'V2 Session',
|
||||
time: { created: 3000, updated: 4000 },
|
||||
location: { directory: '/my-repo', workspaceID: 'ws_v2' },
|
||||
agent: 'default',
|
||||
model: { id: 'gpt-4', providerID: 'openai' },
|
||||
cost: 0.05,
|
||||
tokens: { input: 100, output: 50, reasoning: 10, cache: { read: 0, write: 0 } },
|
||||
},
|
||||
],
|
||||
cursor: { next: 'v2_cursor' },
|
||||
}),
|
||||
{ status: 200 },
|
||||
),
|
||||
)
|
||||
|
||||
const result = await new OpenCodeClient('/api/opencode', '/repo').listSessionsPage({ limit: 10 })
|
||||
|
||||
expect(result.items).toHaveLength(1)
|
||||
expect(result.items[0]).toMatchObject({
|
||||
id: 'ses_v2_1',
|
||||
projectID: 'proj_v2',
|
||||
workspaceID: 'ws_v2',
|
||||
directory: '/repo',
|
||||
parentID: 'parent_v2',
|
||||
title: 'V2 Session',
|
||||
version: 'v2',
|
||||
})
|
||||
expect(result.nextCursor).toBe('v2_cursor')
|
||||
})
|
||||
|
||||
it('sends first-page params to /api/session with directory and returns adapted sessions', async () => {
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(
|
||||
|
||||
Reference in new issue
Block a user