Add an AIGen-only generate API for external tools.
Cursor and similar clients can enqueue Studio 2 stills with the same steps and CFG the bench uses, through session or AIGEN_API_KEY. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,6 +19,8 @@ COMFY_CONTROL_TOKEN=
|
||||
# COMFY_IDLE_MS=1800000
|
||||
|
||||
NUXT_SESSION_SECRET=change-me
|
||||
# Optional. Bearer token for POST /api/aigen/generate and GET /api/aigen/jobs/:id (AIGen only).
|
||||
# AIGEN_API_KEY=
|
||||
NUXT_PUBLIC_AUTH_ENABLED=true
|
||||
NUXT_OIDC_CLIENT_ID=
|
||||
NUXT_OIDC_CLIENT_SECRET=
|
||||
|
||||
@@ -510,6 +510,7 @@ import {
|
||||
} from '~/shared/studio2/photos.mjs'
|
||||
import {DEFAULT_MUSIC_LYRICS,DEFAULT_MUSIC_TAGS} from '~/utils/music'
|
||||
import {isXaigenStudio} from '~/utils/videoModels'
|
||||
import {studio2EngineDefaults} from '~/shared/studio2/engine-defaults.mjs'
|
||||
import {LOAD_GENERATION_PAYLOAD_KEY} from '~/utils/queuedJob'
|
||||
|
||||
const NEG_STORAGE_KEY='studio2-negative-chips'
|
||||
@@ -521,9 +522,8 @@ let draftTimer:ReturnType<typeof setTimeout>|null=null
|
||||
let restoringDraft=false
|
||||
type EngineLook={steps:number;cfg:number;aspect:string;seed:number|null;seedMode:string;loraStack:any[]}
|
||||
function defaultEngineLook(engine:string):EngineLook{
|
||||
if(engine==='qwen21') return {steps:25,cfg:1,aspect:'auto',seed:null,seedMode:'random',loraStack:[]}
|
||||
if(engine==='moss') return {steps:25,cfg:2.5,aspect:'1:1',seed:null,seedMode:'random',loraStack:[]}
|
||||
return {steps:24,cfg:4,aspect:'auto',seed:null,seedMode:'random',loraStack:[]}
|
||||
const d=studio2EngineDefaults(engine)
|
||||
return {steps:d.steps,cfg:d.cfg,aspect:d.aspect,seed:null,seedMode:'random',loraStack:[]}
|
||||
}
|
||||
/** Plain JSON snapshot only — never structuredClone Vue proxies / Files. */
|
||||
function plainJson<T>(value:unknown, fallback:T):T{
|
||||
@@ -872,10 +872,13 @@ const engineOptions=computed(()=>{
|
||||
]
|
||||
})
|
||||
function defaultSamplingFor(engine:string){
|
||||
if(engine==='qwen21') return {steps:form.turbo?6:25,cfg:1}
|
||||
if(engine==='moss') return {steps:25,cfg:2.5}
|
||||
if(engine==='qwen21'){
|
||||
const d=studio2EngineDefaults('qwen21')
|
||||
return {steps:form.turbo?6:d.steps,cfg:d.cfg}
|
||||
}
|
||||
if(engine==='moss') return studio2EngineDefaults('moss')
|
||||
if(engine==='minimax' || engine==='ltx') return {steps:8,cfg:1.5}
|
||||
return {steps:24,cfg:4}
|
||||
return studio2EngineDefaults(engine==='krea'?'krea':'flux')
|
||||
}
|
||||
function rememberEngineSampling(engine:string){
|
||||
if(!['flux','krea','qwen21','moss'].includes(engine)) return
|
||||
|
||||
@@ -60,6 +60,7 @@ export default defineNuxtConfig({
|
||||
comfyFilenamePrefix: process.env.COMFY_FILENAME_PREFIX || 'video/MiniMax_H3',
|
||||
comfyAudioPrefix: process.env.COMFY_AUDIO_PREFIX || 'audio/AIGen',
|
||||
kreaConceptLora: process.env.NUXT_KREA_CONCEPT_LORA || '',
|
||||
aigenApiKey: process.env.AIGEN_API_KEY || '',
|
||||
public: {
|
||||
authEnabled: process.env.NUXT_PUBLIC_AUTH_ENABLED === 'true',
|
||||
authMode: process.env.NUXT_PUBLIC_AUTH_MODE || process.env.AUTH_MODE || '',
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import { filterLoraStackForUse } from '~/utils/loras'
|
||||
import { validateRequest } from '~/shared/studio2/contracts.mjs'
|
||||
import { defaultLibraryFolderId, isStudio2ImageEngine, studio2EngineDefaults } from '~/shared/studio2/engine-defaults.mjs'
|
||||
import { resolveRequestSize } from '../../utils/studio2/size'
|
||||
import { parsePostedLoraStack, assertImageV2LoraStack } from '../../utils/loras'
|
||||
import { saveRecord, readRecord } from '../../utils/studio2/store'
|
||||
import { addStudioJob, kickStudioQueue, type StudioJobPayload } from '../../utils/studioQueue'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
import { assertAigenApiAccess } from '~/server/utils/aigenApi'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { owner, catalog } = assertAigenApiAccess(event)
|
||||
const rawBody = await readBody(event).catch(() => ({}))
|
||||
const body = rawBody && typeof rawBody === 'object' ? rawBody as Record<string, unknown> : {}
|
||||
|
||||
const prompt = String(body.prompt || '').trim()
|
||||
if (!prompt) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'A prompt is required' })
|
||||
}
|
||||
|
||||
const engine = String(body.engine || 'flux').trim().toLowerCase() || 'flux'
|
||||
if (!isStudio2ImageEngine(engine)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'engine must be flux, krea, qwen21, or moss' })
|
||||
}
|
||||
|
||||
const mode = String(body.mode || 'generate').trim().toLowerCase() || 'generate'
|
||||
if (mode !== 'generate') {
|
||||
throw createError({ statusCode: 400, statusMessage: 'mode must be generate' })
|
||||
}
|
||||
|
||||
const defaults = studio2EngineDefaults(engine)
|
||||
const steps = body.steps == null || body.steps === ''
|
||||
? defaults.steps
|
||||
: Number(body.steps)
|
||||
const cfg = body.cfg == null || body.cfg === ''
|
||||
? defaults.cfg
|
||||
: Number(body.cfg)
|
||||
if (!Number.isFinite(steps) || !Number.isInteger(steps)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'steps must be an integer' })
|
||||
}
|
||||
if (!Number.isFinite(cfg)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'cfg must be a number' })
|
||||
}
|
||||
|
||||
const aspect = String(body.aspect || defaults.aspect || 'auto').trim() || defaults.aspect
|
||||
const folderId = defaultLibraryFolderId(catalog, body.folderId == null ? '' : String(body.folderId))
|
||||
if (!folderId) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Create a library folder before generating' })
|
||||
}
|
||||
|
||||
const seedRaw = body.seed
|
||||
const seedSet = seedRaw != null && String(seedRaw) !== ''
|
||||
const seed = seedSet ? Number(seedRaw) : null
|
||||
if (seedSet && !Number.isFinite(seed)) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'seed must be a number' })
|
||||
}
|
||||
|
||||
const xaigen = isXaigenStudio()
|
||||
const requestRaw = {
|
||||
mode: 'generate',
|
||||
engine,
|
||||
folderId,
|
||||
promptSections: { action: prompt },
|
||||
settings: {
|
||||
aspect,
|
||||
steps,
|
||||
cfg,
|
||||
seed,
|
||||
seedMode: seedSet ? 'locked' : 'random',
|
||||
loraStack: []
|
||||
}
|
||||
}
|
||||
|
||||
let request: any
|
||||
try {
|
||||
request = validateRequest(requestRaw, xaigen)
|
||||
} catch (e: any) {
|
||||
throw createError({ statusCode: e.statusCode || 400, statusMessage: e.message })
|
||||
}
|
||||
|
||||
request.settings.loraStack = parsePostedLoraStack(request.settings.loraStack, 'image')
|
||||
request.settings.loraStack = filterLoraStackForUse(request.settings.loraStack, request.engine, xaigen)
|
||||
if (request.engine !== 'qwen21') assertImageV2LoraStack(request.settings.loraStack, request.engine)
|
||||
assertFolderAccess(event, request.folderId)
|
||||
try {
|
||||
await resolveRequestSize(owner, request)
|
||||
} catch (e: any) {
|
||||
const message = e?.statusMessage || e?.message || 'Could not resolve size'
|
||||
throw createError({
|
||||
statusCode: e?.statusCode || 400,
|
||||
statusMessage: message
|
||||
})
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID()
|
||||
const record = {
|
||||
id,
|
||||
owner,
|
||||
request,
|
||||
state: 'waiting',
|
||||
queuedAt: Date.now(),
|
||||
familyId: crypto.randomUUID(),
|
||||
outputs: [],
|
||||
purgeResult: 'Not yet saved'
|
||||
}
|
||||
saveRecord(record)
|
||||
void (async () => {
|
||||
try {
|
||||
const row = await addStudioJob({
|
||||
ownerKey: owner,
|
||||
kind: 'edit',
|
||||
familyId: record.familyId,
|
||||
payload: {
|
||||
...request.settings,
|
||||
engine: request.engine,
|
||||
studio2Id: id,
|
||||
studio2Request: structuredClone(request),
|
||||
prompt: request.compiledPrompt,
|
||||
folderId: request.folderId,
|
||||
extensions: [],
|
||||
referenceStillIds: [],
|
||||
useIdentityRefs: false,
|
||||
queueAutoRun: true
|
||||
} as StudioJobPayload
|
||||
})
|
||||
saveRecord({ ...readRecord(owner, id), queueId: row.id })
|
||||
} catch { /* poll / resume will pick up waiting studio2 records */ }
|
||||
kickStudioQueue()
|
||||
})()
|
||||
|
||||
return {
|
||||
id,
|
||||
engine: request.engine,
|
||||
steps: request.settings.steps,
|
||||
cfg: request.settings.cfg,
|
||||
aspect: request.settings.aspect,
|
||||
folderId: request.folderId,
|
||||
status: 'waiting' as const
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { jobView } from '~/shared/studio2/queue-view.mjs'
|
||||
import { getJob } from '../../../utils/jobs'
|
||||
import { readRecord } from '../../../utils/studio2/store'
|
||||
import { listStudioJobs } from '../../../utils/studioQueue'
|
||||
import { assertAigenApiAccess } from '~/server/utils/aigenApi'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const { owner } = assertAigenApiAccess(event)
|
||||
const id = String(getRouterParam(event, 'id') || '')
|
||||
let record: any
|
||||
try {
|
||||
record = readRecord(owner, id)
|
||||
} catch (e: any) {
|
||||
throw createError({
|
||||
statusCode: e?.statusCode || 404,
|
||||
statusMessage: e?.statusMessage || 'Job not found'
|
||||
})
|
||||
}
|
||||
|
||||
const queue = listStudioJobs(owner).find(row => row.id === record.queueId)
|
||||
const live = record.liveId ? getJob(record.liveId) : null
|
||||
const view = jobView(record, queue, live)
|
||||
const still = (record.outputs || []).find((item: any) => item?.id && item.kind !== 'clip' && item.kind !== 'track')
|
||||
|| (record.outputs || []).find((item: any) => item?.id)
|
||||
const stillId = still?.id ? String(still.id) : undefined
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
state: view.state,
|
||||
engine: record.request?.engine || '',
|
||||
steps: record.request?.settings?.steps,
|
||||
cfg: record.request?.settings?.cfg,
|
||||
...(view.error ? { error: view.error } : {}),
|
||||
...(stillId ? { stillId, stillUrl: `/api/library/stills/${stillId}` } : {})
|
||||
}
|
||||
})
|
||||
@@ -1,3 +1,6 @@
|
||||
import { aigenApiPathAllowed, aigenBearerAuthorized } from '~/server/utils/aigenApiAuth'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
if (!authEnabled()) return
|
||||
const path = getRequestURL(event).pathname
|
||||
@@ -15,6 +18,10 @@ export default defineEventHandler((event) => {
|
||||
) {
|
||||
return
|
||||
}
|
||||
const method = String(event.method || getMethod(event) || 'GET').toUpperCase()
|
||||
if (!isXaigenStudio() && aigenApiPathAllowed(path, method) && aigenBearerAuthorized(event)) {
|
||||
return
|
||||
}
|
||||
const user = getSessionUser(event)
|
||||
if (user) return
|
||||
if (path.startsWith('/api/')) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { assertLibraryOwner } from '~/server/utils/library'
|
||||
import {
|
||||
aigenBearerAuthorized,
|
||||
aigenInstanceOwnerKey,
|
||||
assertAigenFeature
|
||||
} from '~/server/utils/aigenApiAuth'
|
||||
|
||||
export {
|
||||
aigenApiKeyConfigured,
|
||||
aigenApiPathAllowed,
|
||||
aigenBearerAuthorized,
|
||||
aigenInstanceOwnerKey,
|
||||
assertAigenFeature
|
||||
} from '~/server/utils/aigenApiAuth'
|
||||
export { defaultLibraryFolderId as defaultAigenFolderId } from '~/shared/studio2/engine-defaults.mjs'
|
||||
|
||||
/**
|
||||
* Session (assertLibraryOwner) or Authorization: Bearer <AIGEN_API_KEY>.
|
||||
* Bearer runs as the instance library owner. xAIGen is 404.
|
||||
*/
|
||||
export function assertAigenApiAccess(event: H3Event) {
|
||||
assertAigenFeature()
|
||||
if (aigenBearerAuthorized(event)) {
|
||||
// libraryOwnerKey already maps this bearer to aigenInstanceOwnerKey()
|
||||
const { owner, catalog } = assertLibraryOwner(event)
|
||||
return { owner, catalog, auth: 'bearer' as const, instanceOwner: aigenInstanceOwnerKey() }
|
||||
}
|
||||
try {
|
||||
const { owner, catalog } = assertLibraryOwner(event)
|
||||
return { owner, catalog, auth: 'session' as const }
|
||||
} catch (e: any) {
|
||||
if (Number(e?.statusCode) === 401) {
|
||||
throw createError({ statusCode: 401, statusMessage: 'Authentication required' })
|
||||
}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { createHash, timingSafeEqual } from 'node:crypto'
|
||||
import type { H3Event } from 'h3'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
import { passwordAuthEnabled, privateInstanceId } from '~/server/utils/localAuth'
|
||||
|
||||
function configuredApiKey() {
|
||||
const config = useRuntimeConfig()
|
||||
return String((config as { aigenApiKey?: string }).aigenApiKey || process.env.AIGEN_API_KEY || '').trim()
|
||||
}
|
||||
|
||||
function safeEqual(left: string, right: string) {
|
||||
const a = Buffer.from(left)
|
||||
const b = Buffer.from(right)
|
||||
if (a.length !== b.length) return false
|
||||
try {
|
||||
return timingSafeEqual(a, b)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Owner key for bearer calls — same catalog as a no-session / password instance. */
|
||||
export function aigenInstanceOwnerKey() {
|
||||
if (passwordAuthEnabled()) return privateInstanceId()
|
||||
return createHash('sha256').update('local').digest('hex').slice(0, 24)
|
||||
}
|
||||
|
||||
export function aigenApiKeyConfigured() {
|
||||
return Boolean(configuredApiKey())
|
||||
}
|
||||
|
||||
export function aigenBearerAuthorized(event: H3Event) {
|
||||
if (isXaigenStudio()) return false
|
||||
const expected = configuredApiKey()
|
||||
if (!expected) return false
|
||||
const header = String(getHeader(event, 'authorization') || '')
|
||||
const match = header.match(/^Bearer\s+(.+)$/i)
|
||||
if (!match) return false
|
||||
return safeEqual(match[1].trim(), expected)
|
||||
}
|
||||
|
||||
export function aigenApiPathAllowed(path: string, method: string) {
|
||||
if (path === '/api/aigen' || path.startsWith('/api/aigen/')) return true
|
||||
if (method === 'GET' && (path === '/api/library/stills' || path.startsWith('/api/library/stills/'))) return true
|
||||
return false
|
||||
}
|
||||
|
||||
export function assertAigenFeature() {
|
||||
if (isXaigenStudio()) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'Not found' })
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from '~/utils/keepPrompts'
|
||||
import { familyBaseName, nextClipPartName, clipPartLabel } from '~/utils/libraryBrowse'
|
||||
import { musicExtension } from '~/utils/music'
|
||||
import { aigenBearerAuthorized, aigenInstanceOwnerKey } from '~/server/utils/aigenApiAuth'
|
||||
|
||||
export { familyBaseName, nextClipPartName, clipPartLabel }
|
||||
|
||||
@@ -197,6 +198,8 @@ export function libraryRoot() {
|
||||
|
||||
export function libraryOwnerKey(event: H3Event) {
|
||||
if (passwordAuthEnabled()) return privateInstanceId()
|
||||
// AIGen API key: same catalog as the unauthenticated local owner. Never invent a second tree.
|
||||
if (aigenBearerAuthorized(event)) return aigenInstanceOwnerKey()
|
||||
const user = getSessionUser(event)
|
||||
const raw = user?.sub || user?.email || (!authEnabled() ? 'local' : '')
|
||||
if (!raw) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { sectionsFrom, compileSections } from './prompt.mjs'
|
||||
import { QWEN21_ASPECT_IDS, resolveQwen21Size } from './qwen21-size.mjs'
|
||||
import { QWEN21_TURBO_CFG, QWEN21_TURBO_LORA, QWEN21_TURBO_SIGMAS, QWEN21_TURBO_STEPS } from './qwen21-turbo.mjs'
|
||||
import { applyPhotosToRequest } from './photos.mjs'
|
||||
import { studio2EngineDefaults } from './engine-defaults.mjs'
|
||||
export { sectionsFrom } from './prompt.mjs'
|
||||
export const cameraFamilies = ['static','dolly in','dolly out','pan left','pan right','tilt up','tilt down','zoom in','zoom out','orbit left','orbit right']
|
||||
export const identityLock = '<Picture 1> / hero is identity for face, hair, glasses, body, and wardrobe. Keep the person and clothes fully preserved. Start frame is composition, pose, place, and camera only. Do not copy facial drift from the start frame.'
|
||||
@@ -56,9 +57,14 @@ export function validateRequest(raw, xaigen = false) {
|
||||
const number=(key, fallback, min, max) => { const n=Number(raw.settings?.[key] ?? fallback); if (!Number.isFinite(n)||n<min||n>max) fail(`Invalid ${key}.`); return n }
|
||||
const qwen = engine === 'qwen21'
|
||||
const moss = engine === 'moss'
|
||||
const defaultSteps = video ? 8 : qwen || moss ? 25 : 24
|
||||
const defaultCfg = video ? 1.5 : qwen ? 1 : moss ? 2.5 : 4
|
||||
const aspect = QWEN21_ASPECT_IDS.has(raw.settings?.aspect) ? raw.settings.aspect : 'auto'
|
||||
const imageDefaults = studio2EngineDefaults(engine)
|
||||
const defaultSteps = video ? 8 : imageDefaults.steps
|
||||
const defaultCfg = video ? 1.5 : imageDefaults.cfg
|
||||
const requestedAspect = raw.settings?.aspect == null || raw.settings?.aspect === ''
|
||||
? imageDefaults.aspect
|
||||
: raw.settings.aspect
|
||||
const aspect = QWEN21_ASPECT_IDS.has(requestedAspect) ? requestedAspect : 'auto'
|
||||
|
||||
const qwenSize = qwen && mode === 'generate' ? resolveQwen21Size(aspect) : null
|
||||
const defaultWidth = qwenSize ? qwenSize.width : qwen || moss ? 1024 : 1344
|
||||
const defaultHeight = qwenSize ? qwenSize.height : qwen || moss ? 1024 : 768
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/** Recommended Studio 2 image Generate steps / CFG / aspect. Bench and /api/aigen share this. */
|
||||
export const STUDIO2_IMAGE_ENGINES = ['flux', 'krea', 'qwen21', 'moss']
|
||||
|
||||
export function studio2EngineDefaults(engine) {
|
||||
const id = String(engine || 'flux').trim().toLowerCase()
|
||||
if (id === 'qwen21') return { steps: 25, cfg: 1, aspect: 'auto' }
|
||||
if (id === 'moss') return { steps: 25, cfg: 2.5, aspect: '1:1' }
|
||||
return { steps: 24, cfg: 4, aspect: 'auto' }
|
||||
}
|
||||
|
||||
export function isStudio2ImageEngine(engine) {
|
||||
return STUDIO2_IMAGE_ENGINES.includes(String(engine || '').trim().toLowerCase())
|
||||
}
|
||||
|
||||
/** Inbox when present, otherwise the first folder. */
|
||||
export function defaultLibraryFolderId(catalog, requested) {
|
||||
const folders = catalog?.folders || []
|
||||
const want = String(requested || '').trim()
|
||||
if (want && folders.some(folder => folder.id === want)) return want
|
||||
const inbox = folders.find(folder => folder.id === 'inbox' || /^inbox$/i.test(String(folder.name || '')))
|
||||
return inbox?.id || folders[0]?.id || ''
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { dirname, join } from 'node:path'
|
||||
import {
|
||||
defaultLibraryFolderId,
|
||||
isStudio2ImageEngine,
|
||||
studio2EngineDefaults,
|
||||
STUDIO2_IMAGE_ENGINES
|
||||
} from '../shared/studio2/engine-defaults.mjs'
|
||||
import { validateRequest } from '../shared/studio2/contracts.mjs'
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
|
||||
test('studio2EngineDefaults match the recommended Generate values', () => {
|
||||
assert.deepEqual(studio2EngineDefaults('flux'), { steps: 24, cfg: 4, aspect: 'auto' })
|
||||
assert.deepEqual(studio2EngineDefaults('krea'), { steps: 24, cfg: 4, aspect: 'auto' })
|
||||
assert.deepEqual(studio2EngineDefaults('qwen21'), { steps: 25, cfg: 1, aspect: 'auto' })
|
||||
assert.deepEqual(studio2EngineDefaults('moss'), { steps: 25, cfg: 2.5, aspect: '1:1' })
|
||||
assert.deepEqual(STUDIO2_IMAGE_ENGINES, ['flux', 'krea', 'qwen21', 'moss'])
|
||||
assert.equal(isStudio2ImageEngine('krea'), true)
|
||||
assert.equal(isStudio2ImageEngine('ltx'), false)
|
||||
})
|
||||
|
||||
test('aigen generate request validates like Studio 2 with recommended krea steps/cfg', () => {
|
||||
const defaults = studio2EngineDefaults('krea')
|
||||
const request = validateRequest({
|
||||
mode: 'generate',
|
||||
engine: 'krea',
|
||||
folderId: 'inbox',
|
||||
promptSections: { action: 'a red chair' },
|
||||
settings: {
|
||||
aspect: defaults.aspect,
|
||||
steps: defaults.steps,
|
||||
cfg: defaults.cfg,
|
||||
seed: null,
|
||||
seedMode: 'random',
|
||||
loraStack: []
|
||||
}
|
||||
}, false)
|
||||
assert.equal(request.engine, 'krea')
|
||||
assert.equal(request.mode, 'generate')
|
||||
assert.equal(request.settings.steps, 24)
|
||||
assert.equal(request.settings.cfg, 4)
|
||||
assert.equal(request.folderId, 'inbox')
|
||||
assert.match(request.compiledPrompt, /a red chair/)
|
||||
})
|
||||
|
||||
test('aigen routes exist, stay on the studio-2 enqueue path, and 404 on xAIGen', () => {
|
||||
const generate = readFileSync(join(root, 'server/api/aigen/generate.post.ts'), 'utf8')
|
||||
const job = readFileSync(join(root, 'server/api/aigen/jobs/[id].get.ts'), 'utf8')
|
||||
const auth = readFileSync(join(root, 'server/utils/aigenApi.ts'), 'utf8')
|
||||
const middleware = readFileSync(join(root, 'server/middleware/auth.ts'), 'utf8')
|
||||
const nuxt = readFileSync(join(root, 'nuxt.config.ts'), 'utf8')
|
||||
const bench = readFileSync(join(root, 'components/studio2/Bench.vue'), 'utf8')
|
||||
|
||||
assert.match(generate, /assertAigenApiAccess/)
|
||||
assert.match(generate, /validateRequest/)
|
||||
assert.match(generate, /addStudioJob/)
|
||||
assert.match(generate, /studio2EngineDefaults/)
|
||||
assert.match(generate, /status:\s*'waiting'/)
|
||||
assert.match(generate, /isStudio2ImageEngine/)
|
||||
assert.doesNotMatch(generate, /isXaigenStudio\(\)[\s\S]*return[\s\S]*404/)
|
||||
assert.match(auth, /assertAigenFeature/)
|
||||
assert.match(job, /stillUrl/)
|
||||
assert.match(job, /stillId/)
|
||||
assert.match(middleware, /aigenBearerAuthorized/)
|
||||
assert.match(middleware, /aigenApiPathAllowed/)
|
||||
assert.match(nuxt, /aigenApiKey:\s*process\.env\.AIGEN_API_KEY/)
|
||||
assert.match(bench, /studio2EngineDefaults/)
|
||||
assert.match(generate, /assertAigenApiAccess/)
|
||||
})
|
||||
|
||||
test('defaultLibraryFolderId prefers Inbox then the first folder', () => {
|
||||
assert.equal(defaultLibraryFolderId({ folders: [{ id: 'inbox', name: 'Inbox' }, { id: 'b', name: 'B' }] }), 'inbox')
|
||||
assert.equal(defaultLibraryFolderId({ folders: [{ id: 'a', name: 'Alpha' }] }), 'a')
|
||||
assert.equal(defaultLibraryFolderId({ folders: [{ id: 'inbox', name: 'Inbox' }, { id: 'b', name: 'B' }] }, 'b'), 'b')
|
||||
assert.equal(defaultLibraryFolderId({ folders: [{ id: 'x', name: 'Inbox' }] }), 'x')
|
||||
})
|
||||
Reference in New Issue
Block a user