Add hosted MCP endpoint at POST /mcp for remote agents.
Bearer-auth JSON-RPC exposes engines, generate, and job tools without duplicating the aigen API path. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { jobView } from '~/shared/studio2/queue-view.mjs'
|
||||
import { getJob } from '~/server/utils/jobs'
|
||||
import { readRecord } from '~/server/utils/studio2/store'
|
||||
import { listStudioJobs } from '~/server/utils/studioQueue'
|
||||
import { assertAigenApiAccess } from '~/server/utils/aigenApi'
|
||||
import { publicBaseUrl } from '~/server/utils/session'
|
||||
|
||||
/** Same path as GET /api/aigen/jobs/:id — job state plus optional still URLs. */
|
||||
export function readAigenJob(event: H3Event, idRaw: string, opts?: { absoluteStillUrl?: boolean }) {
|
||||
const { owner } = assertAigenApiAccess(event)
|
||||
const id = String(idRaw || '')
|
||||
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
|
||||
const stillUrl = stillId ? `/api/library/stills/${stillId}` : 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 && stillUrl
|
||||
? {
|
||||
stillId,
|
||||
stillUrl,
|
||||
...(opts?.absoluteStillUrl
|
||||
? { stillAbsoluteUrl: `${publicBaseUrl(event)}${stillUrl}` }
|
||||
: {})
|
||||
}
|
||||
: {})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user