Skip to content

Commit 5301288

Browse files
authored
chore(agent-server): report background agents usage for cloud runs (#1035)
1 parent 7ff7eca commit 5301288

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/agent/src/server/agent-server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,10 @@ Important:
651651

652652
private configureEnvironment(): void {
653653
const { apiKey, apiUrl, projectId } = this.config;
654-
const gatewayUrl = process.env.LLM_GATEWAY_URL || getLlmGatewayUrl(apiUrl);
654+
const product =
655+
this.config.mode === "background" ? "background_agents" : "twig";
656+
const gatewayUrl =
657+
process.env.LLM_GATEWAY_URL || getLlmGatewayUrl(apiUrl, product);
655658
const openaiBaseUrl = gatewayUrl.endsWith("/v1")
656659
? gatewayUrl
657660
: `${gatewayUrl}/v1`;
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
export function getLlmGatewayUrl(posthogHost: string): string {
1+
export type GatewayProduct = "twig" | "background_agents";
2+
3+
export function getLlmGatewayUrl(
4+
posthogHost: string,
5+
product: GatewayProduct = "twig",
6+
): string {
27
const url = new URL(posthogHost);
38
const hostname = url.hostname;
49

510
// Local development (normalize 127.0.0.1 to localhost)
611
if (hostname === "localhost" || hostname === "127.0.0.1") {
7-
return `${url.protocol}//localhost:3308/twig`;
12+
return `${url.protocol}//localhost:3308/${product}`;
813
}
914

1015
// Docker containers accessing host
1116
if (hostname === "host.docker.internal") {
12-
return `${url.protocol}//host.docker.internal:3308/twig`;
17+
return `${url.protocol}//host.docker.internal:3308/${product}`;
1318
}
1419

1520
// Production - extract region from hostname, default to US
1621
const region = hostname.match(/^(us|eu)\.posthog\.com$/)?.[1] ?? "us";
17-
return `https://gateway.${region}.posthog.com/twig`;
22+
return `https://gateway.${region}.posthog.com/${product}`;
1823
}

0 commit comments

Comments
 (0)