@posthog/agent 2.3.110 → 2.3.125
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 +34 -10
- 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.js +49 -13
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +49 -13
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +1 -1
- package/src/server/agent-server.ts +17 -4
- package/src/session-log-writer.test.ts +216 -0
- package/src/session-log-writer.ts +48 -11
package/dist/agent.js
CHANGED
|
@@ -371,7 +371,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
371
371
|
// package.json
|
|
372
372
|
var package_default = {
|
|
373
373
|
name: "@posthog/agent",
|
|
374
|
-
version: "2.3.
|
|
374
|
+
version: "2.3.125",
|
|
375
375
|
repository: "https://github.com/PostHog/code",
|
|
376
376
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
377
377
|
exports: {
|
|
@@ -4730,9 +4730,9 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4730
4730
|
this.logger = options.logger ?? new Logger({ debug: false, prefix: "[SessionLogWriter]" });
|
|
4731
4731
|
}
|
|
4732
4732
|
async flushAll() {
|
|
4733
|
-
const sessionIds = [...this.sessions.keys()];
|
|
4734
4733
|
const flushPromises = [];
|
|
4735
|
-
for (const sessionId of
|
|
4734
|
+
for (const [sessionId, session] of this.sessions) {
|
|
4735
|
+
this.emitCoalescedMessage(sessionId, session);
|
|
4736
4736
|
flushPromises.push(this.flush(sessionId));
|
|
4737
4737
|
}
|
|
4738
4738
|
await Promise.all(flushPromises);
|
|
@@ -4788,7 +4788,11 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4788
4788
|
}
|
|
4789
4789
|
return;
|
|
4790
4790
|
}
|
|
4791
|
-
this.
|
|
4791
|
+
if (this.isDirectAgentMessage(message) && session.chunkBuffer) {
|
|
4792
|
+
session.chunkBuffer = void 0;
|
|
4793
|
+
} else {
|
|
4794
|
+
this.emitCoalescedMessage(sessionId, session);
|
|
4795
|
+
}
|
|
4792
4796
|
const nonChunkAgentText = this.extractAgentMessageText(message);
|
|
4793
4797
|
if (nonChunkAgentText) {
|
|
4794
4798
|
session.lastAgentMessage = nonChunkAgentText;
|
|
@@ -4814,7 +4818,13 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4814
4818
|
});
|
|
4815
4819
|
}
|
|
4816
4820
|
}
|
|
4817
|
-
async flush(sessionId) {
|
|
4821
|
+
async flush(sessionId, { coalesce = false } = {}) {
|
|
4822
|
+
if (coalesce) {
|
|
4823
|
+
const session = this.sessions.get(sessionId);
|
|
4824
|
+
if (session) {
|
|
4825
|
+
this.emitCoalescedMessage(sessionId, session);
|
|
4826
|
+
}
|
|
4827
|
+
}
|
|
4818
4828
|
const prev = this.flushQueues.get(sessionId) ?? Promise.resolve();
|
|
4819
4829
|
const next = prev.catch(() => {
|
|
4820
4830
|
}).then(() => this._doFlush(sessionId));
|
|
@@ -4832,7 +4842,6 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4832
4842
|
this.logger.warn("flush: no session found", { sessionId });
|
|
4833
4843
|
return;
|
|
4834
4844
|
}
|
|
4835
|
-
this.emitCoalescedMessage(sessionId, session);
|
|
4836
4845
|
const pending = this.pendingEntries.get(sessionId);
|
|
4837
4846
|
if (!this.posthogAPI || !pending?.length) {
|
|
4838
4847
|
return;
|
|
@@ -4881,11 +4890,17 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4881
4890
|
}
|
|
4882
4891
|
}
|
|
4883
4892
|
}
|
|
4884
|
-
|
|
4885
|
-
if (message.method !== "session/update") return
|
|
4893
|
+
getSessionUpdateType(message) {
|
|
4894
|
+
if (message.method !== "session/update") return void 0;
|
|
4886
4895
|
const params = message.params;
|
|
4887
4896
|
const update = params?.update;
|
|
4888
|
-
return update?.sessionUpdate
|
|
4897
|
+
return update?.sessionUpdate;
|
|
4898
|
+
}
|
|
4899
|
+
isDirectAgentMessage(message) {
|
|
4900
|
+
return this.getSessionUpdateType(message) === "agent_message";
|
|
4901
|
+
}
|
|
4902
|
+
isAgentMessageChunk(message) {
|
|
4903
|
+
return this.getSessionUpdateType(message) === "agent_message_chunk";
|
|
4889
4904
|
}
|
|
4890
4905
|
extractChunkText(message) {
|
|
4891
4906
|
const params = message.params;
|
|
@@ -4930,6 +4945,15 @@ var SessionLogWriter = class _SessionLogWriter {
|
|
|
4930
4945
|
getFullAgentResponse(sessionId) {
|
|
4931
4946
|
const session = this.sessions.get(sessionId);
|
|
4932
4947
|
if (!session || session.currentTurnMessages.length === 0) return void 0;
|
|
4948
|
+
if (session.chunkBuffer) {
|
|
4949
|
+
this.logger.warn(
|
|
4950
|
+
"getFullAgentResponse called with non-empty chunk buffer",
|
|
4951
|
+
{
|
|
4952
|
+
sessionId,
|
|
4953
|
+
bufferedLength: session.chunkBuffer.text.length
|
|
4954
|
+
}
|
|
4955
|
+
);
|
|
4956
|
+
}
|
|
4933
4957
|
return session.currentTurnMessages.join("\n\n");
|
|
4934
4958
|
}
|
|
4935
4959
|
resetTurnMessages(sessionId) {
|
|
@@ -5148,7 +5172,7 @@ var Agent = class {
|
|
|
5148
5172
|
}
|
|
5149
5173
|
async cleanup() {
|
|
5150
5174
|
if (this.sessionLogWriter && this.taskRunId) {
|
|
5151
|
-
await this.sessionLogWriter.flush(this.taskRunId);
|
|
5175
|
+
await this.sessionLogWriter.flush(this.taskRunId, { coalesce: true });
|
|
5152
5176
|
}
|
|
5153
5177
|
await this.acpConnection?.cleanup();
|
|
5154
5178
|
}
|