Merge remote-tracking branch 'upstream/dev' into feat/obsidian-plugin

This commit is contained in:
Anish Sarkar 2026-04-24 21:34:55 +05:30
commit 9b1b9a90c0
175 changed files with 10592 additions and 2302 deletions

View file

@ -0,0 +1,61 @@
export type AgentFilesystemMode = "cloud" | "desktop_local_folder";
export type ClientPlatform = "web" | "desktop";
export interface AgentFilesystemMountSelection {
mount_id: string;
root_path: string;
}
export interface AgentFilesystemSelection {
filesystem_mode: AgentFilesystemMode;
client_platform: ClientPlatform;
local_filesystem_mounts?: AgentFilesystemMountSelection[];
}
const DEFAULT_SELECTION: AgentFilesystemSelection = {
filesystem_mode: "cloud",
client_platform: "web",
};
export function getClientPlatform(): ClientPlatform {
if (typeof window === "undefined") return "web";
return window.electronAPI ? "desktop" : "web";
}
export async function getAgentFilesystemSelection(): Promise<AgentFilesystemSelection> {
const platform = getClientPlatform();
if (platform !== "desktop" || !window.electronAPI?.getAgentFilesystemSettings) {
return { ...DEFAULT_SELECTION, client_platform: platform };
}
try {
const settings = await window.electronAPI.getAgentFilesystemSettings();
if (settings.mode === "desktop_local_folder") {
const mounts = await window.electronAPI.getAgentFilesystemMounts?.();
const localFilesystemMounts =
mounts?.map((entry) => ({
mount_id: entry.mount,
root_path: entry.rootPath,
})) ?? [];
if (localFilesystemMounts.length === 0) {
return {
filesystem_mode: "cloud",
client_platform: "desktop",
};
}
return {
filesystem_mode: "desktop_local_folder",
client_platform: "desktop",
local_filesystem_mounts: localFilesystemMounts,
};
}
return {
filesystem_mode: "cloud",
client_platform: "desktop",
};
} catch {
return {
filesystem_mode: "cloud",
client_platform: "desktop",
};
}
}

View file

@ -12,6 +12,10 @@ import { ValidationError } from "../error";
const BASE = "/api/v1/public/anon-chat";
export type AnonUploadResult =
| { ok: true; data: { filename: string; size_bytes: number } }
| { ok: false; reason: "quota_exceeded" };
class AnonymousChatApiService {
private baseUrl: string;
@ -71,7 +75,7 @@ class AnonymousChatApiService {
});
};
uploadDocument = async (file: File): Promise<{ filename: string; size_bytes: number }> => {
uploadDocument = async (file: File): Promise<AnonUploadResult> => {
const formData = new FormData();
formData.append("file", file);
const res = await fetch(this.fullUrl("/upload"), {
@ -79,11 +83,15 @@ class AnonymousChatApiService {
credentials: "include",
body: formData,
});
if (res.status === 409) {
return { ok: false, reason: "quota_exceeded" };
}
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.detail || `Upload failed: ${res.status}`);
}
return res.json();
const data = await res.json();
return { ok: true, data };
};
getDocument = async (): Promise<{ filename: string; size_bytes: number } | null> => {

View file

@ -1,4 +1,5 @@
import type { ZodType } from "zod";
import { getClientPlatform } from "../agent-filesystem";
import { getBearerToken, handleUnauthorized, refreshAccessToken } from "../auth-utils";
import {
AbortedError,
@ -75,6 +76,8 @@ class BaseApiService {
const defaultOptions: RequestOptions = {
headers: {
Authorization: `Bearer ${this.bearerToken || ""}`,
"X-SurfSense-Client-Platform":
typeof window === "undefined" ? "web" : getClientPlatform(),
},
method: "GET",
responseType: ResponseType.JSON,

View file

@ -414,16 +414,8 @@ class ConnectorsApiService {
* Subsequent calls to this tool will skip HITL approval.
*/
trustMCPTool = async (connectorId: number, toolName: string): Promise<void> => {
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
const token =
typeof window !== "undefined" ? document.cookie.match(/fapiToken=([^;]+)/)?.[1] : undefined;
await fetch(`${backendUrl}/api/v1/connectors/mcp/${connectorId}/trust-tool`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}),
},
body: JSON.stringify({ tool_name: toolName }),
await baseApiService.post(`/api/v1/connectors/mcp/${connectorId}/trust-tool`, undefined, {
body: { tool_name: toolName },
});
};
@ -431,16 +423,8 @@ class ConnectorsApiService {
* Remove a tool from the MCP connector's "Always Allow" list.
*/
untrustMCPTool = async (connectorId: number, toolName: string): Promise<void> => {
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
const token =
typeof window !== "undefined" ? document.cookie.match(/fapiToken=([^;]+)/)?.[1] : undefined;
await fetch(`${backendUrl}/api/v1/connectors/mcp/${connectorId}/untrust-tool`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}),
},
body: JSON.stringify({ tool_name: toolName }),
await baseApiService.post(`/api/v1/connectors/mcp/${connectorId}/untrust-tool`, undefined, {
body: { tool_name: toolName },
});
};

View file

@ -0,0 +1,34 @@
const EXTENSION_TO_MONACO_LANGUAGE: Record<string, string> = {
css: "css",
csv: "plaintext",
cjs: "javascript",
html: "html",
htm: "html",
ini: "ini",
js: "javascript",
json: "json",
markdown: "markdown",
md: "markdown",
mjs: "javascript",
py: "python",
sql: "sql",
toml: "plaintext",
ts: "typescript",
tsx: "typescript",
xml: "xml",
yaml: "yaml",
yml: "yaml",
};
export function inferMonacoLanguageFromPath(filePath: string | null | undefined): string {
if (!filePath) return "plaintext";
const fileName = filePath.split("/").pop() ?? filePath;
const extensionIndex = fileName.lastIndexOf(".");
if (extensionIndex <= 0 || extensionIndex === fileName.length - 1) {
return "plaintext";
}
const extension = fileName.slice(extensionIndex + 1).toLowerCase();
return EXTENSION_TO_MONACO_LANGUAGE[extension] ?? "plaintext";
}