Compare commits
1 Commits
fix/fleet-
...
fix/contai
| Author | SHA1 | Date | |
|---|---|---|---|
| 39a87cd1c5 |
@@ -1,5 +1,4 @@
|
|||||||
import { Module } from "@nestjs/common";
|
import { Module } from "@nestjs/common";
|
||||||
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";
|
||||||
import { PrismaModule } from "../prisma/prisma.module";
|
import { PrismaModule } from "../prisma/prisma.module";
|
||||||
@@ -7,7 +6,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: [PrismaModule, ContainerLifecycleModule, AgentConfigModule],
|
||||||
controllers: [ChatProxyController],
|
controllers: [ChatProxyController],
|
||||||
providers: [ChatProxyService],
|
providers: [ChatProxyService],
|
||||||
exports: [ChatProxyService],
|
exports: [ChatProxyService],
|
||||||
|
|||||||
@@ -87,17 +87,6 @@ describe("CsrfGuard", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("State-changing methods requiring CSRF", () => {
|
describe("State-changing methods requiring CSRF", () => {
|
||||||
it("should allow POST with Bearer auth without CSRF token", () => {
|
|
||||||
const context = createContext(
|
|
||||||
"POST",
|
|
||||||
{},
|
|
||||||
{ authorization: "Bearer api-token" },
|
|
||||||
false,
|
|
||||||
"user-123"
|
|
||||||
);
|
|
||||||
expect(guard.canActivate(context)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should reject POST without CSRF token", () => {
|
it("should reject POST without CSRF token", () => {
|
||||||
const context = createContext("POST", {}, {}, false, "user-123");
|
const context = createContext("POST", {}, {}, false, "user-123");
|
||||||
expect(() => guard.canActivate(context)).toThrow(ForbiddenException);
|
expect(() => guard.canActivate(context)).toThrow(ForbiddenException);
|
||||||
|
|||||||
@@ -57,11 +57,6 @@ export class CsrfGuard implements CanActivate {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authHeader = request.headers.authorization;
|
|
||||||
if (typeof authHeader === "string" && authHeader.startsWith("Bearer ")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get CSRF token from cookie and header
|
// Get CSRF token from cookie and header
|
||||||
const cookies = request.cookies as Record<string, string> | undefined;
|
const cookies = request.cookies as Record<string, string> | undefined;
|
||||||
const cookieToken = cookies?.["csrf-token"];
|
const cookieToken = cookies?.["csrf-token"];
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { Module } from "@nestjs/common";
|
import { Module } from "@nestjs/common";
|
||||||
import { AuthModule } from "../auth/auth.module";
|
|
||||||
import { PrismaModule } from "../prisma/prisma.module";
|
import { PrismaModule } from "../prisma/prisma.module";
|
||||||
import { CryptoModule } from "../crypto/crypto.module";
|
import { CryptoModule } from "../crypto/crypto.module";
|
||||||
import { FleetSettingsController } from "./fleet-settings.controller";
|
import { FleetSettingsController } from "./fleet-settings.controller";
|
||||||
import { FleetSettingsService } from "./fleet-settings.service";
|
import { FleetSettingsService } from "./fleet-settings.service";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuthModule, PrismaModule, CryptoModule],
|
imports: [PrismaModule, CryptoModule],
|
||||||
controllers: [FleetSettingsController],
|
controllers: [FleetSettingsController],
|
||||||
providers: [FleetSettingsService],
|
providers: [FleetSettingsService],
|
||||||
exports: [FleetSettingsService],
|
exports: [FleetSettingsService],
|
||||||
|
|||||||
@@ -85,14 +85,6 @@ const INITIAL_FORM: ProviderFormState = {
|
|||||||
isActive: true,
|
isActive: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapProviderTypeToApi(type: string): "ollama" | "openai" | "claude" {
|
|
||||||
if (type === "ollama" || type === "claude") {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "openai";
|
|
||||||
}
|
|
||||||
|
|
||||||
function getErrorMessage(error: unknown, fallback: string): string {
|
function getErrorMessage(error: unknown, fallback: string): string {
|
||||||
if (error instanceof Error && error.message.trim().length > 0) {
|
if (error instanceof Error && error.message.trim().length > 0) {
|
||||||
return error.message;
|
return error.message;
|
||||||
@@ -101,6 +93,18 @@ function getErrorMessage(error: unknown, fallback: string): string {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildProviderName(displayName: string, type: string): string {
|
||||||
|
const slug = displayName
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, "-")
|
||||||
|
.replace(/^-+/, "")
|
||||||
|
.replace(/-+$/, "");
|
||||||
|
|
||||||
|
const candidate = `${type}-${slug.length > 0 ? slug : "provider"}`;
|
||||||
|
return candidate.slice(0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeProviderModels(models: unknown): FleetProviderModel[] {
|
function normalizeProviderModels(models: unknown): FleetProviderModel[] {
|
||||||
if (!Array.isArray(models)) {
|
if (!Array.isArray(models)) {
|
||||||
return [];
|
return [];
|
||||||
@@ -149,11 +153,11 @@ function modelsToEditorText(models: unknown): string {
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseModelsText(value: string): string[] {
|
function parseModelsText(value: string): FleetProviderModel[] {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
|
|
||||||
return value
|
return value
|
||||||
.split(/\r?\n/g)
|
.split(/\n|,/g)
|
||||||
.map((segment) => segment.trim())
|
.map((segment) => segment.trim())
|
||||||
.filter((segment) => segment.length > 0)
|
.filter((segment) => segment.length > 0)
|
||||||
.filter((segment) => {
|
.filter((segment) => {
|
||||||
@@ -162,7 +166,8 @@ function parseModelsText(value: string): string[] {
|
|||||||
}
|
}
|
||||||
seen.add(segment);
|
seen.add(segment);
|
||||||
return true;
|
return true;
|
||||||
});
|
})
|
||||||
|
.map((id) => ({ id, name: id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
function maskApiKey(value: string): string {
|
function maskApiKey(value: string): string {
|
||||||
@@ -274,7 +279,6 @@ export default function ProvidersSettingsPage(): ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const models = parseModelsText(form.modelsText);
|
const models = parseModelsText(form.modelsText);
|
||||||
const providerModels = models.map((id) => ({ id, name: id }));
|
|
||||||
const baseUrl = form.baseUrl.trim();
|
const baseUrl = form.baseUrl.trim();
|
||||||
const apiKey = form.apiKey.trim();
|
const apiKey = form.apiKey.trim();
|
||||||
|
|
||||||
@@ -285,7 +289,7 @@ export default function ProvidersSettingsPage(): ReactElement {
|
|||||||
const updatePayload: UpdateFleetProviderRequest = {
|
const updatePayload: UpdateFleetProviderRequest = {
|
||||||
displayName,
|
displayName,
|
||||||
isActive: form.isActive,
|
isActive: form.isActive,
|
||||||
models: providerModels,
|
models,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (baseUrl.length > 0) {
|
if (baseUrl.length > 0) {
|
||||||
@@ -299,27 +303,21 @@ export default function ProvidersSettingsPage(): ReactElement {
|
|||||||
await updateFleetProvider(editingProvider.id, updatePayload);
|
await updateFleetProvider(editingProvider.id, updatePayload);
|
||||||
setSuccessMessage(`Updated provider "${displayName}".`);
|
setSuccessMessage(`Updated provider "${displayName}".`);
|
||||||
} else {
|
} else {
|
||||||
const config: CreateFleetProviderRequest["config"] = {};
|
const createPayload: CreateFleetProviderRequest = {
|
||||||
|
name: buildProviderName(displayName, form.type),
|
||||||
|
displayName,
|
||||||
|
type: form.type,
|
||||||
|
models,
|
||||||
|
};
|
||||||
|
|
||||||
if (baseUrl.length > 0) {
|
if (baseUrl.length > 0) {
|
||||||
config.endpoint = baseUrl;
|
createPayload.baseUrl = baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiKey.length > 0) {
|
if (apiKey.length > 0) {
|
||||||
config.apiKey = apiKey;
|
createPayload.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (models.length > 0) {
|
|
||||||
config.models = models;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createPayload: CreateFleetProviderRequest = {
|
|
||||||
displayName,
|
|
||||||
providerType: mapProviderTypeToApi(form.type),
|
|
||||||
config,
|
|
||||||
isEnabled: form.isActive,
|
|
||||||
};
|
|
||||||
|
|
||||||
await createFleetProvider(createPayload);
|
await createFleetProvider(createPayload);
|
||||||
setSuccessMessage(`Added provider "${displayName}".`);
|
setSuccessMessage(`Added provider "${displayName}".`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,25 +34,17 @@ describe("createFleetProvider", (): void => {
|
|||||||
vi.mocked(client.apiPost).mockResolvedValueOnce({ id: "provider-1" } as never);
|
vi.mocked(client.apiPost).mockResolvedValueOnce({ id: "provider-1" } as never);
|
||||||
|
|
||||||
await createFleetProvider({
|
await createFleetProvider({
|
||||||
providerType: "openai",
|
name: "openai-main",
|
||||||
displayName: "OpenAI Main",
|
displayName: "OpenAI Main",
|
||||||
config: {
|
type: "openai",
|
||||||
endpoint: "https://api.openai.com/v1",
|
apiKey: "sk-test",
|
||||||
apiKey: "sk-test",
|
|
||||||
models: ["gpt-4.1-mini", "gpt-4o-mini"],
|
|
||||||
},
|
|
||||||
isEnabled: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(client.apiPost).toHaveBeenCalledWith("/api/fleet-settings/providers", {
|
expect(client.apiPost).toHaveBeenCalledWith("/api/fleet-settings/providers", {
|
||||||
providerType: "openai",
|
name: "openai-main",
|
||||||
displayName: "OpenAI Main",
|
displayName: "OpenAI Main",
|
||||||
config: {
|
type: "openai",
|
||||||
endpoint: "https://api.openai.com/v1",
|
apiKey: "sk-test",
|
||||||
apiKey: "sk-test",
|
|
||||||
models: ["gpt-4.1-mini", "gpt-4o-mini"],
|
|
||||||
},
|
|
||||||
isEnabled: true,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,16 +16,13 @@ export interface FleetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateFleetProviderRequest {
|
export interface CreateFleetProviderRequest {
|
||||||
providerType: "ollama" | "openai" | "claude";
|
name: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
config: {
|
type: string;
|
||||||
endpoint?: string;
|
baseUrl?: string;
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
models?: string[];
|
apiType?: string;
|
||||||
timeout?: number;
|
models?: FleetProviderModel[];
|
||||||
};
|
|
||||||
isDefault?: boolean;
|
|
||||||
isEnabled?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateFleetProviderRequest {
|
export interface UpdateFleetProviderRequest {
|
||||||
|
|||||||
Reference in New Issue
Block a user