@posthog/agent 2.3.104 → 2.3.110
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 +39 -22
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.d.ts +6 -2
- package/dist/posthog-api.js +36 -19
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +36 -19
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +36 -19
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/agent.ts +4 -4
- package/src/posthog-api.test.ts +48 -0
- package/src/posthog-api.ts +54 -20
- package/src/types.ts +2 -1
package/dist/server/bin.cjs
CHANGED
|
@@ -904,7 +904,7 @@ var import_hono = require("hono");
|
|
|
904
904
|
// package.json
|
|
905
905
|
var package_default = {
|
|
906
906
|
name: "@posthog/agent",
|
|
907
|
-
version: "2.3.
|
|
907
|
+
version: "2.3.110",
|
|
908
908
|
repository: "https://github.com/PostHog/code",
|
|
909
909
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
910
910
|
exports: {
|
|
@@ -5433,22 +5433,41 @@ var PostHogAPIClient = class {
|
|
|
5433
5433
|
const host = this.config.apiUrl.endsWith("/") ? this.config.apiUrl.slice(0, -1) : this.config.apiUrl;
|
|
5434
5434
|
return host;
|
|
5435
5435
|
}
|
|
5436
|
-
|
|
5437
|
-
return
|
|
5438
|
-
Authorization: `Bearer ${this.config.getApiKey()}`,
|
|
5439
|
-
"Content-Type": "application/json",
|
|
5440
|
-
"User-Agent": this.config.userAgent ?? DEFAULT_USER_AGENT
|
|
5441
|
-
};
|
|
5436
|
+
isAuthFailure(status) {
|
|
5437
|
+
return status === 401 || status === 403;
|
|
5442
5438
|
}
|
|
5443
|
-
async
|
|
5439
|
+
async resolveApiKey(forceRefresh = false) {
|
|
5440
|
+
if (forceRefresh && this.config.refreshApiKey) {
|
|
5441
|
+
return this.config.refreshApiKey();
|
|
5442
|
+
}
|
|
5443
|
+
return this.config.getApiKey();
|
|
5444
|
+
}
|
|
5445
|
+
async buildHeaders(options, forceRefresh = false) {
|
|
5446
|
+
const headers = new Headers(options.headers);
|
|
5447
|
+
headers.set(
|
|
5448
|
+
"Authorization",
|
|
5449
|
+
`Bearer ${await this.resolveApiKey(forceRefresh)}`
|
|
5450
|
+
);
|
|
5451
|
+
headers.set("Content-Type", "application/json");
|
|
5452
|
+
headers.set("User-Agent", this.config.userAgent ?? DEFAULT_USER_AGENT);
|
|
5453
|
+
return headers;
|
|
5454
|
+
}
|
|
5455
|
+
async performRequest(endpoint, options, forceRefresh = false) {
|
|
5444
5456
|
const url = `${this.baseUrl}${endpoint}`;
|
|
5445
|
-
|
|
5457
|
+
return fetch(url, {
|
|
5446
5458
|
...options,
|
|
5447
|
-
headers:
|
|
5448
|
-
...this.headers,
|
|
5449
|
-
...options.headers
|
|
5450
|
-
}
|
|
5459
|
+
headers: await this.buildHeaders(options, forceRefresh)
|
|
5451
5460
|
});
|
|
5461
|
+
}
|
|
5462
|
+
async performRequestWithRetry(endpoint, options = {}) {
|
|
5463
|
+
let response = await this.performRequest(endpoint, options);
|
|
5464
|
+
if (!response.ok && this.isAuthFailure(response.status)) {
|
|
5465
|
+
response = await this.performRequest(endpoint, options, true);
|
|
5466
|
+
}
|
|
5467
|
+
return response;
|
|
5468
|
+
}
|
|
5469
|
+
async apiRequest(endpoint, options = {}) {
|
|
5470
|
+
const response = await this.performRequestWithRetry(endpoint, options);
|
|
5452
5471
|
if (!response.ok) {
|
|
5453
5472
|
let errorMessage;
|
|
5454
5473
|
try {
|
|
@@ -5464,8 +5483,8 @@ var PostHogAPIClient = class {
|
|
|
5464
5483
|
getTeamId() {
|
|
5465
5484
|
return this.config.projectId;
|
|
5466
5485
|
}
|
|
5467
|
-
getApiKey() {
|
|
5468
|
-
return this.
|
|
5486
|
+
async getApiKey(forceRefresh = false) {
|
|
5487
|
+
return this.resolveApiKey(forceRefresh);
|
|
5469
5488
|
}
|
|
5470
5489
|
getLlmGatewayUrl() {
|
|
5471
5490
|
return getLlmGatewayUrl(this.baseUrl);
|
|
@@ -5565,11 +5584,9 @@ var PostHogAPIClient = class {
|
|
|
5565
5584
|
*/
|
|
5566
5585
|
async fetchTaskRunLogs(taskRun) {
|
|
5567
5586
|
const teamId = this.getTeamId();
|
|
5587
|
+
const endpoint = `/api/projects/${teamId}/tasks/${taskRun.task}/runs/${taskRun.id}/logs`;
|
|
5568
5588
|
try {
|
|
5569
|
-
const response = await
|
|
5570
|
-
`${this.baseUrl}/api/projects/${teamId}/tasks/${taskRun.task}/runs/${taskRun.id}/logs`,
|
|
5571
|
-
{ headers: this.headers }
|
|
5572
|
-
);
|
|
5589
|
+
const response = await this.performRequestWithRetry(endpoint);
|
|
5573
5590
|
if (!response.ok) {
|
|
5574
5591
|
if (response.status === 404) {
|
|
5575
5592
|
return [];
|