@posthog/agent 2.3.31 → 2.3.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -79,6 +79,7 @@ interface TaskExecutionOptions {
79
79
  repositoryPath?: string;
80
80
  adapter?: "claude" | "codex";
81
81
  model?: string;
82
+ gatewayUrl?: string;
82
83
  codexBinaryPath?: string;
83
84
  processCallbacks?: ProcessSpawnedCallback;
84
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/agent",
3
- "version": "2.3.31",
3
+ "version": "2.3.43",
4
4
  "repository": "https://github.com/PostHog/code",
5
5
  "description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
6
6
  "exports": {
package/src/agent.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  BLOCKED_MODELS,
7
7
  DEFAULT_GATEWAY_MODEL,
8
- fetchArrayModels,
8
+ fetchModelsList,
9
9
  } from "./gateway-models";
10
10
  import { PostHogAPIClient, type TaskRunUpdate } from "./posthog-api";
11
11
  import { SessionLogWriter } from "./session-log-writer";
@@ -45,7 +45,7 @@ export class Agent {
45
45
  }
46
46
  }
47
47
 
48
- private _configureLlmGateway(_adapter?: "claude" | "codex"): {
48
+ private _configureLlmGateway(overrideUrl?: string): {
49
49
  gatewayUrl: string;
50
50
  apiKey: string;
51
51
  } | null {
@@ -54,7 +54,7 @@ export class Agent {
54
54
  }
55
55
 
56
56
  try {
57
- const gatewayUrl = this.posthogAPI.getLlmGatewayUrl();
57
+ const gatewayUrl = overrideUrl ?? this.posthogAPI.getLlmGatewayUrl();
58
58
  const apiKey = this.posthogAPI.getApiKey();
59
59
 
60
60
  process.env.OPENAI_BASE_URL = `${gatewayUrl}/v1`;
@@ -74,7 +74,7 @@ export class Agent {
74
74
  taskRunId: string,
75
75
  options: TaskExecutionOptions = {},
76
76
  ): Promise<InProcessAcpConnection> {
77
- const gatewayConfig = this._configureLlmGateway(options.adapter);
77
+ const gatewayConfig = this._configureLlmGateway(options.gatewayUrl);
78
78
  this.logger.info("Configured LLM gateway", {
79
79
  adapter: options.adapter,
80
80
  });
@@ -86,7 +86,7 @@ export class Agent {
86
86
  ? options.model
87
87
  : undefined;
88
88
  if (options.adapter === "codex" && gatewayConfig) {
89
- const models = await fetchArrayModels({
89
+ const models = await fetchModelsList({
90
90
  gatewayUrl: gatewayConfig.gatewayUrl,
91
91
  });
92
92
  const codexModelIds = models
@@ -19,7 +19,7 @@ export const DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
19
19
 
20
20
  export const BLOCKED_MODELS = new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
21
21
 
22
- type ArrayModelsResponse =
22
+ type ModelsListResponse =
23
23
  | {
24
24
  data?: Array<{ id?: string; owned_by?: string }>;
25
25
  models?: Array<{ id?: string; owned_by?: string }>;
@@ -79,53 +79,50 @@ export function isAnthropicModel(model: GatewayModel): boolean {
79
79
  return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
80
80
  }
81
81
 
82
- export interface ArrayModelInfo {
82
+ export interface ModelInfo {
83
83
  id: string;
84
84
  owned_by?: string;
85
85
  }
86
86
 
87
- let arrayModelsCache: {
88
- models: ArrayModelInfo[];
87
+ let modelsListCache: {
88
+ models: ModelInfo[];
89
89
  expiry: number;
90
90
  url: string;
91
91
  } | null = null;
92
92
 
93
- export async function fetchArrayModels(
93
+ export async function fetchModelsList(
94
94
  options?: FetchGatewayModelsOptions,
95
- ): Promise<ArrayModelInfo[]> {
95
+ ): Promise<ModelInfo[]> {
96
96
  const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
97
97
  if (!gatewayUrl) {
98
98
  return [];
99
99
  }
100
100
 
101
101
  if (
102
- arrayModelsCache &&
103
- arrayModelsCache.url === gatewayUrl &&
104
- Date.now() < arrayModelsCache.expiry
102
+ modelsListCache &&
103
+ modelsListCache.url === gatewayUrl &&
104
+ Date.now() < modelsListCache.expiry
105
105
  ) {
106
- return arrayModelsCache.models;
106
+ return modelsListCache.models;
107
107
  }
108
108
 
109
109
  try {
110
- const base = new URL(gatewayUrl);
111
- base.pathname = "/array/v1/models";
112
- base.search = "";
113
- base.hash = "";
114
- const response = await fetch(base.toString());
110
+ const modelsUrl = `${gatewayUrl}/v1/models`;
111
+ const response = await fetch(modelsUrl);
115
112
  if (!response.ok) {
116
113
  return [];
117
114
  }
118
- const data = (await response.json()) as ArrayModelsResponse;
115
+ const data = (await response.json()) as ModelsListResponse;
119
116
  const models = Array.isArray(data)
120
117
  ? data
121
118
  : (data.data ?? data.models ?? []);
122
- const results: ArrayModelInfo[] = [];
119
+ const results: ModelInfo[] = [];
123
120
  for (const model of models) {
124
121
  const id = model?.id ? String(model.id) : "";
125
122
  if (!id) continue;
126
123
  results.push({ id, owned_by: model?.owned_by });
127
124
  }
128
- arrayModelsCache = {
125
+ modelsListCache = {
129
126
  models: results,
130
127
  expiry: Date.now() + CACHE_TTL,
131
128
  url: gatewayUrl,
package/src/types.ts CHANGED
@@ -109,6 +109,7 @@ export interface TaskExecutionOptions {
109
109
  repositoryPath?: string;
110
110
  adapter?: "claude" | "codex";
111
111
  model?: string;
112
+ gatewayUrl?: string;
112
113
  codexBinaryPath?: string;
113
114
  processCallbacks?: ProcessSpawnedCallback;
114
115
  }