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:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user