@posthog/agent 2.3.513 → 2.3.519
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/README.md +1 -1
- package/dist/agent.js +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +2 -1
- package/dist/server/agent-server.js +52 -23
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +50 -22
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/server/agent-server.test.ts +68 -1
- package/src/server/agent-server.ts +55 -20
package/dist/server/bin.cjs
CHANGED
|
@@ -8755,7 +8755,7 @@ var import_zod3 = require("zod");
|
|
|
8755
8755
|
// package.json
|
|
8756
8756
|
var package_default = {
|
|
8757
8757
|
name: "@posthog/agent",
|
|
8758
|
-
version: "2.3.
|
|
8758
|
+
version: "2.3.519",
|
|
8759
8759
|
repository: "https://github.com/PostHog/code",
|
|
8760
8760
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8761
8761
|
exports: {
|
|
@@ -21058,6 +21058,7 @@ var agentErrorClassificationSchema = import_zod3.z.enum([
|
|
|
21058
21058
|
var errorWithClassificationSchema = import_zod3.z.object({
|
|
21059
21059
|
data: import_zod3.z.object({ classification: agentErrorClassificationSchema })
|
|
21060
21060
|
});
|
|
21061
|
+
var SSE_KEEPALIVE_INTERVAL_MS = 25e3;
|
|
21061
21062
|
var NdJsonTap = class {
|
|
21062
21063
|
constructor(onMessage) {
|
|
21063
21064
|
this.onMessage = onMessage;
|
|
@@ -21236,41 +21237,67 @@ var AgentServer = class {
|
|
|
21236
21237
|
401
|
|
21237
21238
|
);
|
|
21238
21239
|
}
|
|
21240
|
+
let keepaliveInterval = null;
|
|
21241
|
+
const clearKeepalive = () => {
|
|
21242
|
+
if (keepaliveInterval) {
|
|
21243
|
+
clearInterval(keepaliveInterval);
|
|
21244
|
+
keepaliveInterval = null;
|
|
21245
|
+
}
|
|
21246
|
+
};
|
|
21239
21247
|
const stream = new ReadableStream({
|
|
21240
21248
|
start: async (controller) => {
|
|
21241
|
-
|
|
21249
|
+
let sseController = null;
|
|
21250
|
+
const encoder = new TextEncoder();
|
|
21251
|
+
const detachCurrentSseController = () => {
|
|
21252
|
+
if (sseController) {
|
|
21253
|
+
this.detachSseController(sseController);
|
|
21254
|
+
}
|
|
21255
|
+
};
|
|
21256
|
+
const enqueueSseFrame = (frame) => {
|
|
21257
|
+
try {
|
|
21258
|
+
controller.enqueue(encoder.encode(frame));
|
|
21259
|
+
} catch {
|
|
21260
|
+
clearKeepalive();
|
|
21261
|
+
detachCurrentSseController();
|
|
21262
|
+
}
|
|
21263
|
+
};
|
|
21264
|
+
sseController = {
|
|
21242
21265
|
send: (data) => {
|
|
21243
|
-
|
|
21244
|
-
controller.enqueue(
|
|
21245
|
-
new TextEncoder().encode(`data: ${JSON.stringify(data)}
|
|
21266
|
+
enqueueSseFrame(`data: ${JSON.stringify(data)}
|
|
21246
21267
|
|
|
21247
|
-
`)
|
|
21248
|
-
);
|
|
21249
|
-
} catch {
|
|
21250
|
-
this.detachSseController(sseController);
|
|
21251
|
-
}
|
|
21268
|
+
`);
|
|
21252
21269
|
},
|
|
21253
21270
|
close: () => {
|
|
21254
21271
|
try {
|
|
21272
|
+
clearKeepalive();
|
|
21255
21273
|
controller.close();
|
|
21256
21274
|
} catch {
|
|
21257
|
-
|
|
21275
|
+
detachCurrentSseController();
|
|
21258
21276
|
}
|
|
21259
21277
|
}
|
|
21260
21278
|
};
|
|
21261
|
-
|
|
21262
|
-
|
|
21263
|
-
}
|
|
21264
|
-
|
|
21265
|
-
this.session.
|
|
21266
|
-
|
|
21279
|
+
keepaliveInterval = setInterval(() => {
|
|
21280
|
+
enqueueSseFrame(": keepalive\n\n");
|
|
21281
|
+
}, SSE_KEEPALIVE_INTERVAL_MS);
|
|
21282
|
+
try {
|
|
21283
|
+
if (!this.session || this.session.payload.run_id !== payload.run_id) {
|
|
21284
|
+
await this.initializeSession(payload, sseController);
|
|
21285
|
+
} else {
|
|
21286
|
+
this.session.sseController = sseController;
|
|
21287
|
+
this.session.hasDesktopConnected = true;
|
|
21288
|
+
this.replayPendingEvents();
|
|
21289
|
+
}
|
|
21290
|
+
this.sendSseEvent(sseController, {
|
|
21291
|
+
type: "connected",
|
|
21292
|
+
run_id: payload.run_id
|
|
21293
|
+
});
|
|
21294
|
+
} catch (error) {
|
|
21295
|
+
clearKeepalive();
|
|
21296
|
+
throw error;
|
|
21267
21297
|
}
|
|
21268
|
-
this.sendSseEvent(sseController, {
|
|
21269
|
-
type: "connected",
|
|
21270
|
-
run_id: payload.run_id
|
|
21271
|
-
});
|
|
21272
21298
|
},
|
|
21273
21299
|
cancel: () => {
|
|
21300
|
+
clearKeepalive();
|
|
21274
21301
|
this.logger.debug("SSE connection closed");
|
|
21275
21302
|
if (this.session?.sseController) {
|
|
21276
21303
|
this.session.sseController = null;
|
|
@@ -21741,7 +21768,8 @@ var AgentServer = class {
|
|
|
21741
21768
|
params: {
|
|
21742
21769
|
sessionId: acpSessionId,
|
|
21743
21770
|
runId: payload.run_id,
|
|
21744
|
-
taskId: payload.task_id
|
|
21771
|
+
taskId: payload.task_id,
|
|
21772
|
+
agentVersion: this.config.version ?? package_default.version
|
|
21745
21773
|
}
|
|
21746
21774
|
};
|
|
21747
21775
|
this.broadcastEvent({
|