@posthog/agent 2.3.84 → 2.3.92

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.84",
374
+ version: "2.3.92",
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 {
@@ -2567,6 +2570,7 @@ async function canUseTool(context) {
2567
2570
 
2568
2571
  // src/adapters/claude/session/commands.ts
2569
2572
  var UNSUPPORTED_COMMANDS = [
2573
+ "clear",
2570
2574
  "context",
2571
2575
  "cost",
2572
2576
  "keybindings-help",
@@ -3231,8 +3235,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3231
3235
  sessionCapabilities: {
3232
3236
  list: {},
3233
3237
  fork: {},
3234
- resume: {},
3235
- close: {}
3238
+ resume: {}
3236
3239
  },
3237
3240
  _meta: {
3238
3241
  posthog: {
@@ -4163,6 +4166,10 @@ function spawnCodexProcess(options) {
4163
4166
  function isGroupedOptions(options) {
4164
4167
  return options.length > 0 && "group" in options[0];
4165
4168
  }
4169
+ function formatOption(o) {
4170
+ if (!o.value) return o;
4171
+ return { ...o, name: formatModelId(o.value) };
4172
+ }
4166
4173
  function filterModelConfigOptions(msg, allowedModelIds) {
4167
4174
  const payload = msg;
4168
4175
  const configOptions = payload.result?.configOptions ?? payload.params?.update?.configOptions;
@@ -4173,9 +4180,7 @@ function filterModelConfigOptions(msg, allowedModelIds) {
4173
4180
  if (isGroupedOptions(options)) {
4174
4181
  const filteredOptions2 = options.map((group) => ({
4175
4182
  ...group,
4176
- options: (group.options ?? []).filter(
4177
- (o) => o?.value && allowedModelIds.has(o.value)
4178
- )
4183
+ options: (group.options ?? []).filter((o) => o?.value && allowedModelIds.has(o.value)).map(formatOption)
4179
4184
  }));
4180
4185
  const flat = filteredOptions2.flatMap((g) => g.options ?? []);
4181
4186
  const currentAllowed2 = opt.currentValue && allowedModelIds.has(opt.currentValue);
@@ -4187,9 +4192,7 @@ function filterModelConfigOptions(msg, allowedModelIds) {
4187
4192
  };
4188
4193
  }
4189
4194
  const valueOptions = options;
4190
- const filteredOptions = valueOptions.filter(
4191
- (o) => o?.value && allowedModelIds.has(o.value)
4192
- );
4195
+ const filteredOptions = valueOptions.filter((o) => o?.value && allowedModelIds.has(o.value)).map(formatOption);
4193
4196
  const currentAllowed = opt.currentValue && allowedModelIds.has(opt.currentValue);
4194
4197
  const nextCurrent = currentAllowed || filteredOptions.length === 0 ? opt.currentValue : filteredOptions[0]?.value;
4195
4198
  return {
@@ -5064,7 +5067,7 @@ var Agent = class {
5064
5067
  sanitizedModel = codexModelIds[0];
5065
5068
  }
5066
5069
  }
5067
- if (!sanitizedModel) {
5070
+ if (!sanitizedModel && options.adapter !== "codex") {
5068
5071
  sanitizedModel = DEFAULT_GATEWAY_MODEL;
5069
5072
  }
5070
5073
  this.acpConnection = createAcpConnection({