chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
import { z } from 'zod'
|
||||
import { AWS_REGION_PATTERN, toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
import { FileInputSchema, RawFileInputSchema } from '@/lib/uploads/utils/file-schemas'
|
||||
|
||||
const textractQuerySchema = z.object({
|
||||
Text: z.string().min(1),
|
||||
Alias: z.string().optional(),
|
||||
Pages: z.array(z.string()).optional(),
|
||||
})
|
||||
|
||||
export const textractParseBodySchema = z
|
||||
.object({
|
||||
accessKeyId: z.string().min(1, 'AWS Access Key ID is required'),
|
||||
secretAccessKey: z.string().min(1, 'AWS Secret Access Key is required'),
|
||||
region: z
|
||||
.string()
|
||||
.min(1, 'AWS region is required')
|
||||
.regex(
|
||||
AWS_REGION_PATTERN,
|
||||
'AWS region must be a valid AWS region (e.g., us-east-1, eu-west-2, us-gov-west-1)'
|
||||
),
|
||||
processingMode: z.enum(['sync', 'async']).optional().default('sync'),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
s3Uri: z.string().optional(),
|
||||
featureTypes: z
|
||||
.array(z.enum(['TABLES', 'FORMS', 'QUERIES', 'SIGNATURES', 'LAYOUT']))
|
||||
.optional(),
|
||||
queries: z.array(textractQuerySchema).optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.processingMode === 'async' && !data.s3Uri) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'S3 URI is required for multi-page processing (s3://bucket/key)',
|
||||
path: ['s3Uri'],
|
||||
})
|
||||
}
|
||||
if (data.processingMode !== 'async' && !data.file && !data.filePath) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'File input is required for single-page processing',
|
||||
path: ['filePath'],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const textractAnalyzeExpenseBodySchema = z
|
||||
.object({
|
||||
accessKeyId: z.string().min(1, 'AWS Access Key ID is required'),
|
||||
secretAccessKey: z.string().min(1, 'AWS Secret Access Key is required'),
|
||||
region: z
|
||||
.string()
|
||||
.min(1, 'AWS region is required')
|
||||
.regex(
|
||||
AWS_REGION_PATTERN,
|
||||
'AWS region must be a valid AWS region (e.g., us-east-1, eu-west-2, us-gov-west-1)'
|
||||
),
|
||||
processingMode: z.enum(['sync', 'async']).optional().default('sync'),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
s3Uri: z.string().optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.processingMode === 'async' && !data.s3Uri) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'S3 URI is required for multi-page processing (s3://bucket/key)',
|
||||
path: ['s3Uri'],
|
||||
})
|
||||
}
|
||||
if (data.processingMode !== 'async' && !data.file && !data.filePath) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Document input is required for single-page processing',
|
||||
path: ['filePath'],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const textractAnalyzeIdBodySchema = z
|
||||
.object({
|
||||
accessKeyId: z.string().min(1, 'AWS Access Key ID is required'),
|
||||
secretAccessKey: z.string().min(1, 'AWS Secret Access Key is required'),
|
||||
region: z
|
||||
.string()
|
||||
.min(1, 'AWS region is required')
|
||||
.regex(
|
||||
AWS_REGION_PATTERN,
|
||||
'AWS region must be a valid AWS region (e.g., us-east-1, eu-west-2, us-gov-west-1)'
|
||||
),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
filePathBack: z.string().optional(),
|
||||
fileBack: RawFileInputSchema.optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (!data.file && !data.filePath) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Identity document is required',
|
||||
path: ['filePath'],
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
export const reductoParseBodySchema = z.object({
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
pages: z.array(z.number()).optional(),
|
||||
tableOutputFormat: z.enum(['html', 'md']).optional(),
|
||||
})
|
||||
|
||||
export const pulseParseBodySchema = z.object({
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
pages: z.string().optional(),
|
||||
extractFigure: z.boolean().optional(),
|
||||
figureDescription: z.boolean().optional(),
|
||||
returnHtml: z.boolean().optional(),
|
||||
chunking: z.string().optional(),
|
||||
chunkSize: z.number().optional(),
|
||||
})
|
||||
|
||||
export const extendParseBodySchema = z.object({
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
filePath: z.string().optional(),
|
||||
file: RawFileInputSchema.optional(),
|
||||
outputFormat: z.enum(['markdown', 'spatial']).optional(),
|
||||
chunking: z.enum(['page', 'document', 'section']).optional(),
|
||||
engine: z.enum(['parse_performance', 'parse_light']).optional(),
|
||||
})
|
||||
|
||||
export const mistralParseBodySchema = z.object({
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
filePath: z.string().min(1, 'File path is required').optional(),
|
||||
fileData: FileInputSchema.optional(),
|
||||
file: FileInputSchema.optional(),
|
||||
resultType: z.string().optional(),
|
||||
pages: z.array(z.number()).optional(),
|
||||
includeImageBase64: z.boolean().optional(),
|
||||
imageLimit: z.number().optional(),
|
||||
imageMinSize: z.number().optional(),
|
||||
})
|
||||
|
||||
export const textractParseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/textract/parse',
|
||||
body: textractParseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const textractAnalyzeExpenseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/textract/analyze-expense',
|
||||
body: textractAnalyzeExpenseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const textractAnalyzeIdContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/textract/analyze-id',
|
||||
body: textractAnalyzeIdBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const reductoParseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/reducto/parse',
|
||||
body: reductoParseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const pulseParseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/pulse/parse',
|
||||
body: pulseParseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const extendParseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/extend/parse',
|
||||
body: extendParseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const mistralParseContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/mistral/parse',
|
||||
body: mistralParseBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import { z } from 'zod'
|
||||
import { userFileSchema } from '@/lib/api/contracts/primitives'
|
||||
import { toolBooleanSchema, toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
|
||||
const MISSING_FIELDS_ERROR = 'Missing required fields: operation and apiKey'
|
||||
|
||||
export const elevenLabsAudioFileSchema = userFileSchema.extend({
|
||||
type: z.string().optional().default(''),
|
||||
})
|
||||
|
||||
export const elevenLabsAudioToolBodySchema = z
|
||||
.object({
|
||||
operation: z.enum(['sound_effects', 'speech_to_speech', 'audio_isolation'], {
|
||||
error: MISSING_FIELDS_ERROR,
|
||||
}),
|
||||
apiKey: z.string({ error: MISSING_FIELDS_ERROR }).min(1, MISSING_FIELDS_ERROR),
|
||||
voiceId: z.string().optional(),
|
||||
text: z.string().optional(),
|
||||
modelId: z.string().optional(),
|
||||
durationSeconds: z.coerce.number().min(0.5).max(30).optional(),
|
||||
promptInfluence: z.coerce.number().min(0).max(1).optional(),
|
||||
loop: toolBooleanSchema.optional(),
|
||||
removeBackgroundNoise: toolBooleanSchema.optional(),
|
||||
audioFile: elevenLabsAudioFileSchema.optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export const elevenLabsAudioToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/elevenlabs/audio',
|
||||
body: elevenLabsAudioToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,58 @@
|
||||
import { z } from 'zod'
|
||||
import { toolBooleanSchema, toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
|
||||
export const imageProviders = ['openai', 'gemini', 'falai'] as const
|
||||
const MISSING_IMAGE_FIELDS_ERROR = 'Missing required fields: provider, apiKey, and prompt'
|
||||
|
||||
export const imageProxyQuerySchema = z.object({
|
||||
url: z.string({ error: 'Missing URL parameter' }).min(1, 'Missing URL parameter'),
|
||||
})
|
||||
|
||||
export const imageToolBodySchema = z
|
||||
.object({
|
||||
provider: z
|
||||
.string({ error: MISSING_IMAGE_FIELDS_ERROR })
|
||||
.min(1, MISSING_IMAGE_FIELDS_ERROR)
|
||||
.refine((provider) => imageProviders.includes(provider as (typeof imageProviders)[number]), {
|
||||
message: `Invalid provider. Must be one of: ${imageProviders.join(', ')}`,
|
||||
}),
|
||||
apiKey: z.string({ error: MISSING_IMAGE_FIELDS_ERROR }).min(1, MISSING_IMAGE_FIELDS_ERROR),
|
||||
model: z.string().optional(),
|
||||
prompt: z.string({ error: MISSING_IMAGE_FIELDS_ERROR }).min(1, MISSING_IMAGE_FIELDS_ERROR),
|
||||
size: z.string().optional(),
|
||||
aspectRatio: z.string().optional(),
|
||||
resolution: z.string().optional(),
|
||||
quality: z.string().optional(),
|
||||
background: z.string().optional(),
|
||||
outputFormat: z.string().optional(),
|
||||
moderation: z.string().optional(),
|
||||
safetyTolerance: z.string().optional(),
|
||||
numImages: z.coerce.number().int().optional(),
|
||||
seed: z.coerce.number().int().optional(),
|
||||
enableSafetyChecker: toolBooleanSchema.optional(),
|
||||
enableWebSearch: toolBooleanSchema.optional(),
|
||||
thinkingLevel: z.string().optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
userId: z.string().optional(),
|
||||
useHostedCostTracking: z.boolean().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export type ImageToolBody = z.infer<typeof imageToolBodySchema>
|
||||
|
||||
export const imageProxyContract = defineRouteContract({
|
||||
method: 'GET',
|
||||
path: '/api/tools/image',
|
||||
query: imageProxyQuerySchema,
|
||||
response: { mode: 'binary' },
|
||||
})
|
||||
|
||||
export const imageToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/image',
|
||||
body: imageToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from '@/lib/api/contracts/tools/media/document-parse'
|
||||
export * from '@/lib/api/contracts/tools/media/image'
|
||||
export * from '@/lib/api/contracts/tools/media/shared'
|
||||
export * from '@/lib/api/contracts/tools/media/stt'
|
||||
export * from '@/lib/api/contracts/tools/media/tts'
|
||||
export * from '@/lib/api/contracts/tools/media/video'
|
||||
export * from '@/lib/api/contracts/tools/media/vision'
|
||||
@@ -0,0 +1,27 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const AWS_REGION_PATTERN =
|
||||
/^(eu-isoe|us-isob|us-iso|us-gov|af|ap|ca|cn|eu|il|me|mx|sa|us)-(central|north|northeast|northwest|south|southeast|southwest|east|west)-\d{1,2}$/
|
||||
|
||||
export const toolJsonResponseSchema = z
|
||||
.object({
|
||||
success: z.boolean().optional(),
|
||||
output: z.unknown().optional(),
|
||||
error: z.string().optional(),
|
||||
message: z.string().optional(),
|
||||
data: z.unknown().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export const toolBooleanSchema = z.preprocess(
|
||||
(value) => {
|
||||
if (typeof value === 'boolean') return value
|
||||
if (typeof value !== 'string') return value
|
||||
|
||||
const normalized = value.trim().toLowerCase()
|
||||
if (normalized === 'true' || normalized === '1') return true
|
||||
if (normalized === 'false' || normalized === '0' || normalized === '') return false
|
||||
return value
|
||||
},
|
||||
z.boolean({ error: 'must be a boolean (true/false)' })
|
||||
)
|
||||
@@ -0,0 +1,49 @@
|
||||
import { z } from 'zod'
|
||||
import { userFileSchema } from '@/lib/api/contracts/primitives'
|
||||
import { toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
|
||||
export const sttProviders = ['whisper', 'deepgram', 'elevenlabs', 'assemblyai', 'gemini'] as const
|
||||
const MISSING_STT_FIELDS_ERROR = 'Missing required fields: provider and apiKey'
|
||||
|
||||
export const sttUserFileSchema = userFileSchema.extend({
|
||||
type: z.string().optional().default(''),
|
||||
})
|
||||
|
||||
export const sttUserFileInputSchema = z.union([sttUserFileSchema, z.array(sttUserFileSchema)])
|
||||
|
||||
export const sttToolBodySchema = z
|
||||
.object({
|
||||
provider: z
|
||||
.string({ error: MISSING_STT_FIELDS_ERROR })
|
||||
.min(1, MISSING_STT_FIELDS_ERROR)
|
||||
.refine((provider) => sttProviders.includes(provider as (typeof sttProviders)[number]), {
|
||||
message: `Invalid provider. Must be one of: ${sttProviders.join(', ')}`,
|
||||
}),
|
||||
apiKey: z.string({ error: MISSING_STT_FIELDS_ERROR }).min(1, MISSING_STT_FIELDS_ERROR),
|
||||
model: z.string().optional(),
|
||||
audioFile: sttUserFileInputSchema.optional(),
|
||||
audioFileReference: sttUserFileInputSchema.optional(),
|
||||
audioUrl: z.string().optional(),
|
||||
language: z.string().optional(),
|
||||
timestamps: z.enum(['none', 'sentence', 'word']).optional(),
|
||||
diarization: z.boolean().optional(),
|
||||
translateToEnglish: z.boolean().optional(),
|
||||
prompt: z.string().optional(),
|
||||
temperature: z.coerce.number().optional(),
|
||||
sentiment: z.boolean().optional(),
|
||||
entityDetection: z.boolean().optional(),
|
||||
piiRedaction: z.boolean().optional(),
|
||||
summarization: z.boolean().optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export const sttToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/stt',
|
||||
body: sttToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,92 @@
|
||||
import { z } from 'zod'
|
||||
import { toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
|
||||
export const ttsToolBodySchema = z.object({
|
||||
text: z.string({ error: 'Missing required parameters' }).min(1, 'Missing required parameters'),
|
||||
voiceId: z.string({ error: 'Missing required parameters' }).min(1, 'Missing required parameters'),
|
||||
apiKey: z.string({ error: 'Missing required parameters' }).min(1, 'Missing required parameters'),
|
||||
modelId: z.string().optional().default('eleven_monolingual_v1'),
|
||||
stability: z.coerce.number().min(0).max(1).optional(),
|
||||
similarityBoost: z.coerce.number().min(0).max(1).optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const ttsOutputFormatSchema = z.union([z.record(z.string(), z.unknown()), z.string()])
|
||||
export const playHtOutputFormatSchema = z.enum(['mp3', 'wav', 'ogg', 'flac', 'mulaw'])
|
||||
|
||||
export const ttsUnifiedToolBodySchema = z
|
||||
.object({
|
||||
provider: z.enum(
|
||||
['openai', 'deepgram', 'elevenlabs', 'cartesia', 'google', 'azure', 'playht'],
|
||||
{
|
||||
error: 'Missing required fields: provider, text, and apiKey',
|
||||
}
|
||||
),
|
||||
text: z
|
||||
.string({ error: 'Missing required fields: provider, text, and apiKey' })
|
||||
.min(1, 'Missing required fields: provider, text, and apiKey'),
|
||||
apiKey: z
|
||||
.string({ error: 'Missing required fields: provider, text, and apiKey' })
|
||||
.min(1, 'Missing required fields: provider, text, and apiKey'),
|
||||
model: z.enum(['tts-1', 'tts-1-hd', 'gpt-4o-mini-tts']).optional(),
|
||||
voice: z.string().optional(),
|
||||
responseFormat: z.enum(['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm']).optional(),
|
||||
speed: z.coerce.number().optional(),
|
||||
encoding: z.enum(['linear16', 'mp3', 'opus', 'aac', 'flac', 'mulaw', 'alaw']).optional(),
|
||||
sampleRate: z.coerce.number().optional(),
|
||||
bitRate: z.coerce.number().optional(),
|
||||
container: z.enum(['none', 'wav', 'ogg']).optional(),
|
||||
voiceId: z.string().optional(),
|
||||
modelId: z.string().optional(),
|
||||
stability: z.coerce.number().optional(),
|
||||
similarityBoost: z.coerce.number().optional(),
|
||||
style: z.union([z.coerce.number(), z.string()]).optional(),
|
||||
useSpeakerBoost: z.boolean().optional(),
|
||||
language: z.string().optional(),
|
||||
outputFormat: ttsOutputFormatSchema.optional().nullable(),
|
||||
emotion: z.array(z.string()).optional(),
|
||||
languageCode: z.string().optional(),
|
||||
gender: z.enum(['MALE', 'FEMALE', 'NEUTRAL']).optional(),
|
||||
audioEncoding: z.enum(['LINEAR16', 'MP3', 'OGG_OPUS', 'MULAW', 'ALAW']).optional(),
|
||||
speakingRate: z.coerce.number().optional(),
|
||||
pitch: z.union([z.number(), z.string()]).optional(),
|
||||
volumeGainDb: z.coerce.number().optional(),
|
||||
sampleRateHertz: z.coerce.number().optional(),
|
||||
effectsProfileId: z.array(z.string()).optional(),
|
||||
region: z
|
||||
.string()
|
||||
.regex(
|
||||
/^[a-z][a-z0-9-]{1,30}[a-z0-9]$/,
|
||||
'region must be a valid Azure region identifier (e.g. eastus, westeurope)'
|
||||
)
|
||||
.optional(),
|
||||
rate: z.string().optional(),
|
||||
styleDegree: z.coerce.number().optional(),
|
||||
role: z.string().optional(),
|
||||
userId: z.string().optional(),
|
||||
quality: z.enum(['draft', 'standard', 'premium']).optional(),
|
||||
temperature: z.coerce.number().optional(),
|
||||
voiceGuidance: z.coerce.number().optional(),
|
||||
textGuidance: z.coerce.number().optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export const ttsToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/tts',
|
||||
body: ttsToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
|
||||
export const ttsUnifiedToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/tts/unified',
|
||||
body: ttsUnifiedToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import { z } from 'zod'
|
||||
import { userFileSchema } from '@/lib/api/contracts/primitives'
|
||||
import { toolBooleanSchema, toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
|
||||
export const videoProviders = ['runway', 'veo', 'luma', 'minimax', 'falai'] as const
|
||||
const MISSING_VIDEO_FIELDS_ERROR = 'Missing required fields: provider, apiKey, and prompt'
|
||||
|
||||
export const videoToolBodySchema = z
|
||||
.object({
|
||||
provider: z
|
||||
.string({ error: MISSING_VIDEO_FIELDS_ERROR })
|
||||
.min(1, MISSING_VIDEO_FIELDS_ERROR)
|
||||
.refine((provider) => videoProviders.includes(provider as (typeof videoProviders)[number]), {
|
||||
message: `Invalid provider. Must be one of: ${videoProviders.join(', ')}`,
|
||||
}),
|
||||
apiKey: z.string({ error: MISSING_VIDEO_FIELDS_ERROR }).min(1, MISSING_VIDEO_FIELDS_ERROR),
|
||||
model: z.string().optional(),
|
||||
prompt: z.string({ error: MISSING_VIDEO_FIELDS_ERROR }).min(1, MISSING_VIDEO_FIELDS_ERROR),
|
||||
duration: z.coerce.number().optional(),
|
||||
aspectRatio: z.string().optional(),
|
||||
resolution: z.string().optional(),
|
||||
visualReference: userFileSchema.optional(),
|
||||
cameraControl: z.unknown().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
promptOptimizer: toolBooleanSchema.optional(),
|
||||
generateAudio: toolBooleanSchema.optional(),
|
||||
workspaceId: z.string().optional(),
|
||||
workflowId: z.string().optional(),
|
||||
executionId: z.string().optional(),
|
||||
userId: z.string().optional(),
|
||||
useHostedCostTracking: z.boolean().optional(),
|
||||
})
|
||||
.passthrough()
|
||||
|
||||
export const videoToolContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/video',
|
||||
body: videoToolBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from 'zod'
|
||||
import { toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
||||
import { defineRouteContract } from '@/lib/api/contracts/types'
|
||||
import { RawFileInputSchema } from '@/lib/uploads/utils/file-schemas'
|
||||
|
||||
export const visionAnalyzeBodySchema = z.object({
|
||||
apiKey: z.string().min(1, 'API key is required'),
|
||||
imageUrl: z.string().optional().nullable(),
|
||||
imageFile: RawFileInputSchema.optional().nullable(),
|
||||
model: z.string().optional().default('gpt-5.2'),
|
||||
prompt: z.string().optional().nullable(),
|
||||
})
|
||||
|
||||
export const visionAnalyzeContract = defineRouteContract({
|
||||
method: 'POST',
|
||||
path: '/api/tools/vision/analyze',
|
||||
body: visionAnalyzeBodySchema,
|
||||
response: { mode: 'json', schema: toolJsonResponseSchema },
|
||||
})
|
||||
Reference in New Issue
Block a user