351c861777
- Migrate source to packages/client and packages/server directories - Namespace all Hermes-specific code under hermes/ subdirectories (api/hermes/, components/hermes/, views/hermes/, stores/hermes/) - Add hermes.* route names and /hermes/* path prefixes - Upgrade @koa/router to v15, adapt path-to-regexp v8 syntax - Fix proxy path rewriting: /api/hermes/v1/* → /v1/*, /api/hermes/* → /api/* - Fix frontend API paths to match backend /api/hermes/* routes - Fix WebSocket terminal path to /api/hermes/terminal - Add proxyMiddleware for reliable unmatched route proxying - Add profiles route module and hermes-cli profile commands - Update CLAUDE.md development guide with new architecture - Add Chinese README (README_zh.md) - Add Web Terminal feature to README Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import * as jobsApi from '@/api/hermes/jobs'
|
|
import type { Job, CreateJobRequest, UpdateJobRequest } from '@/api/hermes/jobs'
|
|
|
|
function matchId(job: Job, id: string): boolean {
|
|
return job.job_id === id || job.id === id
|
|
}
|
|
|
|
export const useJobsStore = defineStore('jobs', () => {
|
|
const jobs = ref<Job[]>([])
|
|
const loading = ref(false)
|
|
|
|
async function fetchJobs() {
|
|
loading.value = true
|
|
try {
|
|
jobs.value = await jobsApi.listJobs()
|
|
} catch (err) {
|
|
console.error('Failed to fetch jobs:', err)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
async function createJob(data: CreateJobRequest): Promise<Job> {
|
|
const job = await jobsApi.createJob(data)
|
|
jobs.value.unshift(job)
|
|
return job
|
|
}
|
|
|
|
async function updateJob(jobId: string, data: UpdateJobRequest): Promise<Job> {
|
|
const job = await jobsApi.updateJob(jobId, data)
|
|
const idx = jobs.value.findIndex(j => matchId(j, jobId))
|
|
if (idx !== -1) jobs.value[idx] = job
|
|
return job
|
|
}
|
|
|
|
async function deleteJob(jobId: string) {
|
|
await jobsApi.deleteJob(jobId)
|
|
jobs.value = jobs.value.filter(j => !matchId(j, jobId))
|
|
}
|
|
|
|
async function pauseJob(jobId: string) {
|
|
const job = await jobsApi.pauseJob(jobId)
|
|
const idx = jobs.value.findIndex(j => matchId(j, jobId))
|
|
if (idx !== -1) jobs.value[idx] = job
|
|
}
|
|
|
|
async function resumeJob(jobId: string) {
|
|
const job = await jobsApi.resumeJob(jobId)
|
|
const idx = jobs.value.findIndex(j => matchId(j, jobId))
|
|
if (idx !== -1) jobs.value[idx] = job
|
|
}
|
|
|
|
async function runJob(jobId: string) {
|
|
const job = await jobsApi.runJob(jobId)
|
|
const idx = jobs.value.findIndex(j => matchId(j, jobId))
|
|
if (idx !== -1) jobs.value[idx] = job
|
|
}
|
|
|
|
return {
|
|
jobs,
|
|
loading,
|
|
fetchJobs,
|
|
createJob,
|
|
updateJob,
|
|
deleteJob,
|
|
pauseJob,
|
|
resumeJob,
|
|
runJob,
|
|
}
|
|
})
|