6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (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 / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
206 lines
7.2 KiB
TypeScript
206 lines
7.2 KiB
TypeScript
import { z } from 'zod'
|
|
import { resolvedSecretTraceProvenanceSchema } from '@/lib/api/contracts/primitives'
|
|
import { AWS_REGION_PATTERN, toolJsonResponseSchema } from '@/lib/api/contracts/tools/media/shared'
|
|
import { defineRouteContract } from '@/lib/api/contracts/types'
|
|
import { RESOLVED_SECRET_PROVENANCE_FIELD } from '@/lib/execution/private-tool-metadata'
|
|
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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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(),
|
|
[RESOLVED_SECRET_PROVENANCE_FIELD]: resolvedSecretTraceProvenanceSchema.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 },
|
|
})
|