mirror of
https://github.com/documenso/documenso.git
synced 2025-11-11 04:52:41 +10:00
chore: cleanup
This commit is contained in:
@ -80,12 +80,6 @@ const EnvelopeEditorFieldsPageRenderer = lazy(
|
|||||||
* });
|
* });
|
||||||
* // Result: height expanded to ~2.7% (30px), centered on original position
|
* // 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: {
|
const enforceMinimumFieldDimensions = (params: {
|
||||||
positionX: number;
|
positionX: number;
|
||||||
positionY: number;
|
positionY: number;
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { google } from '@ai-sdk/google';
|
|
||||||
import { sValidator } from '@hono/standard-validator';
|
import { sValidator } from '@hono/standard-validator';
|
||||||
import { generateObject, generateText } from 'ai';
|
import { generateObject } from 'ai';
|
||||||
import { readFile, writeFile } from 'fs/promises';
|
import { readFile, writeFile } from 'fs/promises';
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { cors } from 'hono/cors';
|
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { Canvas, Image } from 'skia-canvas';
|
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 { HonoEnv } from '../router';
|
||||||
import {
|
import {
|
||||||
type TDetectObjectsResponse,
|
type TDetectObjectsResponse,
|
||||||
type TGenerateTextResponse,
|
|
||||||
ZDetectObjectsAndDrawRequestSchema,
|
ZDetectObjectsAndDrawRequestSchema,
|
||||||
ZDetectObjectsRequestSchema,
|
ZDetectObjectsRequestSchema,
|
||||||
ZDetectObjectsResponseSchema,
|
ZDetectedObjectSchema,
|
||||||
ZGenerateTextRequestSchema,
|
|
||||||
} from './ai.types';
|
} from './ai.types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,8 +96,10 @@ const runObjectDetection = async (imageBuffer: Buffer): Promise<TDetectObjectsRe
|
|||||||
const base64Image = compressedImageBuffer.toString('base64');
|
const base64Image = compressedImageBuffer.toString('base64');
|
||||||
|
|
||||||
const result = await generateObject({
|
const result = await generateObject({
|
||||||
model: google('gemini-2.5-pro'),
|
// model: google('gemini-2.5-pro'),
|
||||||
schema: ZDetectObjectsResponseSchema,
|
model: 'google/gemini-2.5-pro',
|
||||||
|
output: 'array',
|
||||||
|
schema: ZDetectedObjectSchema,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
@ -123,42 +121,6 @@ const runObjectDetection = async (imageBuffer: Buffer): Promise<TDetectObjectsRe
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const aiRoute = new Hono<HonoEnv>()
|
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) => {
|
.post('/detect-objects', sValidator('json', ZDetectObjectsRequestSchema), async (c) => {
|
||||||
try {
|
try {
|
||||||
await getSession(c.req.raw);
|
await getSession(c.req.raw);
|
||||||
|
|||||||
Reference in New Issue
Block a user