Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.next
node_modules
out
public
*.d.ts
*.js.map
*.css
*.svg
*.png
*.jpg
*.jpeg
*.gif
*.ico
*.woff
*.woff2
*.ttf
*.eot
63 changes: 63 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"extends": [
"next/core-web-vitals",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"react",
"import"
],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_|props|node",
"varsIgnorePattern": "^_",
"ignoreRestSiblings": true
}],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
"@typescript-eslint/no-non-null-assertion": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/no-unescaped-entities": "warn",
"react/no-unused-prop-types": "warn",
"react/jsx-no-duplicate-props": "error",
"react/jsx-key": ["error", { "checkFragmentShorthand": true }],
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
"prefer-const": "error",
"no-var": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
"eqeqeq": ["error", "always"],
"curly": ["error", "all"],
"no-unused-expressions": "error",
"import/no-unresolved": "off",
"import/order": ["error", {
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
"newlines-between": "always",
"alphabetize": { "order": "asc" }
}],
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/ban-ts-comment": ["warn", { "minimumDescriptionLength": 3 }],
"@next/next/no-img-element": "warn",
"no-empty": "warn",
"@typescript-eslint/no-var-requires": "warn",
"no-empty-pattern": "warn"
},
"settings": {
"react": {
"version": "detect"
}
},
"ignorePatterns": [
"node_modules/",
".next/",
"out/",
"public/",
"*.config.js"
]
}
9 changes: 5 additions & 4 deletions app/api/auth/session/refresh/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import crypto from 'crypto';

import { NextResponse } from 'next/server';

import { CACHE_TTL } from '@/app/config/api';
import { checkApiAccessToken } from '@/lib/auth';
import { validateSession, storeSession } from '@/lib/redis';
import crypto from 'crypto';
import redis from '@/lib/redis';
import { ACCESS_TOKEN, CACHE_TTL } from '@/app/config/api';
import { checkApiAccessToken } from '@/lib/auth';

const RATE_LIMIT_WINDOW = Math.floor(CACHE_TTL * 0.20 * 0.25);
const MAX_REQUESTS = 3;
Expand Down Expand Up @@ -56,7 +58,6 @@ export async function POST(request: Request) {
return authCheckResponse;
}


if (await isRateLimited(currentToken)) {
return NextResponse.json(
{ error: 'Too many refresh attempts. Please try again later.' },
Expand Down
8 changes: 5 additions & 3 deletions app/api/auth/session/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NextResponse } from 'next/server';
import crypto from 'crypto';
import { storeSession } from '@/lib/redis';
import { ACCESS_TOKEN, CACHE_TTL } from '@/app/config/api';

import { NextResponse } from 'next/server';

import { CACHE_TTL } from '@/app/config/api';
import { checkApiAccessToken } from '@/lib/auth';
import { storeSession } from '@/lib/redis';

export async function GET(request: Request) {
if (process.env.NODE_ENV === 'production') {
Expand Down
1 change: 1 addition & 0 deletions app/api/auth/status/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';

import { ACCESS_TOKEN } from '@/app/config/api';

/**
Expand Down
15 changes: 7 additions & 8 deletions app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createOpenAI } from '@ai-sdk/openai';
import { streamText, createDataStreamResponse, generateText, simulateReadableStream, Message } from 'ai';

import { apiEndpoint, apiKey, imgGenFnModel, DEFAULT_SYSTEM_PROMPT } from '@/app/config/api';
import { defaultModel, models } from '@/app/config/models';
import { generateImageTool } from '@/lib/tools';
import { getAvailableModels } from '@/lib/models';
import { withAuth } from '@/lib/auth';
import { getAvailableModels } from '@/lib/models';
import { generateImageTool } from '@/lib/tools';

const { Tiktoken } = require("tiktoken/lite");
const cl100k_base = require("tiktoken/encoders/cl100k_base.json");
const { Tiktoken } = require("tiktoken/lite");

// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
Expand All @@ -26,12 +27,13 @@ const openai = createOpenAI({
// Define the handler function to be wrapped with authentication
async function handlePostRequest(req: Request) {
// Extract the `messages` and `model` from the body of the request
let { messages, model, system, temperature, topP, context } = await req.json();
const body = await req.json();
const { messages, system, temperature, topP, context } = body;
let { model } = body;
// Get available models from cache or API
const allModels = await getAvailableModels();
const selectedModel = allModels.find(m => m.id === model) || models.find(m => m.id === defaultModel);


const encoding = new Tiktoken(
cl100k_base.bpe_ranks,
cl100k_base.special_tokens,
Expand Down Expand Up @@ -130,7 +132,6 @@ async function handlePostRequest(req: Request) {
}
}


return createDataStreamResponse({
execute: dataStream => {
const result = streamText({
Expand Down Expand Up @@ -167,5 +168,3 @@ async function handlePostRequest(req: Request) {

// Export the wrapped handler
export const POST = withAuth(handlePostRequest);


1 change: 1 addition & 0 deletions app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';

import { apiEndpoint, apiKey, imgEndpoint, imgApiKey } from '@/app/config/api';
import { models } from '@/app/config/models';

Expand Down
3 changes: 2 additions & 1 deletion app/api/models/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextResponse } from 'next/server';
import { getAvailableModels } from '@/lib/models';

import { withAuth } from '@/lib/auth';
import { getAvailableModels } from '@/lib/models';

async function handleGetRequest() {
const models = await getAvailableModels();
Expand Down
1 change: 1 addition & 0 deletions app/api/transcription/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';

import { WS_TRANSCRIPTION_URLS, WS_TRANSCRIPTION_MODEL } from '@/app/config/api';
import { withAuth } from '@/lib/auth';

Expand Down
58 changes: 0 additions & 58 deletions app/api/use-chat-streaming-tool-calls/route.ts

This file was deleted.

34 changes: 0 additions & 34 deletions app/api/use-chat-vision/route.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/config/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Model {
deployUrl?: string;
}

export let models: Model[] = [
export const models: Model[] = [
{
id: 'Qwen3-235B-A22B-FP8',
name: 'Qwen3 235B A22B',
Expand Down
Loading