@posthog/agent 2.3.31 → 2.3.43
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 +12 -15
- package/dist/agent.js.map +1 -1
- package/dist/gateway-models.d.ts +3 -3
- package/dist/gateway-models.js +8 -11
- package/dist/gateway-models.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +1 -1
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +1 -1
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/agent.ts +5 -5
- package/src/gateway-models.ts +15 -18
- package/src/types.ts +1 -0
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.
|
|
284
|
+
version: "2.3.43",
|
|
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
|
|
461
|
-
async function
|
|
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 (
|
|
467
|
-
return
|
|
466
|
+
if (modelsListCache && modelsListCache.url === gatewayUrl && Date.now() < modelsListCache.expiry) {
|
|
467
|
+
return modelsListCache.models;
|
|
468
468
|
}
|
|
469
469
|
try {
|
|
470
|
-
const
|
|
471
|
-
|
|
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
|
-
|
|
483
|
+
modelsListCache = {
|
|
487
484
|
models: results,
|
|
488
485
|
expiry: Date.now() + CACHE_TTL,
|
|
489
486
|
url: gatewayUrl
|
|
@@ -4777,12 +4774,12 @@ var Agent = class {
|
|
|
4777
4774
|
}
|
|
4778
4775
|
}
|
|
4779
4776
|
}
|
|
4780
|
-
_configureLlmGateway(
|
|
4777
|
+
_configureLlmGateway(overrideUrl) {
|
|
4781
4778
|
if (!this.posthogAPI) {
|
|
4782
4779
|
return null;
|
|
4783
4780
|
}
|
|
4784
4781
|
try {
|
|
4785
|
-
const gatewayUrl = this.posthogAPI.getLlmGatewayUrl();
|
|
4782
|
+
const gatewayUrl = overrideUrl ?? this.posthogAPI.getLlmGatewayUrl();
|
|
4786
4783
|
const apiKey = this.posthogAPI.getApiKey();
|
|
4787
4784
|
process.env.OPENAI_BASE_URL = `${gatewayUrl}/v1`;
|
|
4788
4785
|
process.env.OPENAI_API_KEY = apiKey;
|
|
@@ -4795,7 +4792,7 @@ var Agent = class {
|
|
|
4795
4792
|
}
|
|
4796
4793
|
}
|
|
4797
4794
|
async run(taskId, taskRunId, options = {}) {
|
|
4798
|
-
const gatewayConfig = this._configureLlmGateway(options.
|
|
4795
|
+
const gatewayConfig = this._configureLlmGateway(options.gatewayUrl);
|
|
4799
4796
|
this.logger.info("Configured LLM gateway", {
|
|
4800
4797
|
adapter: options.adapter
|
|
4801
4798
|
});
|
|
@@ -4803,7 +4800,7 @@ var Agent = class {
|
|
|
4803
4800
|
let allowedModelIds;
|
|
4804
4801
|
let sanitizedModel = options.model && !BLOCKED_MODELS.has(options.model) ? options.model : void 0;
|
|
4805
4802
|
if (options.adapter === "codex" && gatewayConfig) {
|
|
4806
|
-
const models = await
|
|
4803
|
+
const models = await fetchModelsList({
|
|
4807
4804
|
gatewayUrl: gatewayConfig.gatewayUrl
|
|
4808
4805
|
});
|
|
4809
4806
|
const codexModelIds = models.filter((model) => {
|