Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 153 additions & 19 deletions apps/code/src/renderer/api/posthogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import type {
SignalReportStatus,
SignalReportsQueryParams,
SignalReportsResponse,
SignalReportTask,
SignalTeamConfig,
SignalUserAutonomyConfig,
SuggestedReviewersArtefact,
Task,
TaskRun,
Expand Down Expand Up @@ -412,7 +415,7 @@ export class PostHogAPIClient {
async listSignalSourceConfigs(
projectId: number,
): Promise<SignalSourceConfig[]> {
const urlPath = `/api/projects/${projectId}/signal_source_configs/`;
const urlPath = `/api/projects/${projectId}/signals/source_configs/`;
const url = new URL(`${this.api.baseUrl}${urlPath}`);
const response = await this.api.fetcher.fetch({
method: "get",
Expand All @@ -439,7 +442,7 @@ export class PostHogAPIClient {
config?: Record<string, unknown>;
},
): Promise<SignalSourceConfig> {
const urlPath = `/api/projects/${projectId}/signal_source_configs/`;
const urlPath = `/api/projects/${projectId}/signals/source_configs/`;
const url = new URL(`${this.api.baseUrl}${urlPath}`);
const response = await this.api.fetcher.fetch({
method: "post",
Expand All @@ -466,7 +469,7 @@ export class PostHogAPIClient {
configId: string,
updates: { enabled: boolean },
): Promise<SignalSourceConfig> {
const urlPath = `/api/projects/${projectId}/signal_source_configs/${configId}/`;
const urlPath = `/api/projects/${projectId}/signals/source_configs/${configId}/`;
const url = new URL(`${this.api.baseUrl}${urlPath}`);
const response = await this.api.fetcher.fetch({
method: "patch",
Expand Down Expand Up @@ -1212,7 +1215,7 @@ export class PostHogAPIClient {
): Promise<SignalReportsResponse> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/`,
);

if (params?.limit != null) {
Expand All @@ -1237,7 +1240,7 @@ export class PostHogAPIClient {
const response = await this.api.fetcher.fetch({
method: "get",
url,
path: `/api/projects/${teamId}/signal_reports/`,
path: `/api/projects/${teamId}/signals/reports/`,
});

if (!response.ok) {
Expand All @@ -1254,9 +1257,9 @@ export class PostHogAPIClient {
async getSignalProcessingState(): Promise<SignalProcessingStateResponse> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_processing/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/processing/`,
);
const path = `/api/projects/${teamId}/signal_processing/`;
const path = `/api/projects/${teamId}/signals/processing/`;

const response = await this.api.fetcher.fetch({
method: "get",
Expand All @@ -1282,9 +1285,9 @@ export class PostHogAPIClient {
): Promise<AvailableSuggestedReviewersResponse> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/available_reviewers/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/available_reviewers/`,
);
const path = `/api/projects/${teamId}/signal_reports/available_reviewers/`;
const path = `/api/projects/${teamId}/signals/reports/available_reviewers/`;

if (query?.trim()) {
url.searchParams.set("query", query.trim());
Expand All @@ -1311,12 +1314,12 @@ export class PostHogAPIClient {
try {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/${reportId}/signals/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/signals/`,
);
const response = await this.api.fetcher.fetch({
method: "get",
url,
path: `/api/projects/${teamId}/signal_reports/${reportId}/signals/`,
path: `/api/projects/${teamId}/signals/reports/${reportId}/signals/`,
});

if (!response.ok) {
Expand All @@ -1343,9 +1346,9 @@ export class PostHogAPIClient {
): Promise<SignalReportArtefactsResponse> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/${reportId}/artefacts/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/artefacts/`,
);
const path = `/api/projects/${teamId}/signal_reports/${reportId}/artefacts/`;
const path = `/api/projects/${teamId}/signals/reports/${reportId}/artefacts/`;

try {
const response = await this.api.fetcher.fetch({
Expand Down Expand Up @@ -1410,9 +1413,9 @@ export class PostHogAPIClient {
): Promise<SignalReport> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/${reportId}/state/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/state/`,
);
const path = `/api/projects/${teamId}/signal_reports/${reportId}/state/`;
const path = `/api/projects/${teamId}/signals/reports/${reportId}/state/`;

const response = await this.api.fetcher.fetch({
method: "post",
Expand All @@ -1437,9 +1440,9 @@ export class PostHogAPIClient {
}> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/${reportId}/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/`,
);
const path = `/api/projects/${teamId}/signal_reports/${reportId}/`;
const path = `/api/projects/${teamId}/signals/reports/${reportId}/`;

const response = await this.api.fetcher.fetch({
method: "delete",
Expand All @@ -1464,9 +1467,9 @@ export class PostHogAPIClient {
}> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signal_reports/${reportId}/reingest/`,
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/reingest/`,
);
const path = `/api/projects/${teamId}/signal_reports/${reportId}/reingest/`;
const path = `/api/projects/${teamId}/signals/reports/${reportId}/reingest/`;

const response = await this.api.fetcher.fetch({
method: "post",
Expand All @@ -1485,6 +1488,137 @@ export class PostHogAPIClient {
};
}

async getSignalReportTasks(
reportId: string,
options?: { relationship?: SignalReportTask["relationship"] },
): Promise<SignalReportTask[]> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signals/reports/${reportId}/tasks/`,
);
if (options?.relationship) {
url.searchParams.set("relationship", options.relationship);
}
const path = `/api/projects/${teamId}/signals/reports/${reportId}/tasks/`;

const response = await this.api.fetcher.fetch({
method: "get",
url,
path,
});

if (!response.ok) {
throw new Error(
`Failed to fetch signal report tasks: ${response.statusText}`,
);
}

const data = await response.json();
return data.results ?? [];
}

async getSignalTeamConfig(): Promise<SignalTeamConfig> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signals/config/`,
);
const path = `/api/projects/${teamId}/signals/config/`;

const response = await this.api.fetcher.fetch({
method: "get",
url,
path,
});

if (!response.ok) {
throw new Error(
`Failed to fetch signal team config: ${response.statusText}`,
);
}

return (await response.json()) as SignalTeamConfig;
}

async updateSignalTeamConfig(updates: {
default_autostart_priority: string;
}): Promise<SignalTeamConfig> {
const teamId = await this.getTeamId();
const url = new URL(
`${this.api.baseUrl}/api/projects/${teamId}/signals/config/`,
);
const path = `/api/projects/${teamId}/signals/config/`;

const response = await this.api.fetcher.fetch({
method: "post",
url,
path,
overrides: {
body: JSON.stringify(updates),
},
});

if (!response.ok) {
throw new Error(
`Failed to update signal team config: ${response.statusText}`,
);
}

return (await response.json()) as SignalTeamConfig;
}

async getSignalUserAutonomyConfig(): Promise<SignalUserAutonomyConfig | null> {
const url = new URL(`${this.api.baseUrl}/api/users/@me/signal_autonomy/`);
const path = "/api/users/@me/signal_autonomy/";

const response = await this.api.fetcher.fetch({
method: "get",
url,
path,
});

return (await response.json()) as SignalUserAutonomyConfig;
}

async updateSignalUserAutonomyConfig(updates: {
autostart_priority: string | null;
}): Promise<SignalUserAutonomyConfig> {
const url = new URL(`${this.api.baseUrl}/api/users/@me/signal_autonomy/`);
const path = "/api/users/@me/signal_autonomy/";

const response = await this.api.fetcher.fetch({
method: "post",
url,
path,
overrides: {
body: JSON.stringify(updates),
},
});

if (!response.ok) {
throw new Error(
`Failed to update signal user autonomy config: ${response.statusText}`,
);
}
return (await response.json()) as SignalUserAutonomyConfig;
}

async deleteSignalUserAutonomyConfig(): Promise<void> {
const url = new URL(`${this.api.baseUrl}/api/users/@me/signal_autonomy/`);
const path = "/api/users/@me/signal_autonomy/";

const response = await this.api.fetcher.fetch({
method: "delete",
url,
path,
});

if (!response.ok) {
throw new Error(
`Failed to delete signal user autonomy config: ${response.statusText}`,
);
}
}

async getMcpServers(): Promise<McpRecommendedServer[]> {
const teamId = await this.getTeamId();
const url = new URL(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ interface SignalSourceToggleCardProps {
onSetup?: () => void;
loading?: boolean;
statusSection?: React.ReactNode;
syncStatus?: string | null;
}

function syncStatusLabel(status: string | null | undefined): {
text: string;
color: string;
} | null {
if (!status) return null;
switch (status) {
case "running":
return { text: "Syncing…", color: "var(--amber-11)" };
case "completed":
return { text: "Synced", color: "var(--green-11)" };
case "failed":
return { text: "Sync failed", color: "var(--red-11)" };
default:
return null;
}
}

const SignalSourceToggleCard = memo(function SignalSourceToggleCard({
Expand All @@ -61,7 +79,10 @@ const SignalSourceToggleCard = memo(function SignalSourceToggleCard({
onSetup,
loading,
statusSection,
syncStatus,
}: SignalSourceToggleCardProps) {
const statusInfo = checked ? syncStatusLabel(syncStatus) : null;

return (
<Box
p="4"
Expand Down Expand Up @@ -92,6 +113,11 @@ const SignalSourceToggleCard = memo(function SignalSourceToggleCard({
{label}
</Text>
{labelSuffix}
{statusInfo && (
<Text size="1" style={{ color: statusInfo.color }}>
{statusInfo.text}
</Text>
)}
</Flex>
<Text size="1" style={{ color: "var(--gray-11)" }}>
{description}
Expand Down Expand Up @@ -276,7 +302,7 @@ interface SignalSourceTogglesProps {
sourceStates?: Partial<
Record<
keyof SignalSourceValues,
{ requiresSetup: boolean; loading: boolean }
{ requiresSetup: boolean; loading: boolean; syncStatus?: string | null }
>
>;
sessionAnalysisStatus?: SignalSourceConfig["status"];
Expand Down Expand Up @@ -334,6 +360,7 @@ export function SignalSourceToggles({
checked={value.error_tracking}
onCheckedChange={toggleErrorTracking}
disabled={disabled}
syncStatus={sourceStates?.error_tracking?.syncStatus}
/>
<SignalSourceToggleCard
icon={<ChatsIcon size={20} />}
Expand Down Expand Up @@ -386,6 +413,7 @@ export function SignalSourceToggles({
requiresSetup={sourceStates?.github?.requiresSetup}
onSetup={setupGithub}
loading={sourceStates?.github?.loading}
syncStatus={sourceStates?.github?.syncStatus}
/>
<SignalSourceToggleCard
icon={<KanbanIcon size={20} />}
Expand All @@ -397,6 +425,7 @@ export function SignalSourceToggles({
requiresSetup={sourceStates?.linear?.requiresSetup}
onSetup={setupLinear}
loading={sourceStates?.linear?.loading}
syncStatus={sourceStates?.linear?.syncStatus}
/>
<SignalSourceToggleCard
icon={<TicketIcon size={20} />}
Expand All @@ -408,6 +437,7 @@ export function SignalSourceToggles({
requiresSetup={sourceStates?.zendesk?.requiresSetup}
onSetup={setupZendesk}
loading={sourceStates?.zendesk?.loading}
syncStatus={sourceStates?.zendesk?.syncStatus}
/>
</Flex>
);
Expand Down
Loading
Loading