@posthog/agent 2.3.548 → 2.3.556

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.
@@ -8755,7 +8755,7 @@ var import_zod3 = require("zod");
8755
8755
  // package.json
8756
8756
  var package_default = {
8757
8757
  name: "@posthog/agent",
8758
- version: "2.3.548",
8758
+ version: "2.3.556",
8759
8759
  repository: "https://github.com/PostHog/code",
8760
8760
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
8761
8761
  exports: {
@@ -11222,6 +11222,7 @@ var ParserManager = class {
11222
11222
  languages = /* @__PURE__ */ new Map();
11223
11223
  languageKeys = /* @__PURE__ */ new WeakMap();
11224
11224
  queryCache = /* @__PURE__ */ new Map();
11225
+ failedQueries = /* @__PURE__ */ new Set();
11225
11226
  maxCacheSize = 256;
11226
11227
  initPromise = null;
11227
11228
  wasmDir = resolveGrammarsDir();
@@ -11229,6 +11230,7 @@ var ParserManager = class {
11229
11230
  updateConfig(config) {
11230
11231
  this.config = config;
11231
11232
  this.queryCache.clear();
11233
+ this.failedQueries.clear();
11232
11234
  }
11233
11235
  async ensureInitialized() {
11234
11236
  if (!this.initPromise) {
@@ -11290,6 +11292,9 @@ var ParserManager = class {
11290
11292
  }
11291
11293
  const langKey = this.languageKeys.get(lang) ?? lang.toString();
11292
11294
  const cacheKey = `${langKey}:${queryStr}`;
11295
+ if (this.failedQueries.has(cacheKey)) {
11296
+ return null;
11297
+ }
11293
11298
  let query2 = this.queryCache.get(cacheKey);
11294
11299
  if (query2) {
11295
11300
  this.queryCache.delete(cacheKey);
@@ -11308,6 +11313,7 @@ var ParserManager = class {
11308
11313
  return query2;
11309
11314
  } catch (err2) {
11310
11315
  warn("Query compilation failed", err2);
11316
+ this.failedQueries.add(cacheKey);
11311
11317
  return null;
11312
11318
  }
11313
11319
  }
@@ -11318,6 +11324,7 @@ var ParserManager = class {
11318
11324
  this.languages.clear();
11319
11325
  this.languageKeys = /* @__PURE__ */ new WeakMap();
11320
11326
  this.queryCache.clear();
11327
+ this.failedQueries.clear();
11321
11328
  }
11322
11329
  };
11323
11330
  async function findVariantBranches(pm, source, languageId) {
@@ -12843,6 +12850,33 @@ var PostHogApi = class {
12843
12850
  );
12844
12851
  return data.results.filter((f) => !f.deleted);
12845
12852
  }
12853
+ // Keys absent from the returned map have NOT been called in the window.
12854
+ async getFlagLastCalled(flagKeys, daysBack = 30) {
12855
+ if (flagKeys.length === 0) return /* @__PURE__ */ new Map();
12856
+ const days = Math.max(1, Math.min(365, Math.floor(daysBack)));
12857
+ const query2 = `
12858
+ SELECT
12859
+ properties.$feature_flag AS flag_key,
12860
+ max(timestamp) AS last_called_at
12861
+ FROM events
12862
+ WHERE event = '$feature_flag_called'
12863
+ AND properties.$feature_flag IN {flagKeys}
12864
+ AND timestamp >= now() - INTERVAL ${days} DAY
12865
+ GROUP BY flag_key
12866
+ `;
12867
+ const data = await this.post("/query/", {
12868
+ query: {
12869
+ kind: "HogQLQuery",
12870
+ query: query2,
12871
+ values: { flagKeys }
12872
+ }
12873
+ });
12874
+ const lastCalled = /* @__PURE__ */ new Map();
12875
+ for (const [flagKey, lastCalledAt] of data.results) {
12876
+ if (lastCalledAt) lastCalled.set(flagKey, lastCalledAt);
12877
+ }
12878
+ return lastCalled;
12879
+ }
12846
12880
  async getExperiments() {
12847
12881
  const data = await this.get(
12848
12882
  "/experiments/?limit=500"
@@ -16114,6 +16148,10 @@ function buildMcpServers(userServers, acpServers, projectScopedServers) {
16114
16148
  };
16115
16149
  }
16116
16150
  function buildEnvironment() {
16151
+ const bedrockFallbackHeader = "x-posthog-use-bedrock-fallback: true";
16152
+ const existingCustomHeaders = process.env.ANTHROPIC_CUSTOM_HEADERS;
16153
+ const customHeaders = existingCustomHeaders ? `${existingCustomHeaders}
16154
+ ${bedrockFallbackHeader}` : bedrockFallbackHeader;
16117
16155
  return {
16118
16156
  ...process.env,
16119
16157
  ELECTRON_RUN_AS_NODE: "1",
@@ -16121,7 +16159,9 @@ function buildEnvironment() {
16121
16159
  // Offload all MCP tools by default
16122
16160
  ENABLE_TOOL_SEARCH: "auto:0",
16123
16161
  // Enable idle state as end-of-turn signal (required for SDK 0.2.114+)
16124
- CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1"
16162
+ CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1",
16163
+ // Route to AWS Bedrock as a fallback when Anthropic returns 5xx
16164
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders
16125
16165
  };
16126
16166
  }
16127
16167
  function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache, registeredAgents) {