feat: 同步最新生图与身份能力

This commit is contained in:
GouJ committed 2026-09-22 19:56:12 +08:00
1 parent 65e8f9c3ba
commit be06caaa9f
18 files changed
+583 -69

No files matched your search

+36 -25
View File
@@ -1,12 +1,12 @@
import { computed, ref } from 'vue'
import { useQuery } from '../../composables/useQuery'
import { usePolling } from '../../composables/usePolling'
import { ApiError } from '../../lib/http'
import { useProjectContext } from '../projects/context'
import { getOperation, runOperation } from '../workflows/operations'
import { workflowCheckpoints } from '../workflows/selectors'
import { subjectImagesApi } from './api'
import { getImageSession, hasRunningImages } from './model'
import type { GenerateFormImageInput } from './types'
import type { GenerateFormImageInput, SubjectModule } from './types'
/** 形态图库统一读取数据库记录并管理单图/批量长请求,不调用生产流程。 */
export function useSubjectImages() {
@@ -17,28 +17,33 @@ export function useSubjectImages() {
const limit = ref<number | ''>('')
const promptConcurrency = ref(3)
const promptForce = ref(false)
const query = useQuery(id, async (projectId, signal) => {
if (!projectId) return []
try {
const forms = await subjectImagesApi.listForms(projectId, signal)
if (
forms.some(
form =>
form.subject.projectId !== projectId ||
form.images.some(image => image.subjectFormId !== form.id)
const batchModule = ref<'all' | SubjectModule>('all')
const query = usePolling(
id,
async (projectId, signal) => {
if (!projectId) return []
try {
const forms = await subjectImagesApi.listForms(projectId, signal)
if (
forms.some(
form =>
form.subject.projectId !== projectId ||
form.images.some(image => image.subjectFormId !== form.id)
)
)
)
throw new Error('形态图库返回了不匹配的项目或图片,请刷新后重试。')
return forms
} catch (error) {
if (error instanceof ApiError && error.status === 404)
throw new Error(
'后端尚未提供形态图库查询,请更新后端 dev 并重启服务(GET /projects/:id/subject-forms)。',
{ cause: error }
)
throw error
}
})
throw new Error('形态图库返回了不匹配的项目或图片,请刷新后重试。')
return forms
} catch (error) {
if (error instanceof ApiError && error.status === 404)
throw new Error(
'后端尚未提供形态图库查询,请更新后端 dev 并重启服务(GET /projects/:id/subject-forms)。',
{ cause: error }
)
throw error
}
},
false
)
const forms = computed(() => query.data.value ?? [])
const operation = computed(() => getOperation(id.value))
const session = computed(() => getImageSession(id.value))
@@ -87,7 +92,11 @@ export function useSubjectImages() {
async function generatePrompts() {
if (blocked.value || !promptValid.value || !forms.value.length) return
const projectId = id.value
const input = { concurrency: promptConcurrency.value, force: promptForce.value }
const input = {
concurrency: promptConcurrency.value,
force: promptForce.value,
...(batchModule.value === 'all' ? {} : { module: batchModule.value })
}
const target = getImageSession(projectId)
target.promptReceipt = null
await runOperation(projectId, '批量生成形态正式提示词', async () => {
@@ -120,7 +129,8 @@ export function useSubjectImages() {
const input = {
concurrency: concurrency.value,
force: force.value,
...(limit.value === '' ? {} : { limit: limit.value })
...(limit.value === '' ? {} : { limit: limit.value }),
...(batchModule.value === 'all' ? {} : { module: batchModule.value })
}
const target = getImageSession(projectId)
target.receipt = null
@@ -145,6 +155,7 @@ export function useSubjectImages() {
limit,
promptConcurrency,
promptForce,
batchModule,
promptValid,
concurrencyValid,
generatePrompt,