feat: implement ensure_publication for zero_publication management

- Added the ensure_publication function to create and verify the zero_publication if it is missing, ensuring idempotency during database initialization.
- Integrated ensure_publication into the create_db_and_tables function to prevent zero-cache crash loops on startup.
- Introduced a self-check script to validate the ensure_publication functionality on a create_all-bootstrapped database.
- Updated various components to reflect the transition from search space to workspace, including adjustments in imports and routing paths.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-07-05 23:17:13 -07:00
parent 7562bc78ee
commit a64c8205fe
164 changed files with 626 additions and 506 deletions

View file

@ -5,7 +5,7 @@ const AgentActionReadSchema = z.object({
id: z.number(),
thread_id: z.number(),
user_id: z.string().nullable(),
search_space_id: z.number(),
workspace_id: z.number(),
tool_name: z.string(),
args: z.record(z.string(), z.unknown()).nullable(),
result_id: z.string().nullable(),

View file

@ -7,7 +7,7 @@ export type AgentPermissionAction = z.infer<typeof ActionEnum>;
const AgentPermissionRuleSchema = z.object({
id: z.number(),
search_space_id: z.number(),
workspace_id: z.number(),
user_id: z.string().nullable(),
thread_id: z.number().nullable(),
permission: z.string(),
@ -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}`
);
};
}

View file

@ -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.workspace_id),
limit: String(params.limit),
offset: String(params.offset),
});
@ -66,7 +66,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);
};

View file

@ -139,8 +139,8 @@ class ChatCommentsApiService {
}
const params = new URLSearchParams();
if (parsed.data.search_space_id !== undefined) {
params.set("search_space_id", String(parsed.data.search_space_id));
if (parsed.data.workspace_id !== undefined) {
params.set("workspace_id", String(parsed.data.workspace_id));
}
const queryString = params.toString();

View file

@ -86,7 +86,7 @@ class ChatThreadsApiService {
}
return baseApiService.get(
`/api/v1/searchspaces/${parsed.data.search_space_id}/snapshots`,
`/api/v1/workspaces/${parsed.data.workspace_id}/snapshots`,
publicChatSnapshotsBySpaceResponse
);
};

View file

@ -311,10 +311,10 @@ class ConnectorsApiService {
* Get all MCP connectors for a search space
*/
getMCPConnectors = async (request: GetMCPConnectorsRequest) => {
const { search_space_id } = request.queryParams;
const { workspace_id } = request.queryParams;
const queryString = new URLSearchParams({
search_space_id: String(search_space_id),
workspace_id: String(workspace_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.workspace_id),
}).toString();
return baseApiService.post<MCPConnectorRead>(

View file

@ -126,7 +126,7 @@ class DocumentsApiService {
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
const { files, search_space_id, use_vision_llm, processing_mode } = parsedRequest.data;
const { files, workspace_id, use_vision_llm, processing_mode } = parsedRequest.data;
const UPLOAD_BATCH_SIZE = 5;
const batches: File[][] = [];
@ -143,7 +143,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(workspace_id));
formData.append("use_vision_llm", String(use_vision_llm));
formData.append("processing_mode", processing_mode);
@ -189,9 +189,9 @@ class DocumentsApiService {
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
const { search_space_id, document_ids } = parsedRequest.data.queryParams;
const { workspace_id, document_ids } = parsedRequest.data.queryParams;
const params = new URLSearchParams({
search_space_id: String(search_space_id),
workspace_id: String(workspace_id),
document_ids: document_ids.join(","),
});
@ -266,9 +266,9 @@ class DocumentsApiService {
);
};
getDocumentByVirtualPath = async (request: { search_space_id: number; virtual_path: string }) => {
getDocumentByVirtualPath = async (request: { workspace_id: number; virtual_path: string }) => {
const params = new URLSearchParams({
search_space_id: String(request.search_space_id),
workspace_id: String(request.workspace_id),
virtual_path: request.virtual_path,
});
return baseApiService.get(
@ -403,7 +403,7 @@ class DocumentsApiService {
folderMtimeCheck = async (body: {
folder_name: string;
search_space_id: number;
workspace_id: number;
files: { relative_path: string; mtime: number }[];
}): Promise<{ files_to_upload: string[] }> => {
return baseApiService.post(`/api/v1/documents/folder-mtime-check`, undefined, {
@ -415,7 +415,7 @@ class DocumentsApiService {
files: File[],
metadata: {
folder_name: string;
search_space_id: number;
workspace_id: number;
relative_paths: string[];
root_folder_id?: number | null;
use_vision_llm?: boolean;
@ -428,7 +428,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.workspace_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));
@ -458,7 +458,7 @@ class DocumentsApiService {
folderNotifyUnlinked = async (body: {
folder_name: string;
search_space_id: number;
workspace_id: number;
root_folder_id: number | null;
relative_paths: string[];
}): Promise<{ deleted_count: number }> => {
@ -469,7 +469,7 @@ class DocumentsApiService {
folderSyncFinalize = async (body: {
folder_name: string;
search_space_id: number;
workspace_id: number;
root_folder_id: number | null;
all_relative_paths: string[];
}): Promise<{ deleted_count: number }> => {
@ -480,7 +480,7 @@ class DocumentsApiService {
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
);
};

View file

@ -31,10 +31,7 @@ class FoldersApiService {
};
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) => {

View file

@ -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);

View file

@ -36,7 +36,7 @@ class InvitesApiService {
}
return baseApiService.post(
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/invites`,
`/api/v1/workspaces/${parsedRequest.data.workspace_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.workspace_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.workspace_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.workspace_id}/invites/${parsedRequest.data.invite_id}`,
deleteInviteResponse
);
};

View file

@ -117,8 +117,8 @@ class LogsApiService {
const errorMessage = parsedRequest.error.issues.map((issue) => issue.message).join(", ");
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 { workspace_id, hours } = parsedRequest.data;
const url = `/api/v1/logs/workspaces/${workspace_id}/summary${hours ? `?hours=${hours}` : ""}`;
return baseApiService.get(url, getLogSummaryResponse);
};
}

View file

@ -33,7 +33,7 @@ class MembersApiService {
}
return baseApiService.get(
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/members`,
`/api/v1/workspaces/${parsedRequest.data.workspace_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.workspace_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.workspace_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.workspace_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.workspace_id}/my-access`,
getMyAccessResponse
);
};

View file

@ -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
);
};
@ -159,11 +159,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,
});
};

View file

@ -41,8 +41,8 @@ class NotificationsApiService {
// Build query string from params
const params = new URLSearchParams();
if (queryParams.search_space_id !== undefined) {
params.append("search_space_id", String(queryParams.search_space_id));
if (queryParams.workspace_id !== undefined) {
params.append("workspace_id", String(queryParams.workspace_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();

View file

@ -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);

View file

@ -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";

View file

@ -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);

View file

@ -30,7 +30,7 @@ class RolesApiService {
}
return baseApiService.post(
`/api/v1/searchspaces/${parsedRequest.data.search_space_id}/roles`,
`/api/v1/workspaces/${parsedRequest.data.workspace_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.workspace_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.workspace_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.workspace_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.workspace_id}/roles/${parsedRequest.data.role_id}`,
deleteRoleResponse
);
};

View file

@ -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);

View file

@ -19,7 +19,7 @@ import {
updateSearchSpaceApiAccessResponse,
updateSearchSpaceRequest,
updateSearchSpaceResponse,
} from "@/contracts/types/search-space.types";
} from "@/contracts/types/workspace.types";
import { ValidationError } from "../error";
import { baseApiService } from "./base-api.service";
@ -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
);
};

View file

@ -271,7 +271,7 @@ export function buildCreatePayload(
): AutomationCreateRequest {
const trigger = buildScheduleTrigger(form);
return {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
name: form.name.trim(),
description: form.description?.trim() ? form.description.trim() : null,
definition: buildDefinition(form),

View file

@ -20,7 +20,7 @@ export interface ThreadRecord {
archived: boolean;
visibility: ChatVisibility;
created_by_id: string | null;
search_space_id: number;
workspace_id: number;
created_at: string;
updated_at: string;
has_comments?: boolean;
@ -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,
},
});
}

View file

@ -95,7 +95,7 @@ async function uploadBatchesWithConcurrency(
files,
{
folder_name: params.folderName,
search_space_id: params.searchSpaceId,
workspace_id: params.searchSpaceId,
relative_paths: batch.map((e) => e.relativePath),
root_folder_id: resolvedRootFolderId,
processing_mode: params.processingMode,
@ -169,7 +169,7 @@ export async function uploadFolderScan(params: FolderSyncParams): Promise<number
const mtimeCheckResult = await documentsApiService.folderMtimeCheck({
folder_name: folderName,
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
files: allFiles.map((f) => ({ relative_path: f.relativePath, mtime: f.mtimeMs / 1000 })),
});
@ -214,7 +214,7 @@ export async function uploadFolderScan(params: FolderSyncParams): Promise<number
await documentsApiService.folderSyncFinalize({
folder_name: folderName,
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
root_folder_id: rootFolderId ?? null,
all_relative_paths: allFiles.map((f) => f.relativePath),
});

View file

@ -80,20 +80,20 @@ export function trackLogout() {
export function trackSearchSpaceCreated(searchSpaceId: number, name: string) {
safeCapture("search_space_created", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
name,
});
}
export function trackSearchSpaceDeleted(searchSpaceId: number) {
safeCapture("search_space_deleted", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
});
}
export function trackSearchSpaceViewed(searchSpaceId: number) {
safeCapture("search_space_viewed", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
});
}
@ -103,7 +103,7 @@ export function trackSearchSpaceViewed(searchSpaceId: number) {
export function trackChatCreated(searchSpaceId: number, chatId: number) {
safeCapture("chat_created", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId,
});
}
@ -118,7 +118,7 @@ export function trackChatMessageSent(
}
) {
safeCapture("chat_message_sent", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId,
has_attachments: options?.hasAttachments ?? false,
has_mentioned_documents: options?.hasMentionedDocuments ?? false,
@ -128,14 +128,14 @@ export function trackChatMessageSent(
export function trackChatResponseReceived(searchSpaceId: number, chatId: number) {
safeCapture("chat_response_received", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId,
});
}
export function trackChatError(searchSpaceId: number, chatId: number, error?: string) {
safeCapture("chat_error", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId,
error,
});
@ -158,7 +158,7 @@ export function trackChatBlocked(
safeCapture(
"chat_blocked",
compact({
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId ?? undefined,
flow: payload.flow,
kind: payload.kind,
@ -178,7 +178,7 @@ export function trackChatErrorDetailed(
safeCapture(
"chat_error",
compact({
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId ?? undefined,
flow: payload.flow,
kind: payload.kind,
@ -220,7 +220,7 @@ export function trackDocumentUploadStarted(
totalSizeBytes: number
) {
safeCapture("document_upload_started", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
file_count: fileCount,
total_size_bytes: totalSizeBytes,
});
@ -228,35 +228,35 @@ export function trackDocumentUploadStarted(
export function trackDocumentUploadSuccess(searchSpaceId: number, fileCount: number) {
safeCapture("document_upload_success", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
file_count: fileCount,
});
}
export function trackDocumentUploadFailure(searchSpaceId: number, error?: string) {
safeCapture("document_upload_failure", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
error,
});
}
export function trackDocumentDeleted(searchSpaceId: number, documentId: number) {
safeCapture("document_deleted", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
document_id: documentId,
});
}
export function trackDocumentBulkDeleted(searchSpaceId: number, count: number) {
safeCapture("document_bulk_deleted", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
count,
});
}
export function trackYouTubeImport(searchSpaceId: number, url: string) {
safeCapture("youtube_import_started", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
url,
});
}
@ -303,7 +303,7 @@ export function trackConnectorEvent(
const meta = getConnectorTelemetryMeta(connectorType);
safeCapture(`connector_${stage}`, {
...compact({
search_space_id: options.searchSpaceId ?? undefined,
workspace_id: options.searchSpaceId ?? undefined,
connector_id: options.connectorId ?? undefined,
source: options.source,
error: options.error,
@ -369,14 +369,14 @@ export function trackConnectorSynced(
export function trackSettingsViewed(searchSpaceId: number, section: string) {
safeCapture("settings_viewed", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
section,
});
}
export function trackSettingsUpdated(searchSpaceId: number, section: string, setting: string) {
safeCapture("settings_updated", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
section,
setting,
});
@ -388,14 +388,14 @@ export function trackSettingsUpdated(searchSpaceId: number, section: string, set
export function trackPodcastGenerated(searchSpaceId: number, chatId: number) {
safeCapture("podcast_generated", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
chat_id: chatId,
});
}
export function trackSourcesTabViewed(searchSpaceId: number, tab: string) {
safeCapture("sources_tab_viewed", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
tab,
});
}
@ -423,7 +423,7 @@ export function trackSearchSpaceInviteSent(
}
) {
safeCapture("search_space_invite_sent", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
role_name: options?.roleName,
has_expiry: options?.hasExpiry ?? false,
has_max_uses: options?.hasMaxUses ?? false,
@ -436,7 +436,7 @@ export function trackSearchSpaceInviteAccepted(
roleName?: string | null
) {
safeCapture("search_space_invite_accepted", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
search_space_name: searchSpaceName,
role_name: roleName,
});
@ -454,7 +454,7 @@ export function trackSearchSpaceUserAdded(
roleName?: string | null
) {
safeCapture("search_space_user_added", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
search_space_name: searchSpaceName,
role_name: roleName,
});
@ -466,7 +466,7 @@ export function trackSearchSpaceUsersViewed(
ownerCount: number
) {
safeCapture("search_space_users_viewed", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
user_count: userCount,
owner_count: ownerCount,
});
@ -497,7 +497,7 @@ export function trackIndexWithDateRangeOpened(
connectorId: number
) {
safeCapture("index_with_date_range_opened", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
connector_type: connectorType,
connector_id: connectorId,
});
@ -513,7 +513,7 @@ export function trackIndexWithDateRangeStarted(
}
) {
safeCapture("index_with_date_range_started", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
connector_type: connectorType,
connector_id: connectorId,
has_start_date: options?.hasStartDate ?? false,
@ -527,7 +527,7 @@ export function trackQuickIndexClicked(
connectorId: number
) {
safeCapture("quick_index_clicked", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
connector_type: connectorType,
connector_id: connectorId,
});
@ -539,7 +539,7 @@ export function trackConfigurePeriodicIndexingOpened(
connectorId: number
) {
safeCapture("configure_periodic_indexing_opened", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
connector_type: connectorType,
connector_id: connectorId,
});
@ -552,7 +552,7 @@ export function trackPeriodicIndexingStarted(
frequencyMinutes: number
) {
safeCapture("periodic_indexing_started", {
search_space_id: searchSpaceId,
workspace_id: searchSpaceId,
connector_type: connectorType,
connector_id: connectorId,
frequency_minutes: frequencyMinutes,
@ -602,7 +602,7 @@ export function trackReferralLanding(refCode: string, landingUrl: string) {
// ============================================
interface AutomationCreatedProps {
search_space_id: number;
workspace_id: number;
automation_id: number;
task_count?: number;
trigger_type?: string;
@ -617,13 +617,13 @@ export function trackAutomationCreated(props: AutomationCreatedProps) {
safeCapture("automation_created", compact(props));
}
export function trackAutomationCreateFailed(props: { search_space_id?: number; error?: string }) {
export function trackAutomationCreateFailed(props: { workspace_id?: number; error?: string }) {
safeCapture("automation_create_failed", compact(props));
}
export function trackAutomationUpdated(props: {
automation_id: number;
search_space_id?: number;
workspace_id?: number;
has_definition_change?: boolean;
has_name_change?: boolean;
has_description_change?: boolean;
@ -634,7 +634,7 @@ export function trackAutomationUpdated(props: {
export function trackAutomationStatusChanged(props: {
automation_id: number;
search_space_id?: number;
workspace_id?: number;
next_status: string;
}) {
safeCapture("automation_status_changed", compact(props));
@ -644,7 +644,7 @@ export function trackAutomationUpdateFailed(props: { automation_id: number; erro
safeCapture("automation_update_failed", compact(props));
}
export function trackAutomationDeleted(props: { automation_id: number; search_space_id?: number }) {
export function trackAutomationDeleted(props: { automation_id: number; workspace_id?: number }) {
safeCapture("automation_deleted", compact(props));
}
@ -699,7 +699,7 @@ export function trackAutomationTriggerRemoveFailed(props: {
}
interface AutomationChatDecisionProps {
search_space_id?: number;
workspace_id?: number;
edited?: boolean;
task_count?: number;
trigger_type?: string;
@ -712,25 +712,25 @@ export function trackAutomationChatApproved(props: AutomationChatDecisionProps)
safeCapture("automation_chat_approved", compact(props));
}
export function trackAutomationChatRejected(props: { search_space_id?: number }) {
export function trackAutomationChatRejected(props: { workspace_id?: number }) {
safeCapture("automation_chat_rejected", compact(props));
}
export function trackAutomationChatDraftEdited(props: { search_space_id?: number }) {
export function trackAutomationChatDraftEdited(props: { workspace_id?: number }) {
safeCapture("automation_chat_draft_edited", compact(props));
}
export function trackAutomationChatCreateSucceeded(props: {
automation_id: number;
name?: string;
search_space_id?: number;
workspace_id?: number;
}) {
safeCapture("automation_chat_create_succeeded", compact(props));
}
export function trackAutomationChatCreateFailed(props: {
reason: "invalid" | "error";
search_space_id?: number;
workspace_id?: number;
issue_count?: number;
message?: string;
}) {

View file

@ -1,7 +1,7 @@
import type { GetConnectorsRequest } from "@/contracts/types/connector.types";
import type { GetDocumentsRequest } from "@/contracts/types/document.types";
import type { GetLogsRequest } from "@/contracts/types/log.types";
import type { GetSearchSpacesRequest } from "@/contracts/types/search-space.types";
import type { GetSearchSpacesRequest } from "@/contracts/types/workspace.types";
/**
* Convert an object to a stable array of [key, value] pairs sorted by key.