mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-10 22:32:16 +02:00
feat(workspace): refactor search space handling to workspace
This commit is contained in:
parent
e92b7a34ed
commit
c379ab1155
53 changed files with 268 additions and 169 deletions
|
|
@ -44,7 +44,7 @@ export type AgentPermissionRuleUpdate = z.infer<typeof AgentPermissionRuleUpdate
|
|||
class AgentPermissionsApiService {
|
||||
list = async (searchSpaceId: number): Promise<AgentPermissionRule[]> => {
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
`/api/v1/workspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
AgentPermissionRuleListSchema
|
||||
);
|
||||
};
|
||||
|
|
@ -58,7 +58,7 @@ class AgentPermissionsApiService {
|
|||
throw new ValidationError(parsed.error.issues.map((i) => i.message).join(", "));
|
||||
}
|
||||
return baseApiService.post(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
`/api/v1/workspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
AgentPermissionRuleSchema,
|
||||
{ body: parsed.data }
|
||||
);
|
||||
|
|
@ -74,7 +74,7 @@ class AgentPermissionsApiService {
|
|||
throw new ValidationError(parsed.error.issues.map((i) => i.message).join(", "));
|
||||
}
|
||||
return baseApiService.patch(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`,
|
||||
`/api/v1/workspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`,
|
||||
AgentPermissionRuleSchema,
|
||||
{ body: parsed.data }
|
||||
);
|
||||
|
|
@ -82,7 +82,7 @@ class AgentPermissionsApiService {
|
|||
|
||||
remove = async (searchSpaceId: number, ruleId: number): Promise<void> => {
|
||||
await baseApiService.delete(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`
|
||||
`/api/v1/workspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class AutomationsApiService {
|
|||
|
||||
listAutomations = async (params: AutomationListParams) => {
|
||||
const qs = new URLSearchParams({
|
||||
search_space_id: String(params.search_space_id),
|
||||
workspace_id: String(params.search_space_id),
|
||||
limit: String(params.limit),
|
||||
offset: String(params.offset),
|
||||
});
|
||||
|
|
@ -50,7 +50,10 @@ class AutomationsApiService {
|
|||
|
||||
createAutomation = async (request: AutomationCreateRequest) => {
|
||||
const data = rejectIfInvalid(automationCreateRequest.safeParse(request));
|
||||
return baseApiService.post(BASE, automation, { body: data });
|
||||
const { search_space_id, ...body } = data;
|
||||
return baseApiService.post(BASE, automation, {
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
updateAutomation = async (automationId: number, request: AutomationUpdateRequest) => {
|
||||
|
|
@ -66,7 +69,7 @@ class AutomationsApiService {
|
|||
// Whether the search space's models are billable for automations (premium
|
||||
// global or BYOK). Used to gate creation surfaces before submit.
|
||||
getModelEligibility = async (searchSpaceId: number) => {
|
||||
const qs = new URLSearchParams({ search_space_id: String(searchSpaceId) });
|
||||
const qs = new URLSearchParams({ workspace_id: String(searchSpaceId) });
|
||||
return baseApiService.get(`${BASE}/model-eligibility?${qs.toString()}`, modelEligibility);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class ChatCommentsApiService {
|
|||
|
||||
const params = new URLSearchParams();
|
||||
if (parsed.data.search_space_id !== undefined) {
|
||||
params.set("search_space_id", String(parsed.data.search_space_id));
|
||||
params.set("workspace_id", String(parsed.data.search_space_id));
|
||||
}
|
||||
|
||||
const queryString = params.toString();
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class ChatThreadsApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsed.data.search_space_id}/snapshots`,
|
||||
`/api/v1/workspaces/${parsed.data.search_space_id}/snapshots`,
|
||||
publicChatSnapshotsBySpaceResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class ConnectorsApiService {
|
|||
Object.entries(parsedRequest.data.queryParams)
|
||||
.filter(([_, v]) => v !== undefined && v !== null)
|
||||
.map(([k, v]) => {
|
||||
return [k, String(v)];
|
||||
return [k === "search_space_id" ? "workspace_id" : k, String(v)];
|
||||
})
|
||||
)
|
||||
: undefined;
|
||||
|
|
@ -113,7 +113,7 @@ class ConnectorsApiService {
|
|||
Object.entries(queryParams)
|
||||
.filter(([_, v]) => v !== undefined && v !== null)
|
||||
.map(([k, v]) => {
|
||||
return [k, String(v)];
|
||||
return [k === "search_space_id" ? "workspace_id" : k, String(v)];
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ class ConnectorsApiService {
|
|||
Object.entries(queryParams)
|
||||
.filter(([_, v]) => v !== undefined && v !== null)
|
||||
.map(([k, v]) => {
|
||||
return [k, String(v)];
|
||||
return [k === "search_space_id" ? "workspace_id" : k, String(v)];
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -314,7 +314,7 @@ class ConnectorsApiService {
|
|||
const { search_space_id } = request.queryParams;
|
||||
|
||||
const queryString = new URLSearchParams({
|
||||
search_space_id: String(search_space_id),
|
||||
workspace_id: String(search_space_id),
|
||||
}).toString();
|
||||
|
||||
return baseApiService.get<MCPConnectorRead[]>(`/api/v1/connectors/mcp?${queryString}`);
|
||||
|
|
@ -334,7 +334,7 @@ class ConnectorsApiService {
|
|||
const { data, queryParams } = request;
|
||||
|
||||
const queryString = new URLSearchParams({
|
||||
search_space_id: String(queryParams.search_space_id),
|
||||
workspace_id: String(queryParams.search_space_id),
|
||||
}).toString();
|
||||
|
||||
return baseApiService.post<MCPConnectorRead>(
|
||||
|
|
|
|||
|
|
@ -61,11 +61,12 @@ class DocumentsApiService {
|
|||
const transformedQueryParams = parsedRequest.data.queryParams
|
||||
? Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => {
|
||||
const key = k === "search_space_id" ? "workspace_id" : k;
|
||||
// Handle array values (document_type)
|
||||
if (Array.isArray(v)) {
|
||||
return [k, v.join(",")];
|
||||
return [key, v.join(",")];
|
||||
}
|
||||
return [k, String(v)];
|
||||
return [key, String(v)];
|
||||
})
|
||||
)
|
||||
: undefined;
|
||||
|
|
@ -106,8 +107,9 @@ class DocumentsApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
const { search_space_id, ...body } = parsedRequest.data;
|
||||
return baseApiService.post(`/api/v1/documents`, createDocumentResponse, {
|
||||
body: parsedRequest.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -143,7 +145,7 @@ class DocumentsApiService {
|
|||
for (const batch of batches) {
|
||||
const formData = new FormData();
|
||||
for (const file of batch) formData.append("files", file);
|
||||
formData.append("search_space_id", String(search_space_id));
|
||||
formData.append("workspace_id", String(search_space_id));
|
||||
formData.append("use_vision_llm", String(use_vision_llm));
|
||||
formData.append("processing_mode", processing_mode);
|
||||
|
||||
|
|
@ -191,7 +193,7 @@ class DocumentsApiService {
|
|||
|
||||
const { search_space_id, document_ids } = parsedRequest.data.queryParams;
|
||||
const params = new URLSearchParams({
|
||||
search_space_id: String(search_space_id),
|
||||
workspace_id: String(search_space_id),
|
||||
document_ids: document_ids.join(","),
|
||||
});
|
||||
|
||||
|
|
@ -218,11 +220,12 @@ class DocumentsApiService {
|
|||
const transformedQueryParams = parsedRequest.data.queryParams
|
||||
? Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => {
|
||||
const key = k === "search_space_id" ? "workspace_id" : k;
|
||||
// Handle array values (document_type)
|
||||
if (Array.isArray(v)) {
|
||||
return [k, v.join(",")];
|
||||
return [key, v.join(",")];
|
||||
}
|
||||
return [k, String(v)];
|
||||
return [key, String(v)];
|
||||
})
|
||||
)
|
||||
: undefined;
|
||||
|
|
@ -254,7 +257,10 @@ class DocumentsApiService {
|
|||
const transformedQueryParams = Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams)
|
||||
.filter(([, v]) => v !== undefined)
|
||||
.map(([k, v]) => [k, String(v)])
|
||||
.map(([k, v]) => [
|
||||
k === "search_space_id" || k === "workspace_id" ? "workspace_id" : k,
|
||||
String(v),
|
||||
])
|
||||
);
|
||||
|
||||
const queryParams = new URLSearchParams(transformedQueryParams).toString();
|
||||
|
|
@ -268,7 +274,7 @@ class DocumentsApiService {
|
|||
|
||||
getDocumentByVirtualPath = async (request: { search_space_id: number; virtual_path: string }) => {
|
||||
const params = new URLSearchParams({
|
||||
search_space_id: String(request.search_space_id),
|
||||
workspace_id: String(request.search_space_id),
|
||||
virtual_path: request.virtual_path,
|
||||
});
|
||||
return baseApiService.get(
|
||||
|
|
@ -295,7 +301,10 @@ class DocumentsApiService {
|
|||
// Transform query params to be string values
|
||||
const transformedQueryParams = parsedRequest.data.queryParams
|
||||
? Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => [k, String(v)])
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => [
|
||||
k === "search_space_id" ? "workspace_id" : k,
|
||||
String(v),
|
||||
])
|
||||
)
|
||||
: undefined;
|
||||
|
||||
|
|
@ -375,9 +384,10 @@ class DocumentsApiService {
|
|||
}
|
||||
|
||||
const { id, data } = parsedRequest.data;
|
||||
const { search_space_id, ...body } = data;
|
||||
|
||||
return baseApiService.put(`/api/v1/documents/${id}`, updateDocumentResponse, {
|
||||
body: data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -406,8 +416,9 @@ class DocumentsApiService {
|
|||
search_space_id: number;
|
||||
files: { relative_path: string; mtime: number }[];
|
||||
}): Promise<{ files_to_upload: string[] }> => {
|
||||
const { search_space_id, ...rest } = body;
|
||||
return baseApiService.post(`/api/v1/documents/folder-mtime-check`, undefined, {
|
||||
body,
|
||||
body: { ...rest, workspace_id: search_space_id },
|
||||
}) as unknown as { files_to_upload: string[] };
|
||||
};
|
||||
|
||||
|
|
@ -428,7 +439,7 @@ class DocumentsApiService {
|
|||
formData.append("files", file);
|
||||
}
|
||||
formData.append("folder_name", metadata.folder_name);
|
||||
formData.append("search_space_id", String(metadata.search_space_id));
|
||||
formData.append("workspace_id", String(metadata.search_space_id));
|
||||
formData.append("relative_paths", JSON.stringify(metadata.relative_paths));
|
||||
if (metadata.root_folder_id != null) {
|
||||
formData.append("root_folder_id", String(metadata.root_folder_id));
|
||||
|
|
@ -462,8 +473,9 @@ class DocumentsApiService {
|
|||
root_folder_id: number | null;
|
||||
relative_paths: string[];
|
||||
}): Promise<{ deleted_count: number }> => {
|
||||
const { search_space_id, ...rest } = body;
|
||||
return baseApiService.post(`/api/v1/documents/folder-unlink`, undefined, {
|
||||
body,
|
||||
body: { ...rest, workspace_id: search_space_id },
|
||||
}) as unknown as { deleted_count: number };
|
||||
};
|
||||
|
||||
|
|
@ -473,14 +485,15 @@ class DocumentsApiService {
|
|||
root_folder_id: number | null;
|
||||
all_relative_paths: string[];
|
||||
}): Promise<{ deleted_count: number }> => {
|
||||
const { search_space_id, ...rest } = body;
|
||||
return baseApiService.post(`/api/v1/documents/folder-sync-finalize`, undefined, {
|
||||
body,
|
||||
body: { ...rest, workspace_id: search_space_id },
|
||||
}) as unknown as { deleted_count: number };
|
||||
};
|
||||
|
||||
getWatchedFolders = async (searchSpaceId: number) => {
|
||||
return baseApiService.get(
|
||||
`/api/v1/documents/watched-folders?search_space_id=${searchSpaceId}`,
|
||||
`/api/v1/documents/watched-folders?workspace_id=${searchSpaceId}`,
|
||||
folderListResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ class FoldersApiService {
|
|||
`Invalid request: ${parsed.error.issues.map((i) => i.message).join(", ")}`
|
||||
);
|
||||
}
|
||||
return baseApiService.post("/api/v1/folders", folder, { body: parsed.data });
|
||||
const { search_space_id, ...body } = parsed.data;
|
||||
return baseApiService.post("/api/v1/folders", folder, {
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
listFolders = async (searchSpaceId: number) => {
|
||||
return baseApiService.get(
|
||||
`/api/v1/folders?search_space_id=${searchSpaceId}`,
|
||||
folderListResponse
|
||||
);
|
||||
return baseApiService.get(`/api/v1/folders?workspace_id=${searchSpaceId}`, folderListResponse);
|
||||
};
|
||||
|
||||
getFolder = async (folderId: number) => {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const BASE = "/api/v1/image-generations";
|
|||
class ImageGenerationsApiService {
|
||||
list = async (searchSpaceId: number, limit = 100) => {
|
||||
const qs = new URLSearchParams({
|
||||
search_space_id: String(searchSpaceId),
|
||||
workspace_id: String(searchSpaceId),
|
||||
limit: String(limit),
|
||||
}).toString();
|
||||
return baseApiService.get(`${BASE}?${qs}`, imageGenerationList);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class InvitesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.post(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/invites`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/invites`,
|
||||
createInviteResponse,
|
||||
{
|
||||
body: parsedRequest.data.data,
|
||||
|
|
@ -58,7 +58,7 @@ class InvitesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/invites`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/invites`,
|
||||
getInvitesResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -77,7 +77,7 @@ class InvitesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/invites/${parsedRequest.data.invite_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/invites/${parsedRequest.data.invite_id}`,
|
||||
updateInviteResponse,
|
||||
{
|
||||
body: parsedRequest.data.data,
|
||||
|
|
@ -99,7 +99,7 @@ class InvitesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.delete(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/invites/${parsedRequest.data.invite_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/invites/${parsedRequest.data.invite_id}`,
|
||||
deleteInviteResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,11 +36,12 @@ class LogsApiService {
|
|||
const transformedQueryParams = parsedRequest.data.queryParams
|
||||
? Object.fromEntries(
|
||||
Object.entries(parsedRequest.data.queryParams).map(([k, v]) => {
|
||||
const key = k === "search_space_id" ? "workspace_id" : k;
|
||||
// Handle array values (document_type)
|
||||
if (Array.isArray(v)) {
|
||||
return [k, v.join(",")];
|
||||
return [key, v.join(",")];
|
||||
}
|
||||
return [k, String(v)];
|
||||
return [key, String(v)];
|
||||
})
|
||||
)
|
||||
: undefined;
|
||||
|
|
@ -74,8 +75,9 @@ class LogsApiService {
|
|||
const errorMessage = parsedRequest.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
const { search_space_id, ...body } = parsedRequest.data;
|
||||
return baseApiService.post(`/api/v1/logs`, createLogResponse, {
|
||||
body: parsedRequest.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -89,8 +91,9 @@ class LogsApiService {
|
|||
const errorMessage = parsedRequest.error.issues.map((issue) => issue.message).join(", ");
|
||||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
const { search_space_id, ...body } = parsedRequest.data;
|
||||
return baseApiService.put(`/api/v1/logs/${logId}`, updateLogResponse, {
|
||||
body: parsedRequest.data,
|
||||
body: search_space_id === undefined ? body : { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -118,7 +121,7 @@ class LogsApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
const { search_space_id, hours } = parsedRequest.data;
|
||||
const url = `/api/v1/logs/search-space/${search_space_id}/summary${hours ? `?hours=${hours}` : ""}`;
|
||||
const url = `/api/v1/logs/workspaces/${search_space_id}/summary${hours ? `?hours=${hours}` : ""}`;
|
||||
return baseApiService.get(url, getLogSummaryResponse);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class MembersApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/members`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/members`,
|
||||
getMembersResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -52,7 +52,7 @@ class MembersApiService {
|
|||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/members/${parsedRequest.data.membership_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/members/${parsedRequest.data.membership_id}`,
|
||||
updateMembershipResponse,
|
||||
{
|
||||
body: parsedRequest.data.data,
|
||||
|
|
@ -74,7 +74,7 @@ class MembersApiService {
|
|||
}
|
||||
|
||||
return baseApiService.delete(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/members/${parsedRequest.data.membership_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/members/${parsedRequest.data.membership_id}`,
|
||||
deleteMembershipResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -93,7 +93,7 @@ class MembersApiService {
|
|||
}
|
||||
|
||||
return baseApiService.delete(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/members/me`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/members/me`,
|
||||
leaveSearchSpaceResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -112,7 +112,7 @@ class MembersApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/my-access`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/my-access`,
|
||||
getMyAccessResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class ModelConnectionsApiService {
|
|||
|
||||
getConnections = async (searchSpaceId: number): Promise<ConnectionRead[]> => {
|
||||
return baseApiService.get(
|
||||
`/api/v1/model-connections?search_space_id=${searchSpaceId}`,
|
||||
`/api/v1/model-connections?workspace_id=${searchSpaceId}`,
|
||||
connectionListResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -56,8 +56,15 @@ class ModelConnectionsApiService {
|
|||
if (!parsed.success) {
|
||||
throw new ValidationError(parsed.error.issues.map((issue) => issue.message).join(", "));
|
||||
}
|
||||
const { search_space_id, ...body } = parsed.data;
|
||||
if (
|
||||
body.scope === "SEARCH_SPACE" &&
|
||||
(!Number.isFinite(search_space_id) || (search_space_id ?? 0) <= 0)
|
||||
) {
|
||||
throw new ValidationError("workspace_id is required");
|
||||
}
|
||||
return baseApiService.post(`/api/v1/model-connections`, connectionRead, {
|
||||
body: parsed.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -91,11 +98,18 @@ class ModelConnectionsApiService {
|
|||
if (!parsed.success) {
|
||||
throw new ValidationError(parsed.error.issues.map((issue) => issue.message).join(", "));
|
||||
}
|
||||
const { search_space_id, ...body } = parsed.data;
|
||||
if (
|
||||
body.scope === "SEARCH_SPACE" &&
|
||||
(!Number.isFinite(search_space_id) || (search_space_id ?? 0) <= 0)
|
||||
) {
|
||||
throw new ValidationError("workspace_id is required");
|
||||
}
|
||||
return baseApiService.post(
|
||||
`/api/v1/model-connections/discover-preview`,
|
||||
modelPreviewListResponse,
|
||||
{
|
||||
body: parsed.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
@ -107,8 +121,15 @@ class ModelConnectionsApiService {
|
|||
if (!parsed.success) {
|
||||
throw new ValidationError(parsed.error.issues.map((issue) => issue.message).join(", "));
|
||||
}
|
||||
const { search_space_id, ...body } = parsed.data;
|
||||
if (
|
||||
body.scope === "SEARCH_SPACE" &&
|
||||
(!Number.isFinite(search_space_id) || (search_space_id ?? 0) <= 0)
|
||||
) {
|
||||
throw new ValidationError("workspace_id is required");
|
||||
}
|
||||
return baseApiService.post(`/api/v1/model-connections/test-preview`, verifyConnectionResponse, {
|
||||
body: parsed.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -159,11 +180,11 @@ class ModelConnectionsApiService {
|
|||
};
|
||||
|
||||
getModelRoles = async (searchSpaceId: number): Promise<ModelRoles> => {
|
||||
return baseApiService.get(`/api/v1/search-spaces/${searchSpaceId}/model-roles`, modelRoles);
|
||||
return baseApiService.get(`/api/v1/workspaces/${searchSpaceId}/model-roles`, modelRoles);
|
||||
};
|
||||
|
||||
updateModelRoles = async (searchSpaceId: number, roles: ModelRoles): Promise<ModelRoles> => {
|
||||
return baseApiService.put(`/api/v1/search-spaces/${searchSpaceId}/model-roles`, modelRoles, {
|
||||
return baseApiService.put(`/api/v1/workspaces/${searchSpaceId}/model-roles`, modelRoles, {
|
||||
body: roles,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class NotificationsApiService {
|
|||
const params = new URLSearchParams();
|
||||
|
||||
if (queryParams.search_space_id !== undefined) {
|
||||
params.append("search_space_id", String(queryParams.search_space_id));
|
||||
params.append("workspace_id", String(queryParams.search_space_id));
|
||||
}
|
||||
if (queryParams.type) {
|
||||
params.append("type", queryParams.type);
|
||||
|
|
@ -113,7 +113,7 @@ class NotificationsApiService {
|
|||
getSourceTypes = async (searchSpaceId?: number): Promise<GetSourceTypesResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
if (searchSpaceId !== undefined) {
|
||||
params.append("search_space_id", String(searchSpaceId));
|
||||
params.append("workspace_id", String(searchSpaceId));
|
||||
}
|
||||
const queryString = params.toString();
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ class NotificationsApiService {
|
|||
): Promise<GetUnreadCountResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
if (searchSpaceId !== undefined) {
|
||||
params.append("search_space_id", String(searchSpaceId));
|
||||
params.append("workspace_id", String(searchSpaceId));
|
||||
}
|
||||
if (type) {
|
||||
params.append("type", type);
|
||||
|
|
@ -159,7 +159,7 @@ class NotificationsApiService {
|
|||
getBatchUnreadCounts = async (searchSpaceId?: number): Promise<GetBatchUnreadCountResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
if (searchSpaceId !== undefined) {
|
||||
params.append("search_space_id", String(searchSpaceId));
|
||||
params.append("workspace_id", String(searchSpaceId));
|
||||
}
|
||||
const queryString = params.toString();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const voiceOptionList = z.array(voiceOption);
|
|||
class PodcastsApiService {
|
||||
list = async (searchSpaceId: number, limit = 200) => {
|
||||
const qs = new URLSearchParams({
|
||||
search_space_id: String(searchSpaceId),
|
||||
workspace_id: String(searchSpaceId),
|
||||
limit: String(limit),
|
||||
}).toString();
|
||||
return baseApiService.get(`${BASE}?${qs}`, podcastSummaryList);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class PromptsApiService {
|
|||
list = async (searchSpaceId?: number) => {
|
||||
const params = new URLSearchParams();
|
||||
if (searchSpaceId !== undefined) {
|
||||
params.set("search_space_id", String(searchSpaceId));
|
||||
params.set("workspace_id", String(searchSpaceId));
|
||||
}
|
||||
const queryString = params.toString();
|
||||
const url = queryString ? `/api/v1/prompts?${queryString}` : "/api/v1/prompts";
|
||||
|
|
@ -30,8 +30,9 @@ class PromptsApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
const { search_space_id, ...body } = parsed.data;
|
||||
return baseApiService.post("/api/v1/prompts", promptRead, {
|
||||
body: parsed.data,
|
||||
body: { ...body, workspace_id: search_space_id },
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const BASE = "/api/v1/reports";
|
|||
class ReportsApiService {
|
||||
list = async (searchSpaceId: number, limit = 200) => {
|
||||
const qs = new URLSearchParams({
|
||||
search_space_id: String(searchSpaceId),
|
||||
workspace_id: String(searchSpaceId),
|
||||
limit: String(limit),
|
||||
}).toString();
|
||||
return baseApiService.get(`${BASE}?${qs}`, reportList);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class RolesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.post(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/roles`,
|
||||
createRoleResponse,
|
||||
{
|
||||
body: parsedRequest.data.data,
|
||||
|
|
@ -49,7 +49,7 @@ class RolesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/roles`,
|
||||
getRolesResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -65,7 +65,7 @@ class RolesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
getRoleByIdResponse
|
||||
);
|
||||
};
|
||||
|
|
@ -81,7 +81,7 @@ class RolesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
updateRoleResponse,
|
||||
{
|
||||
body: parsedRequest.data.data,
|
||||
|
|
@ -100,7 +100,7 @@ class RolesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.delete(
|
||||
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
`/api/v1/workspaces/${parsedRequest.data.search_space_id}/roles/${parsedRequest.data.role_id}`,
|
||||
deleteRoleResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class SearchSpacesApiService {
|
|||
? new URLSearchParams(transformedQueryParams).toString()
|
||||
: "";
|
||||
|
||||
return baseApiService.get(`/api/v1/searchspaces?${queryParams}`, getSearchSpacesResponse);
|
||||
return baseApiService.get(`/api/v1/workspaces?${queryParams}`, getSearchSpacesResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +66,7 @@ class SearchSpacesApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.post(`/api/v1/searchspaces`, createSearchSpaceResponse, {
|
||||
return baseApiService.post(`/api/v1/workspaces`, createSearchSpaceResponse, {
|
||||
body: parsedRequest.data,
|
||||
});
|
||||
};
|
||||
|
|
@ -84,7 +84,7 @@ class SearchSpacesApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.get(`/api/v1/searchspaces/${request.id}`, getSearchSpaceResponse);
|
||||
return baseApiService.get(`/api/v1/workspaces/${request.id}`, getSearchSpaceResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +100,7 @@ class SearchSpacesApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.put(`/api/v1/searchspaces/${request.id}`, updateSearchSpaceResponse, {
|
||||
return baseApiService.put(`/api/v1/workspaces/${request.id}`, updateSearchSpaceResponse, {
|
||||
body: parsedRequest.data.data,
|
||||
});
|
||||
};
|
||||
|
|
@ -115,7 +115,7 @@ class SearchSpacesApiService {
|
|||
}
|
||||
|
||||
return baseApiService.put(
|
||||
`/api/v1/searchspaces/${request.id}/api-access`,
|
||||
`/api/v1/workspaces/${request.id}/api-access`,
|
||||
updateSearchSpaceApiAccessResponse,
|
||||
{
|
||||
body: { api_access_enabled: parsedRequest.data.api_access_enabled },
|
||||
|
|
@ -136,7 +136,7 @@ class SearchSpacesApiService {
|
|||
throw new ValidationError(`Invalid request: ${errorMessage}`);
|
||||
}
|
||||
|
||||
return baseApiService.delete(`/api/v1/searchspaces/${request.id}`, deleteSearchSpaceResponse);
|
||||
return baseApiService.delete(`/api/v1/workspaces/${request.id}`, deleteSearchSpaceResponse);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -144,7 +144,7 @@ class SearchSpacesApiService {
|
|||
*/
|
||||
triggerAiSort = async (searchSpaceId: number) => {
|
||||
return baseApiService.post(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/ai-sort`,
|
||||
`/api/v1/workspaces/${searchSpaceId}/ai-sort`,
|
||||
z.object({ message: z.string() }),
|
||||
{}
|
||||
);
|
||||
|
|
@ -156,7 +156,7 @@ class SearchSpacesApiService {
|
|||
*/
|
||||
leaveSearchSpace = async (searchSpaceId: number) => {
|
||||
return baseApiService.delete(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/members/me`,
|
||||
`/api/v1/workspaces/${searchSpaceId}/members/me`,
|
||||
leaveSearchSpaceResponse
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ class StripeApiService {
|
|||
createCreditCheckoutSession = async (
|
||||
request: CreateCreditCheckoutSessionRequest
|
||||
): Promise<CreateCreditCheckoutSessionResponse> => {
|
||||
const { search_space_id, ...body } = request;
|
||||
return baseApiService.post(
|
||||
"/api/v1/stripe/create-credit-checkout-session",
|
||||
createCreditCheckoutSessionResponse,
|
||||
{ body: request }
|
||||
{ body: { ...body, workspace_id: search_space_id } }
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -74,10 +75,11 @@ class StripeApiService {
|
|||
createAutoReloadSetupSession = async (
|
||||
request: CreateAutoReloadSetupSessionRequest
|
||||
): Promise<CreateAutoReloadSetupSessionResponse> => {
|
||||
const { search_space_id } = request;
|
||||
return baseApiService.post(
|
||||
"/api/v1/stripe/auto-reload/setup",
|
||||
createAutoReloadSetupSessionResponse,
|
||||
{ body: request }
|
||||
{ body: { workspace_id: search_space_id } }
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const BASE = "/api/v1/video-presentations";
|
|||
class VideoPresentationsApiService {
|
||||
list = async (searchSpaceId: number, limit = 200) => {
|
||||
const qs = new URLSearchParams({
|
||||
search_space_id: String(searchSpaceId),
|
||||
workspace_id: String(searchSpaceId),
|
||||
limit: String(limit),
|
||||
}).toString();
|
||||
return baseApiService.get(`${BASE}?${qs}`, videoPresentationList);
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ export async function fetchThreads(
|
|||
searchSpaceId: number,
|
||||
limit?: number
|
||||
): Promise<ThreadListResponse> {
|
||||
const params = new URLSearchParams({ search_space_id: String(searchSpaceId) });
|
||||
const params = new URLSearchParams({ workspace_id: String(searchSpaceId) });
|
||||
if (limit) params.append("limit", String(limit));
|
||||
return baseApiService.get<ThreadListResponse>(`/api/v1/threads?${params}`);
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ export async function searchThreads(
|
|||
title: string
|
||||
): Promise<ThreadListItem[]> {
|
||||
const params = new URLSearchParams({
|
||||
search_space_id: String(searchSpaceId),
|
||||
workspace_id: String(searchSpaceId),
|
||||
title,
|
||||
});
|
||||
return baseApiService.get<ThreadListItem[]>(`/api/v1/threads/search?${params}`);
|
||||
|
|
@ -125,7 +125,7 @@ export async function createThread(
|
|||
body: {
|
||||
title,
|
||||
archived: false,
|
||||
search_space_id: searchSpaceId,
|
||||
workspace_id: searchSpaceId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
11
surfsense_web/lib/route-params.ts
Normal file
11
surfsense_web/lib/route-params.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
type RouteParams = Record<string, string | string[] | undefined>;
|
||||
|
||||
export function getWorkspaceIdParam(params: RouteParams | null | undefined): string | undefined {
|
||||
const value = params?.workspace_id ?? params?.search_space_id;
|
||||
return Array.isArray(value) ? value[0] : value;
|
||||
}
|
||||
|
||||
export function getWorkspaceIdNumber(params: RouteParams | null | undefined): number | undefined {
|
||||
const parsed = Number(getWorkspaceIdParam(params));
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue