Compare commits
5 Commits
48d734516a
...
fix/chat-c
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f883c4c04 | |||
| 5207d8c0c9 | |||
| d1c9a747b9 | |||
| 3d669713d7 | |||
| 1a6cf113c8 |
@@ -1,6 +1,7 @@
|
|||||||
import { Body, Controller, HttpException, Logger, Post, Req, Res, UseGuards } from "@nestjs/common";
|
import { Body, Controller, HttpException, Logger, Post, Req, Res, UseGuards } from "@nestjs/common";
|
||||||
import type { Response } from "express";
|
import type { Response } from "express";
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
|
import { SkipCsrf } from "../common/decorators/skip-csrf.decorator";
|
||||||
import type { MaybeAuthenticatedRequest } from "../auth/types/better-auth-request.interface";
|
import type { MaybeAuthenticatedRequest } from "../auth/types/better-auth-request.interface";
|
||||||
import { ChatStreamDto } from "./chat-proxy.dto";
|
import { ChatStreamDto } from "./chat-proxy.dto";
|
||||||
import { ChatProxyService } from "./chat-proxy.service";
|
import { ChatProxyService } from "./chat-proxy.service";
|
||||||
@@ -14,6 +15,7 @@ export class ChatProxyController {
|
|||||||
// POST /api/chat/guest
|
// POST /api/chat/guest
|
||||||
// Guest chat endpoint - no authentication required
|
// Guest chat endpoint - no authentication required
|
||||||
// Uses a shared LLM configuration for unauthenticated users
|
// Uses a shared LLM configuration for unauthenticated users
|
||||||
|
@SkipCsrf()
|
||||||
@Post("guest")
|
@Post("guest")
|
||||||
async guestChat(
|
async guestChat(
|
||||||
@Body() body: ChatStreamDto,
|
@Body() body: ChatStreamDto,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Module } from "@nestjs/common";
|
import { Module } from "@nestjs/common";
|
||||||
|
import { ConfigModule } from "@nestjs/config";
|
||||||
import { AuthModule } from "../auth/auth.module";
|
import { AuthModule } from "../auth/auth.module";
|
||||||
import { AgentConfigModule } from "../agent-config/agent-config.module";
|
import { AgentConfigModule } from "../agent-config/agent-config.module";
|
||||||
import { ContainerLifecycleModule } from "../container-lifecycle/container-lifecycle.module";
|
import { ContainerLifecycleModule } from "../container-lifecycle/container-lifecycle.module";
|
||||||
@@ -7,7 +8,7 @@ import { ChatProxyController } from "./chat-proxy.controller";
|
|||||||
import { ChatProxyService } from "./chat-proxy.service";
|
import { ChatProxyService } from "./chat-proxy.service";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuthModule, PrismaModule, ContainerLifecycleModule, AgentConfigModule],
|
imports: [AuthModule, PrismaModule, ContainerLifecycleModule, AgentConfigModule, ConfigModule],
|
||||||
controllers: [ChatProxyController],
|
controllers: [ChatProxyController],
|
||||||
providers: [ChatProxyService],
|
providers: [ChatProxyService],
|
||||||
exports: [ChatProxyService],
|
exports: [ChatProxyService],
|
||||||
|
|||||||
@@ -280,13 +280,16 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Streaming failed - check if auth error, try guest mode
|
// Streaming failed - check if auth error, try guest mode
|
||||||
const isAuthError = err instanceof Error &&
|
const isAuthError =
|
||||||
(err.message.includes("403") || err.message.includes("401") ||
|
err instanceof Error &&
|
||||||
err.message.includes("auth") || err.message.includes("Forbidden"));
|
(err.message.includes("403") ||
|
||||||
|
err.message.includes("401") ||
|
||||||
|
err.message.includes("auth") ||
|
||||||
|
err.message.includes("Forbidden"));
|
||||||
|
|
||||||
if (isAuthError) {
|
if (isAuthError) {
|
||||||
console.warn("Auth failed, trying guest chat mode");
|
console.warn("Auth failed, trying guest chat mode");
|
||||||
|
|
||||||
// Try guest chat streaming
|
// Try guest chat streaming
|
||||||
try {
|
try {
|
||||||
await new Promise<void>((guestResolve, guestReject) => {
|
await new Promise<void>((guestResolve, guestReject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user