chore: cleanup

This commit is contained in:
Ephraim Atta-Duncan
2025-10-30 00:33:59 +00:00
parent 29be66a844
commit 00e33c5331
2 changed files with 6 additions and 50 deletions

View File

@ -80,12 +80,6 @@ const EnvelopeEditorFieldsPageRenderer = lazy(
* });
* // Result: height expanded to ~2.7% (30px), centered on original position
*/
/**
* Enforces minimum field dimensions with centered expansion.
*
* If a field is smaller than the minimum width or height, it will be expanded
* to meet the minimum requirements while staying centered on its original position.
*/
const enforceMinimumFieldDimensions = (params: {
positionX: number;
positionY: number;

View File

@ -1,9 +1,7 @@
import { google } from '@ai-sdk/google';
import { sValidator } from '@hono/standard-validator';
import { generateObject, generateText } from 'ai';
import { generateObject } from 'ai';
import { readFile, writeFile } from 'fs/promises';
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { join } from 'path';
import sharp from 'sharp';
import { Canvas, Image } from 'skia-canvas';
@ -14,11 +12,9 @@ import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { HonoEnv } from '../router';
import {
type TDetectObjectsResponse,
type TGenerateTextResponse,
ZDetectObjectsAndDrawRequestSchema,
ZDetectObjectsRequestSchema,
ZDetectObjectsResponseSchema,
ZGenerateTextRequestSchema,
ZDetectedObjectSchema,
} from './ai.types';
/**
@ -100,8 +96,10 @@ const runObjectDetection = async (imageBuffer: Buffer): Promise<TDetectObjectsRe
const base64Image = compressedImageBuffer.toString('base64');
const result = await generateObject({
model: google('gemini-2.5-pro'),
schema: ZDetectObjectsResponseSchema,
// model: google('gemini-2.5-pro'),
model: 'google/gemini-2.5-pro',
output: 'array',
schema: ZDetectedObjectSchema,
messages: [
{
role: 'user',
@ -123,42 +121,6 @@ const runObjectDetection = async (imageBuffer: Buffer): Promise<TDetectObjectsRe
};
export const aiRoute = new Hono<HonoEnv>()
.use(
'*',
cors({
origin: 'http://localhost:3000',
allowMethods: ['POST', 'OPTIONS'],
allowHeaders: ['Content-Type', 'Authorization'],
credentials: true,
}),
)
.post('/generate', sValidator('json', ZGenerateTextRequestSchema), async (c) => {
try {
await getSession(c.req.raw);
const { prompt } = c.req.valid('json');
const result = await generateText({
model: google('gemini-2.0-flash-exp'),
prompt,
});
return c.json<TGenerateTextResponse>({ text: result.text });
} catch (error) {
console.error('AI generation failed:', error);
if (error instanceof AppError) {
throw error;
}
throw new AppError(AppErrorCode.UNKNOWN_ERROR, {
message: 'Failed to generate text',
userMessage: 'An error occurred while generating the text. Please try again.',
});
}
})
.post('/detect-objects', sValidator('json', ZDetectObjectsRequestSchema), async (c) => {
try {
await getSession(c.req.raw);