mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Merge pull request #379 from feat/agent-orchestration into beta
feat(sessions): add permission modes, session goals, ocm session tool and multi-run Resolve the duplicate parseJsonBody added by both #380 and #379 into one helper: #379's result shape and allowEmpty option, with the first validation message as the error and the issues as details. Update the repo-git callers, affected route tests and the internal API docs.
This commit is contained in:
commit
8dec410c63
120 files changed
+10402
-219
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { LaunchMultiRunRequest, MultiRun } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export async function listMultiRuns(repoId: number): Promise<MultiRun[]> {
|
||||
const res = await fetchWrapper<{ runs: MultiRun[] }>(`${API_BASE_URL}/api/multi-runs`, {
|
||||
params: { repoId },
|
||||
})
|
||||
return res.runs
|
||||
}
|
||||
|
||||
export async function launchMultiRun(request: LaunchMultiRunRequest): Promise<MultiRun> {
|
||||
const res = await fetchWrapper<{ run: MultiRun }>(`${API_BASE_URL}/api/multi-runs`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(request),
|
||||
})
|
||||
return res.run
|
||||
}
|
||||
|
||||
export async function discardMultiRunEntry(runId: number, entryId: number): Promise<MultiRun> {
|
||||
const res = await fetchWrapper<{ run: MultiRun }>(
|
||||
`${API_BASE_URL}/api/multi-runs/${encodeURIComponent(runId)}/entries/${encodeURIComponent(entryId)}/discard`,
|
||||
{ method: 'POST' },
|
||||
)
|
||||
return res.run
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { getOpenCodeConfigModel, getProviders, getProvidersWithModels, providerCredentialsApi } from './providers'
|
||||
import { getOpenCodeConfigModel, getProviders, getProvidersWithModels, providerCredentialsApi, providerModelRef } from './providers'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { makeOpenCodeConfigFile } from '@/test/fixtures/opencode-config'
|
||||
|
||||
@@ -323,6 +323,18 @@ describe('getProvidersWithModels', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('providerModelRef', () => {
|
||||
it('prefers the catalog key over the backing model id', () => {
|
||||
expect(providerModelRef({ id: 'anthropic' }, { id: 'claude-sonnet-4-20250514', key: 'claude-sonnet-4' })).toBe(
|
||||
'anthropic/claude-sonnet-4'
|
||||
)
|
||||
})
|
||||
|
||||
it('falls back to the model id when no key is present', () => {
|
||||
expect(providerModelRef({ id: 'openai' }, { id: 'gpt-4o' })).toBe('openai/gpt-4o')
|
||||
})
|
||||
})
|
||||
|
||||
describe('providerCredentialsApi', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
@@ -284,6 +284,10 @@ export function formatModelName(model: Model): string {
|
||||
return model.name || model.id;
|
||||
}
|
||||
|
||||
export function providerModelRef(provider: { id: string }, model: { id: string; key?: string }): string {
|
||||
return `${provider.id}/${model.key ?? model.id}`;
|
||||
}
|
||||
|
||||
export function formatProviderName(
|
||||
provider: Provider | ProviderWithModels,
|
||||
): string {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { SessionGoal, StartSessionGoalRequest } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export async function getLatestSessionGoal(sessionId: string): Promise<SessionGoal | null> {
|
||||
const res = await fetchWrapper<{ goal: SessionGoal | null }>(`${API_BASE_URL}/api/session-goals`, {
|
||||
params: { sessionId },
|
||||
})
|
||||
return res.goal
|
||||
}
|
||||
|
||||
export async function startSessionGoal(input: StartSessionGoalRequest): Promise<SessionGoal> {
|
||||
const res = await fetchWrapper<{ goal: SessionGoal }>(`${API_BASE_URL}/api/session-goals`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
})
|
||||
return res.goal
|
||||
}
|
||||
|
||||
async function runGoalAction(id: number, action: 'pause' | 'resume' | 'cancel'): Promise<SessionGoal> {
|
||||
const res = await fetchWrapper<{ goal: SessionGoal }>(
|
||||
`${API_BASE_URL}/api/session-goals/${encodeURIComponent(id)}/${action}`,
|
||||
{ method: 'POST' },
|
||||
)
|
||||
return res.goal
|
||||
}
|
||||
|
||||
export function pauseSessionGoal(id: number): Promise<SessionGoal> {
|
||||
return runGoalAction(id, 'pause')
|
||||
}
|
||||
|
||||
export function resumeSessionGoal(id: number): Promise<SessionGoal> {
|
||||
return runGoalAction(id, 'resume')
|
||||
}
|
||||
|
||||
export function cancelSessionGoal(id: number): Promise<SessionGoal> {
|
||||
return runGoalAction(id, 'cancel')
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { getSessionPermissionMode, setSessionPermissionMode } from './sessionPermissionModes'
|
||||
|
||||
describe('sessionPermissionModes', () => {
|
||||
const fetchMock = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset()
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('calls GET /api/session-permission-modes/:id and returns the state', async () => {
|
||||
const state = { sessionId: 'ses_1', rootSessionId: 'ses_1', mode: 'ask', lockedReason: null }
|
||||
fetchMock.mockResolvedValue(new Response(JSON.stringify(state), { status: 200 }))
|
||||
|
||||
const result = await getSessionPermissionMode('ses_1')
|
||||
|
||||
expect(result).toEqual(state)
|
||||
expect(fetchMock.mock.calls[0][0]).toEqual(expect.stringContaining('/api/session-permission-modes/ses_1'))
|
||||
expect(fetchMock.mock.calls[0][1].method).toBeUndefined()
|
||||
})
|
||||
|
||||
it('calls PUT /api/session-permission-modes/:id with the mode and directory', async () => {
|
||||
const input = { directory: '/repo', mode: 'auto' as const }
|
||||
const state = { sessionId: 'ses_1', rootSessionId: 'ses_1', mode: 'auto' as const, lockedReason: null }
|
||||
fetchMock.mockResolvedValue(new Response(JSON.stringify(state), { status: 200 }))
|
||||
|
||||
const result = await setSessionPermissionMode('ses_1', input)
|
||||
|
||||
expect(result).toEqual(state)
|
||||
expect(fetchMock.mock.calls[0][0]).toEqual(expect.stringContaining('/api/session-permission-modes/ses_1'))
|
||||
const options = fetchMock.mock.calls[0][1]
|
||||
expect(options.method).toBe('PUT')
|
||||
expect(options.headers['Content-Type']).toBe('application/json')
|
||||
expect(JSON.parse(options.body)).toEqual(input)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { SessionPermissionModeState, SetSessionPermissionModeRequest } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export async function getSessionPermissionMode(sessionId: string): Promise<SessionPermissionModeState> {
|
||||
return fetchWrapper<SessionPermissionModeState>(
|
||||
`${API_BASE_URL}/api/session-permission-modes/${encodeURIComponent(sessionId)}`,
|
||||
)
|
||||
}
|
||||
|
||||
export async function setSessionPermissionMode(
|
||||
sessionId: string,
|
||||
input: SetSessionPermissionModeRequest,
|
||||
): Promise<SessionPermissionModeState> {
|
||||
return fetchWrapper<SessionPermissionModeState>(
|
||||
`${API_BASE_URL}/api/session-permission-modes/${encodeURIComponent(sessionId)}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user