Skip to content
Open
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 @@ -14,6 +14,9 @@ import type {
SignalReportStatus,
SignalReportsQueryParams,
SignalReportsResponse,
SignalReportTask,
SignalTeamConfig,
SignalUserAutonomyConfig,
SuggestedReviewersArtefact,
Task,
TaskRun,
Expand Down Expand Up @@ -409,7 +412,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 @@ -436,7 +439,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 @@ -463,7 +466,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 @@ -1181,7 +1184,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 @@ -1206,7 +1209,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 @@ -1223,9 +1226,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 @@ -1251,9 +1254,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 @@ -1280,12 +1283,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 @@ -1312,9 +1315,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 @@ -1379,9 +1382,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 @@ -1406,9 +1409,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 @@ -1433,9 +1436,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 @@ -1454,6 +1457,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
Loading
Loading