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
3 changes: 0 additions & 3 deletions apps/code/src/main/di/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { readFile as fsReadFile, stat as fsStat } from "node:fs/promises";
import { TypedContainer } from "@inversifyjs/strongly-typed";
import { DEFAULT_GATEWAY_MODEL } from "@posthog/agent/gateway-models";
import {
getGatewayInvalidatePlanCacheUrl,
getGatewayUsageUrl,
getLlmGatewayUrl,
} from "@posthog/agent/posthog-api";
Expand Down Expand Up @@ -491,8 +490,6 @@ container.bind(LLM_GATEWAY_HOST).toDynamicValue((ctx) => {
messagesUrl: (apiHost: string) =>
`${getLlmGatewayUrl(apiHost)}/v1/messages`,
usageUrl: (apiHost: string) => getGatewayUsageUrl(apiHost),
invalidatePlanCacheUrl: (apiHost: string) =>
getGatewayInvalidatePlanCacheUrl(apiHost),
defaultModel: DEFAULT_GATEWAY_MODEL,
};
});
Expand Down
2 changes: 0 additions & 2 deletions apps/code/src/renderer/desktop-contributions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { agentChatCoreModule } from "@posthog/core/agent-chat/agentChat.module";
import { autoresearchCoreModule } from "@posthog/core/autoresearch/autoresearch.module";
import { billingCoreModule } from "@posthog/core/billing/billing.module";
import { taskThreadCoreModule } from "@posthog/core/canvas/taskThread.module";
import { inboxCoreModule } from "@posthog/core/inbox/inbox.module";
import { githubConnectModule } from "@posthog/core/integrations/githubConnect.module";
Expand Down Expand Up @@ -37,7 +36,6 @@ export function registerDesktopContributions(): void {
authUiModule,
autoresearchCoreModule,
billingUiModule,
billingCoreModule,
taskThreadCoreModule,
browserTabsUiModule,
cloneUiModule,
Expand Down
14 changes: 3 additions & 11 deletions packages/agent/src/posthog-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ import type {
TaskRun,
TaskRunArtifact,
} from "./types";
import {
getGatewayInvalidatePlanCacheUrl,
getGatewayUsageUrl,
getLlmGatewayUrl,
} from "./utils/gateway";

export {
getGatewayInvalidatePlanCacheUrl,
getGatewayUsageUrl,
getLlmGatewayUrl,
};
import { getGatewayUsageUrl, getLlmGatewayUrl } from "./utils/gateway";

export { getGatewayUsageUrl, getLlmGatewayUrl };

const DEFAULT_USER_AGENT = `posthog/agent.hog.dev; version: ${packageJson.version}`;

Expand Down
7 changes: 0 additions & 7 deletions packages/agent/src/utils/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,3 @@ export function getGatewayUsageUrl(
): string {
return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}`;
}

export function getGatewayInvalidatePlanCacheUrl(
posthogHost: string,
product: GatewayProduct = "posthog_code",
): string {
return `${getGatewayBaseUrl(posthogHost)}/v1/usage/${product}/invalidate-plan-cache`;
}
145 changes: 0 additions & 145 deletions packages/api-client/src/posthog-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import type {
CloudRunSource,
ExecutionMode,
PrAuthorshipMode,
SeatData,
StoredLogEntry,
TaskRunArtifactMetadata,
} from "@posthog/shared";
import {
DISMISSAL_REASON_OPTIONS,
type DismissalReasonOptionValue,
resolveCloudInitialPermissionMode,
SEAT_PRODUCT_KEY,
} from "@posthog/shared";
import type {
AgentAnalyticsData,
Expand Down Expand Up @@ -119,22 +117,6 @@ export function setPosthogApiClientAppVersion(version: string): void {
clientAppVersion = version;
}

export class SeatSubscriptionRequiredError extends Error {
redirectUrl: string;
constructor(redirectUrl: string) {
super("Billing subscription required");
this.name = "SeatSubscriptionRequiredError";
this.redirectUrl = redirectUrl;
}
}

export class SeatPaymentFailedError extends Error {
constructor(message?: string) {
super(message ?? "Payment failed");
this.name = "SeatPaymentFailedError";
}
}

export class SandboxCustomImagesDisabledError extends Error {
constructor(message?: string) {
super(message ?? "Custom sandbox images are not enabled");
Expand Down Expand Up @@ -4452,113 +4434,6 @@ export class PostHogAPIClient {
return data.results ?? [];
}

async getMySeat(
options: { best?: boolean } = { best: true },
): Promise<SeatData | null> {
try {
const url = new URL(`${this.api.baseUrl}/api/seats/me/`);
url.searchParams.set("product_key", SEAT_PRODUCT_KEY);
if (options.best) {
url.searchParams.set("best", "true");
}
const response = await this.api.fetcher.fetch({
method: "get",
url,
path: "/api/seats/me/",
});
return (await response.json()) as SeatData;
} catch (error) {
if (this.isFetcherStatusError(error, 404)) {
return null;
}
throw error;
}
}

async createSeat(planKey: string): Promise<SeatData> {
try {
const user = await this.getCurrentUser();
const distinctId = user.distinct_id;
if (!distinctId) {
throw new Error("Cannot create seat: user has no distinct_id");
}
const url = new URL(`${this.api.baseUrl}/api/seats/`);
const response = await this.api.fetcher.fetch({
method: "post",
url,
path: "/api/seats/",
overrides: {
body: JSON.stringify({
product_key: SEAT_PRODUCT_KEY,
plan_key: planKey,
user_distinct_id: distinctId,
}),
},
});
return (await response.json()) as SeatData;
} catch (error) {
this.throwSeatError(error);
}
}

async upgradeSeat(planKey: string): Promise<SeatData> {
try {
const url = new URL(`${this.api.baseUrl}/api/seats/me/`);
const response = await this.api.fetcher.fetch({
method: "patch",
url,
path: "/api/seats/me/",
overrides: {
body: JSON.stringify({
product_key: SEAT_PRODUCT_KEY,
plan_key: planKey,
}),
},
});
return (await response.json()) as SeatData;
} catch (error) {
this.throwSeatError(error);
}
}

async cancelSeat(): Promise<void> {
try {
const url = new URL(`${this.api.baseUrl}/api/seats/me/`);
url.searchParams.set("product_key", SEAT_PRODUCT_KEY);
await this.api.fetcher.fetch({
method: "delete",
url,
path: "/api/seats/me/",
});
} catch (error) {
if (this.isFetcherStatusError(error, 204)) {
return;
}
this.throwSeatError(error);
}
}

async reactivateSeat(): Promise<SeatData> {
try {
const url = new URL(`${this.api.baseUrl}/api/seats/me/reactivate/`);
const response = await this.api.fetcher.fetch({
method: "post",
url,
path: "/api/seats/me/reactivate/",
overrides: {
body: JSON.stringify({ product_key: SEAT_PRODUCT_KEY }),
},
});
return (await response.json()) as SeatData;
} catch (error) {
this.throwSeatError(error);
}
}

private isFetcherStatusError(error: unknown, status: number): boolean {
return error instanceof Error && error.message.includes(`[${status}]`);
}

private parseFetcherError(error: unknown): {
status: number;
body: Record<string, unknown>;
Expand Down Expand Up @@ -4607,26 +4482,6 @@ export class PostHogAPIClient {
}
}

private throwSeatError(error: unknown): never {
const parsed = this.parseFetcherError(error);

if (parsed) {
if (
parsed.status === 400 &&
typeof parsed.body.redirect_url === "string"
) {
throw new SeatSubscriptionRequiredError(parsed.body.redirect_url);
}
if (parsed.status === 402) {
const message =
typeof parsed.body.error === "string" ? parsed.body.error : undefined;
throw new SeatPaymentFailedError(message);
}
}

throw error;
}

/**
* Check if a feature flag is enabled for the current project.
* Returns true if the flag exists and is active, false otherwise.
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/billing/billing.module.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/core/src/billing/identifiers.ts

This file was deleted.

24 changes: 0 additions & 24 deletions packages/core/src/billing/seatErrors.ts

This file was deleted.

Loading
Loading