@posthog/agent 2.3.81 → 2.3.90

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
@@ -37,6 +37,96 @@ var POSTHOG_NOTIFICATIONS = {
37
37
  COMPACT_BOUNDARY: "_posthog/compact_boundary"
38
38
  };
39
39
 
40
+ // src/gateway-models.ts
41
+ var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
42
+ var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
43
+ var CACHE_TTL = 10 * 60 * 1e3;
44
+ var gatewayModelsCache = null;
45
+ async function fetchGatewayModels(options) {
46
+ const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
47
+ if (!gatewayUrl) {
48
+ return [];
49
+ }
50
+ if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
51
+ return gatewayModelsCache.models;
52
+ }
53
+ const modelsUrl = `${gatewayUrl}/v1/models`;
54
+ try {
55
+ const response = await fetch(modelsUrl);
56
+ if (!response.ok) {
57
+ return [];
58
+ }
59
+ const data = await response.json();
60
+ const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
61
+ gatewayModelsCache = {
62
+ models,
63
+ expiry: Date.now() + CACHE_TTL,
64
+ url: gatewayUrl
65
+ };
66
+ return models;
67
+ } catch {
68
+ return [];
69
+ }
70
+ }
71
+ function isAnthropicModel(model) {
72
+ if (model.owned_by) {
73
+ return model.owned_by === "anthropic";
74
+ }
75
+ return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
76
+ }
77
+ var modelsListCache = null;
78
+ async function fetchModelsList(options) {
79
+ const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
80
+ if (!gatewayUrl) {
81
+ return [];
82
+ }
83
+ if (modelsListCache && modelsListCache.url === gatewayUrl && Date.now() < modelsListCache.expiry) {
84
+ return modelsListCache.models;
85
+ }
86
+ try {
87
+ const modelsUrl = `${gatewayUrl}/v1/models`;
88
+ const response = await fetch(modelsUrl);
89
+ if (!response.ok) {
90
+ return [];
91
+ }
92
+ const data = await response.json();
93
+ const models = Array.isArray(data) ? data : data.data ?? data.models ?? [];
94
+ const results = [];
95
+ for (const model of models) {
96
+ const id = model?.id ? String(model.id) : "";
97
+ if (!id) continue;
98
+ results.push({ id, owned_by: model?.owned_by });
99
+ }
100
+ modelsListCache = {
101
+ models: results,
102
+ expiry: Date.now() + CACHE_TTL,
103
+ url: gatewayUrl
104
+ };
105
+ return results;
106
+ } catch {
107
+ return [];
108
+ }
109
+ }
110
+ var PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
111
+ function formatGatewayModelName(model) {
112
+ return formatModelId(model.id);
113
+ }
114
+ function formatModelId(modelId) {
115
+ let cleanId = modelId;
116
+ for (const prefix of PROVIDER_PREFIXES) {
117
+ if (cleanId.startsWith(prefix)) {
118
+ cleanId = cleanId.slice(prefix.length);
119
+ break;
120
+ }
121
+ }
122
+ cleanId = cleanId.replace(/(\d)-(\d)/g, "$1.$2");
123
+ const words = cleanId.split(/[-_]/).map((word) => {
124
+ if (word.match(/^[0-9.]+$/)) return word;
125
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
126
+ });
127
+ return words.join(" ");
128
+ }
129
+
40
130
  // src/utils/logger.ts
41
131
  var Logger = class _Logger {
42
132
  debugEnabled;
@@ -281,7 +371,7 @@ import { v7 as uuidv7 } from "uuid";
281
371
  // package.json
282
372
  var package_default = {
283
373
  name: "@posthog/agent",
284
- version: "2.3.81",
374
+ version: "2.3.90",
285
375
  repository: "https://github.com/PostHog/code",
286
376
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
287
377
  exports: {
@@ -420,93 +510,6 @@ function unreachable(value, logger) {
420
510
  logger.error(`Unexpected case: ${valueAsString}`);
421
511
  }
422
512
 
423
- // src/gateway-models.ts
424
- var DEFAULT_GATEWAY_MODEL = "claude-opus-4-6";
425
- var BLOCKED_MODELS = /* @__PURE__ */ new Set(["gpt-5-mini", "openai/gpt-5-mini"]);
426
- var CACHE_TTL = 10 * 60 * 1e3;
427
- var gatewayModelsCache = null;
428
- async function fetchGatewayModels(options) {
429
- const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
430
- if (!gatewayUrl) {
431
- return [];
432
- }
433
- if (gatewayModelsCache && gatewayModelsCache.url === gatewayUrl && Date.now() < gatewayModelsCache.expiry) {
434
- return gatewayModelsCache.models;
435
- }
436
- const modelsUrl = `${gatewayUrl}/v1/models`;
437
- try {
438
- const response = await fetch(modelsUrl);
439
- if (!response.ok) {
440
- return [];
441
- }
442
- const data = await response.json();
443
- const models = (data.data ?? []).filter((m) => !BLOCKED_MODELS.has(m.id));
444
- gatewayModelsCache = {
445
- models,
446
- expiry: Date.now() + CACHE_TTL,
447
- url: gatewayUrl
448
- };
449
- return models;
450
- } catch {
451
- return [];
452
- }
453
- }
454
- function isAnthropicModel(model) {
455
- if (model.owned_by) {
456
- return model.owned_by === "anthropic";
457
- }
458
- return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
459
- }
460
- var modelsListCache = null;
461
- async function fetchModelsList(options) {
462
- const gatewayUrl = options?.gatewayUrl ?? process.env.ANTHROPIC_BASE_URL;
463
- if (!gatewayUrl) {
464
- return [];
465
- }
466
- if (modelsListCache && modelsListCache.url === gatewayUrl && Date.now() < modelsListCache.expiry) {
467
- return modelsListCache.models;
468
- }
469
- try {
470
- const modelsUrl = `${gatewayUrl}/v1/models`;
471
- const response = await fetch(modelsUrl);
472
- if (!response.ok) {
473
- return [];
474
- }
475
- const data = await response.json();
476
- const models = Array.isArray(data) ? data : data.data ?? data.models ?? [];
477
- const results = [];
478
- for (const model of models) {
479
- const id = model?.id ? String(model.id) : "";
480
- if (!id) continue;
481
- results.push({ id, owned_by: model?.owned_by });
482
- }
483
- modelsListCache = {
484
- models: results,
485
- expiry: Date.now() + CACHE_TTL,
486
- url: gatewayUrl
487
- };
488
- return results;
489
- } catch {
490
- return [];
491
- }
492
- }
493
- var PROVIDER_PREFIXES = ["anthropic/", "openai/", "google-vertex/"];
494
- function formatGatewayModelName(model) {
495
- let cleanId = model.id;
496
- for (const prefix of PROVIDER_PREFIXES) {
497
- if (cleanId.startsWith(prefix)) {
498
- cleanId = cleanId.slice(prefix.length);
499
- break;
500
- }
501
- }
502
- cleanId = cleanId.replace(/(\d)-(\d)/g, "$1.$2");
503
- const words = cleanId.split(/[-_]/).map((word) => {
504
- if (word.match(/^[0-9.]+$/)) return word;
505
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
506
- });
507
- return words.join(" ");
508
- }
509
-
510
513
  // src/adapters/base-acp-agent.ts
511
514
  var DEFAULT_CONTEXT_WINDOW = 2e5;
512
515
  var BaseAcpAgent = class {
@@ -3192,7 +3195,7 @@ var SettingsManager = class {
3192
3195
  };
3193
3196
 
3194
3197
  // src/adapters/claude/claude-agent.ts
3195
- var SESSION_VALIDATION_TIMEOUT_MS = 1e4;
3198
+ var SESSION_VALIDATION_TIMEOUT_MS = 3e4;
3196
3199
  var MAX_TITLE_LENGTH = 256;
3197
3200
  var LOCAL_ONLY_COMMANDS = /* @__PURE__ */ new Set(["/context", "/heapdump", "/extra-usage"]);
3198
3201
  function sanitizeTitle(text2) {
@@ -3231,8 +3234,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3231
3234
  sessionCapabilities: {
3232
3235
  list: {},
3233
3236
  fork: {},
3234
- resume: {},
3235
- close: {}
3237
+ resume: {}
3236
3238
  },
3237
3239
  _meta: {
3238
3240
  posthog: {
@@ -4163,6 +4165,10 @@ function spawnCodexProcess(options) {
4163
4165
  function isGroupedOptions(options) {
4164
4166
  return options.length > 0 && "group" in options[0];
4165
4167
  }
4168
+ function formatOption(o) {
4169
+ if (!o.value) return o;
4170
+ return { ...o, name: formatModelId(o.value) };
4171
+ }
4166
4172
  function filterModelConfigOptions(msg, allowedModelIds) {
4167
4173
  const payload = msg;
4168
4174
  const configOptions = payload.result?.configOptions ?? payload.params?.update?.configOptions;
@@ -4173,9 +4179,7 @@ function filterModelConfigOptions(msg, allowedModelIds) {
4173
4179
  if (isGroupedOptions(options)) {
4174
4180
  const filteredOptions2 = options.map((group) => ({
4175
4181
  ...group,
4176
- options: (group.options ?? []).filter(
4177
- (o) => o?.value && allowedModelIds.has(o.value)
4178
- )
4182
+ options: (group.options ?? []).filter((o) => o?.value && allowedModelIds.has(o.value)).map(formatOption)
4179
4183
  }));
4180
4184
  const flat = filteredOptions2.flatMap((g) => g.options ?? []);
4181
4185
  const currentAllowed2 = opt.currentValue && allowedModelIds.has(opt.currentValue);
@@ -4187,9 +4191,7 @@ function filterModelConfigOptions(msg, allowedModelIds) {
4187
4191
  };
4188
4192
  }
4189
4193
  const valueOptions = options;
4190
- const filteredOptions = valueOptions.filter(
4191
- (o) => o?.value && allowedModelIds.has(o.value)
4192
- );
4194
+ const filteredOptions = valueOptions.filter((o) => o?.value && allowedModelIds.has(o.value)).map(formatOption);
4193
4195
  const currentAllowed = opt.currentValue && allowedModelIds.has(opt.currentValue);
4194
4196
  const nextCurrent = currentAllowed || filteredOptions.length === 0 ? opt.currentValue : filteredOptions[0]?.value;
4195
4197
  return {
@@ -5064,7 +5066,7 @@ var Agent = class {
5064
5066
  sanitizedModel = codexModelIds[0];
5065
5067
  }
5066
5068
  }
5067
- if (!sanitizedModel) {
5069
+ if (!sanitizedModel && options.adapter !== "codex") {
5068
5070
  sanitizedModel = DEFAULT_GATEWAY_MODEL;
5069
5071
  }
5070
5072
  this.acpConnection = createAcpConnection({