@posthog/agent 2.3.31 → 2.3.46

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/agent.js CHANGED
@@ -281,7 +281,7 @@ import { v7 as uuidv7 } from "uuid";
281
281
  // package.json
282
282
  var package_default = {
283
283
  name: "@posthog/agent",
284
- version: "2.3.31",
284
+ version: "2.3.46",
285
285
  repository: "https://github.com/PostHog/code",
286
286
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
287
287
  exports: {
@@ -457,21 +457,18 @@ function isAnthropicModel(model) {
457
457
  }
458
458
  return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
459
459
  }
460
- var arrayModelsCache = null;
461
- async function fetchArrayModels(options) {
460
+ var modelsListCache = null;
461
+ async function fetchModelsList(options) {
462
462
  const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
463
463
  if (!gatewayUrl) {
464
464
  return [];
465
465
  }
466
- if (arrayModelsCache && arrayModelsCache.url === gatewayUrl && Date.now() < arrayModelsCache.expiry) {
467
- return arrayModelsCache.models;
466
+ if (modelsListCache && modelsListCache.url === gatewayUrl && Date.now() < modelsListCache.expiry) {
467
+ return modelsListCache.models;
468
468
  }
469
469
  try {
470
- const base = new URL(gatewayUrl);
471
- base.pathname = "/array/v1/models";
472
- base.search = "";
473
- base.hash = "";
474
- const response = await fetch(base.toString());
470
+ const modelsUrl = `${gatewayUrl}/v1/models`;
471
+ const response = await fetch(modelsUrl);
475
472
  if (!response.ok) {
476
473
  return [];
477
474
  }
@@ -483,7 +480,7 @@ async function fetchArrayModels(options) {
483
480
  if (!id) continue;
484
481
  results.push({ id, owned_by: model?.owned_by });
485
482
  }
486
- arrayModelsCache = {
483
+ modelsListCache = {
487
484
  models: results,
488
485
  expiry: Date.now() + CACHE_TTL,
489
486
  url: gatewayUrl
@@ -3298,6 +3295,10 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3298
3295
  (m) => m.contextWindow
3299
3296
  );
3300
3297
  const contextWindowSize = contextWindows.length > 0 ? Math.min(...contextWindows) : getDefaultContextWindow(this.session.modelId ?? "");
3298
+ this.session.contextSize = contextWindowSize;
3299
+ if (lastAssistantTotalUsage !== null) {
3300
+ this.session.contextUsed = lastAssistantTotalUsage;
3301
+ }
3301
3302
  if (lastAssistantTotalUsage !== null) {
3302
3303
  await this.client.sessionUpdate({
3303
3304
  sessionId: params.sessionId,
@@ -4777,12 +4778,12 @@ var Agent = class {
4777
4778
  }
4778
4779
  }
4779
4780
  }
4780
- _configureLlmGateway(_adapter) {
4781
+ _configureLlmGateway(overrideUrl) {
4781
4782
  if (!this.posthogAPI) {
4782
4783
  return null;
4783
4784
  }
4784
4785
  try {
4785
- const gatewayUrl = this.posthogAPI.getLlmGatewayUrl();
4786
+ const gatewayUrl = overrideUrl ?? this.posthogAPI.getLlmGatewayUrl();
4786
4787
  const apiKey = this.posthogAPI.getApiKey();
4787
4788
  process.env.OPENAI_BASE_URL = `${gatewayUrl}/v1`;
4788
4789
  process.env.OPENAI_API_KEY = apiKey;
@@ -4795,7 +4796,7 @@ var Agent = class {
4795
4796
  }
4796
4797
  }
4797
4798
  async run(taskId, taskRunId, options = {}) {
4798
- const gatewayConfig = this._configureLlmGateway(options.adapter);
4799
+ const gatewayConfig = this._configureLlmGateway(options.gatewayUrl);
4799
4800
  this.logger.info("Configured LLM gateway", {
4800
4801
  adapter: options.adapter
4801
4802
  });
@@ -4803,7 +4804,7 @@ var Agent = class {
4803
4804
  let allowedModelIds;
4804
4805
  let sanitizedModel = options.model && !BLOCKED_MODELS.has(options.model) ? options.model : void 0;
4805
4806
  if (options.adapter === "codex" && gatewayConfig) {
4806
- const models = await fetchArrayModels({
4807
+ const models = await fetchModelsList({
4807
4808
  gatewayUrl: gatewayConfig.gatewayUrl
4808
4809
  });
4809
4810
  const codexModelIds = models.filter((model) => {