mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
section 13: Phase 13: Session status from the client type, compaction-dr
This commit is contained in:
1 parent
717536c5a6
commit
2d4abe79e1
21 files changed
+194
-100
No files matched your search
@@ -80,6 +80,7 @@ describe('OpenCode facade', () => {
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: 'deploy',
|
||||
parentID: null,
|
||||
})
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
@@ -93,7 +94,7 @@ describe('OpenCode facade', () => {
|
||||
it('passes the directory and cursor for continuation pages', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse({ data: [], cursor: {} }))
|
||||
|
||||
const page = await listSessionPage({ directory: '/repo', cursor: 'cursor_1' })
|
||||
const page = await listSessionPage({ directory: '/repo', cursor: 'cursor_1', parentID: null })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/session?parentID=null&directory=%2Frepo&cursor=cursor_1',
|
||||
@@ -108,7 +109,7 @@ describe('OpenCode facade', () => {
|
||||
jsonResponse({ data: [sessionInfo('ses_1', '/repo')], cursor: { next: 'cursor_next' } }),
|
||||
)
|
||||
|
||||
const page = await listSessionPage({ limit: 25, order: 'desc' })
|
||||
const page = await listSessionPage({ limit: 25, order: 'desc', parentID: null })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/session?limit=25&order=desc&parentID=null',
|
||||
@@ -121,7 +122,7 @@ describe('OpenCode facade', () => {
|
||||
it('omits the directory on an all-directories continuation page', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse({ data: [], cursor: {} }))
|
||||
|
||||
await listSessionPage({ cursor: 'cursor_1' })
|
||||
await listSessionPage({ cursor: 'cursor_1', parentID: null })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/session?parentID=null&cursor=cursor_1',
|
||||
@@ -134,7 +135,7 @@ describe('OpenCode facade', () => {
|
||||
jsonResponse({ data: [sessionInfo('ses_child', '/repo')], cursor: {} }),
|
||||
)
|
||||
|
||||
await listSessionPage({ directory: '/repo', limit: 25, order: 'desc', includeChildren: true })
|
||||
await listSessionPage({ directory: '/repo', limit: 25, order: 'desc' })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/session?limit=25&order=desc&directory=%2Frepo',
|
||||
@@ -313,7 +314,7 @@ describe('OpenCode facade', () => {
|
||||
}),
|
||||
)
|
||||
|
||||
const files = await findFiles({ directory: '/repo', query: 'index', limit: 20 })
|
||||
const files = await findFiles({ location: { directory: '/repo' }, query: 'index', limit: 20 })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/fs/find?location%5Bdirectory%5D=%2Frepo&query=index&type=file&limit=20',
|
||||
@@ -325,7 +326,7 @@ describe('OpenCode facade', () => {
|
||||
it('finds files without a limit when none is given', async () => {
|
||||
fetchMock.mockResolvedValue(jsonResponse({ location: { directory: '/repo' }, data: [] }))
|
||||
|
||||
await findFiles({ directory: '/repo', query: 'index' })
|
||||
await findFiles({ location: { directory: '/repo' }, query: 'index' })
|
||||
|
||||
expect(lastRequest().url).toBe(
|
||||
'http://localhost/api/opencode/api/fs/find?location%5Bdirectory%5D=%2Frepo&query=index&type=file',
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
FormInfo,
|
||||
ModelRef,
|
||||
OpenCodeApi,
|
||||
PermissionReply,
|
||||
PermissionRequest,
|
||||
SessionGoalRead,
|
||||
SessionInboxCompaction,
|
||||
@@ -146,16 +147,7 @@ export interface SessionPage {
|
||||
nextCursor?: string
|
||||
}
|
||||
|
||||
export interface SessionPageInput {
|
||||
directory?: string
|
||||
project?: string
|
||||
subpath?: string
|
||||
limit?: number
|
||||
order?: 'asc' | 'desc'
|
||||
search?: string
|
||||
cursor?: string
|
||||
includeChildren?: boolean
|
||||
}
|
||||
export type SessionPageInput = NonNullable<Parameters<OpenCodeApi['session']['list']>[0]>
|
||||
|
||||
export interface CreateSessionInput {
|
||||
directory: string
|
||||
@@ -164,11 +156,7 @@ export interface CreateSessionInput {
|
||||
model?: string
|
||||
}
|
||||
|
||||
export interface FindFilesInput {
|
||||
directory?: string
|
||||
query: string
|
||||
limit?: number
|
||||
}
|
||||
export type FindFilesInput = Parameters<OpenCodeApi['file']['find']>[0]
|
||||
|
||||
export interface SessionMessagesPage {
|
||||
messages: SessionMessageInfo[]
|
||||
@@ -204,19 +192,7 @@ function buildPromptFields(input: PromptFields) {
|
||||
}
|
||||
|
||||
export async function listSessionPage(input: SessionPageInput, serverId?: string): Promise<SessionPage> {
|
||||
const { data, cursor } = await callOpenCode((api) =>
|
||||
api.session.list({
|
||||
...(input.directory === undefined ? {} : { directory: input.directory }),
|
||||
...(input.project === undefined ? {} : { project: input.project }),
|
||||
...(input.subpath === undefined ? {} : { subpath: input.subpath }),
|
||||
...(input.includeChildren ? {} : { parentID: 'null' }),
|
||||
limit: input.limit,
|
||||
order: input.order,
|
||||
search: input.search,
|
||||
cursor: input.cursor,
|
||||
}),
|
||||
serverId,
|
||||
)
|
||||
const { data, cursor } = await callOpenCode((api) => api.session.list(input), serverId)
|
||||
return { items: data, nextCursor: cursor.next ?? undefined }
|
||||
}
|
||||
|
||||
@@ -546,7 +522,7 @@ export async function listPendingPermissions(
|
||||
export async function replyPermission(
|
||||
sessionID: string,
|
||||
requestID: string,
|
||||
decision: 'once' | 'always' | 'reject',
|
||||
decision: PermissionReply,
|
||||
message?: string,
|
||||
serverId?: string,
|
||||
): Promise<void> {
|
||||
@@ -581,16 +557,7 @@ export async function cancelForm(sessionID: string, formID: string, serverId?: s
|
||||
}
|
||||
|
||||
export async function findFiles(input: FindFilesInput, serverId?: string): Promise<string[]> {
|
||||
const { data } = await callOpenCode(
|
||||
(api) =>
|
||||
api.file.find({
|
||||
...openCodeLocation(input.directory),
|
||||
query: input.query,
|
||||
type: 'file',
|
||||
limit: input.limit,
|
||||
}),
|
||||
serverId,
|
||||
)
|
||||
const { data } = await callOpenCode((api) => api.file.find({ ...input, type: 'file' }), serverId)
|
||||
return data.map((entry) => entry.path)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export interface Repo {
|
||||
}
|
||||
|
||||
export type Session = SessionInfo
|
||||
export type PermissionResponse = 'once' | 'always' | 'reject'
|
||||
|
||||
export interface FileAttachmentInfo {
|
||||
path: string
|
||||
|
||||
Reference in new issue
Block a user