@posthog/agent 2.3.547 → 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.
package/dist/agent.js CHANGED
@@ -4030,7 +4030,7 @@ import { v7 as uuidv7 } from "uuid";
4030
4030
  // package.json
4031
4031
  var package_default = {
4032
4032
  name: "@posthog/agent",
4033
- version: "2.3.547",
4033
+ version: "2.3.556",
4034
4034
  repository: "https://github.com/PostHog/code",
4035
4035
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
4036
4036
  exports: {
@@ -6258,6 +6258,7 @@ var ParserManager = class {
6258
6258
  languages = /* @__PURE__ */ new Map();
6259
6259
  languageKeys = /* @__PURE__ */ new WeakMap();
6260
6260
  queryCache = /* @__PURE__ */ new Map();
6261
+ failedQueries = /* @__PURE__ */ new Set();
6261
6262
  maxCacheSize = 256;
6262
6263
  initPromise = null;
6263
6264
  wasmDir = resolveGrammarsDir();
@@ -6265,6 +6266,7 @@ var ParserManager = class {
6265
6266
  updateConfig(config) {
6266
6267
  this.config = config;
6267
6268
  this.queryCache.clear();
6269
+ this.failedQueries.clear();
6268
6270
  }
6269
6271
  async ensureInitialized() {
6270
6272
  if (!this.initPromise) {
@@ -6326,6 +6328,9 @@ var ParserManager = class {
6326
6328
  }
6327
6329
  const langKey = this.languageKeys.get(lang) ?? lang.toString();
6328
6330
  const cacheKey = `${langKey}:${queryStr}`;
6331
+ if (this.failedQueries.has(cacheKey)) {
6332
+ return null;
6333
+ }
6329
6334
  let query2 = this.queryCache.get(cacheKey);
6330
6335
  if (query2) {
6331
6336
  this.queryCache.delete(cacheKey);
@@ -6344,6 +6349,7 @@ var ParserManager = class {
6344
6349
  return query2;
6345
6350
  } catch (err2) {
6346
6351
  warn("Query compilation failed", err2);
6352
+ this.failedQueries.add(cacheKey);
6347
6353
  return null;
6348
6354
  }
6349
6355
  }
@@ -6354,6 +6360,7 @@ var ParserManager = class {
6354
6360
  this.languages.clear();
6355
6361
  this.languageKeys = /* @__PURE__ */ new WeakMap();
6356
6362
  this.queryCache.clear();
6363
+ this.failedQueries.clear();
6357
6364
  }
6358
6365
  };
6359
6366
  async function findVariantBranches(pm, source, languageId) {
@@ -7879,6 +7886,33 @@ var PostHogApi = class {
7879
7886
  );
7880
7887
  return data.results.filter((f) => !f.deleted);
7881
7888
  }
7889
+ // Keys absent from the returned map have NOT been called in the window.
7890
+ async getFlagLastCalled(flagKeys, daysBack = 30) {
7891
+ if (flagKeys.length === 0) return /* @__PURE__ */ new Map();
7892
+ const days = Math.max(1, Math.min(365, Math.floor(daysBack)));
7893
+ const query2 = `
7894
+ SELECT
7895
+ properties.$feature_flag AS flag_key,
7896
+ max(timestamp) AS last_called_at
7897
+ FROM events
7898
+ WHERE event = '$feature_flag_called'
7899
+ AND properties.$feature_flag IN {flagKeys}
7900
+ AND timestamp >= now() - INTERVAL ${days} DAY
7901
+ GROUP BY flag_key
7902
+ `;
7903
+ const data = await this.post("/query/", {
7904
+ query: {
7905
+ kind: "HogQLQuery",
7906
+ query: query2,
7907
+ values: { flagKeys }
7908
+ }
7909
+ });
7910
+ const lastCalled = /* @__PURE__ */ new Map();
7911
+ for (const [flagKey, lastCalledAt] of data.results) {
7912
+ if (lastCalledAt) lastCalled.set(flagKey, lastCalledAt);
7913
+ }
7914
+ return lastCalled;
7915
+ }
7882
7916
  async getExperiments() {
7883
7917
  const data = await this.get(
7884
7918
  "/experiments/?limit=500"
@@ -11290,6 +11324,10 @@ function buildMcpServers(userServers, acpServers, projectScopedServers) {
11290
11324
  };
11291
11325
  }
11292
11326
  function buildEnvironment() {
11327
+ const bedrockFallbackHeader = "x-posthog-use-bedrock-fallback: true";
11328
+ const existingCustomHeaders = process.env.ANTHROPIC_CUSTOM_HEADERS;
11329
+ const customHeaders = existingCustomHeaders ? `${existingCustomHeaders}
11330
+ ${bedrockFallbackHeader}` : bedrockFallbackHeader;
11293
11331
  return {
11294
11332
  ...process.env,
11295
11333
  ELECTRON_RUN_AS_NODE: "1",
@@ -11297,7 +11335,9 @@ function buildEnvironment() {
11297
11335
  // Offload all MCP tools by default
11298
11336
  ENABLE_TOOL_SEARCH: "auto:0",
11299
11337
  // Enable idle state as end-of-turn signal (required for SDK 0.2.114+)
11300
- CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1"
11338
+ CLAUDE_CODE_EMIT_SESSION_STATE_EVENTS: "1",
11339
+ // Route to AWS Bedrock as a fallback when Anthropic returns 5xx
11340
+ ANTHROPIC_CUSTOM_HEADERS: customHeaders
11301
11341
  };
11302
11342
  }
11303
11343
  function buildHooks(userHooks, onModeChange, settingsManager, logger, enrichmentDeps, enrichedReadCache, registeredAgents) {