mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add cron-based scheduling with prompt templates integration (#164)
This commit is contained in:
1 parent
cbd0ee2958
commit
1e863c5fc5
63 files changed
+7797
-64
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import type { paths } from './opencode-types'
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { OPENCODE_API_ENDPOINT } from '@/config'
|
||||
|
||||
type SessionListResponse = paths['/session']['get']['responses']['200']['content']['application/json']
|
||||
type SessionResponse = paths['/session/{sessionID}']['get']['responses']['200']['content']['application/json']
|
||||
@@ -248,3 +250,14 @@ export class OpenCodeClient {
|
||||
export const createOpenCodeClient = (baseURL: string, directory?: string) => {
|
||||
return new OpenCodeClient(baseURL, directory)
|
||||
}
|
||||
|
||||
export const useAgents = () => {
|
||||
return useQuery({
|
||||
queryKey: ['opencode-agents'],
|
||||
queryFn: async () => {
|
||||
const client = createOpenCodeClient(OPENCODE_API_ENDPOINT)
|
||||
return await client.listAgents()
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type {
|
||||
PromptTemplate,
|
||||
CreatePromptTemplateRequest,
|
||||
UpdatePromptTemplateRequest,
|
||||
} from '@opencode-manager/shared/types'
|
||||
|
||||
export async function listPromptTemplates(): Promise<{ templates: PromptTemplate[] }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/prompt-templates`)
|
||||
}
|
||||
|
||||
export async function createPromptTemplate(data: CreatePromptTemplateRequest): Promise<{ template: PromptTemplate }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/prompt-templates`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function updatePromptTemplate(id: number, data: UpdatePromptTemplateRequest): Promise<{ template: PromptTemplate }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/prompt-templates/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deletePromptTemplate(id: number): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/prompt-templates/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type {
|
||||
CreateScheduleJobRequest,
|
||||
ScheduleJob,
|
||||
ScheduleRun,
|
||||
UpdateScheduleJobRequest,
|
||||
} from '@opencode-manager/shared/types'
|
||||
|
||||
export async function listRepoSchedules(repoId: number): Promise<{ jobs: ScheduleJob[] }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules`)
|
||||
}
|
||||
|
||||
export async function getRepoSchedule(repoId: number, jobId: number): Promise<{ job: ScheduleJob }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}`)
|
||||
}
|
||||
|
||||
export async function createRepoSchedule(repoId: number, data: CreateScheduleJobRequest): Promise<{ job: ScheduleJob }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateRepoSchedule(repoId: number, jobId: number, data: UpdateScheduleJobRequest): Promise<{ job: ScheduleJob }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteRepoSchedule(repoId: number, jobId: number): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
|
||||
export async function runRepoSchedule(repoId: number, jobId: number): Promise<{ run: ScheduleRun }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/run`, {
|
||||
method: 'POST',
|
||||
})
|
||||
}
|
||||
|
||||
export async function listRepoScheduleRuns(repoId: number, jobId: number, limit: number = 20): Promise<{ runs: ScheduleRun[] }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs?limit=${limit}`)
|
||||
}
|
||||
|
||||
export async function getRepoScheduleRun(repoId: number, jobId: number, runId: number): Promise<{ run: ScheduleRun }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs/${runId}`)
|
||||
}
|
||||
|
||||
export async function cancelRepoScheduleRun(repoId: number, jobId: number, runId: number): Promise<{ run: ScheduleRun }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/schedules/${jobId}/runs/${runId}/cancel`, {
|
||||
method: 'POST',
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user