@posthog/agent 2.1.118 → 2.1.124

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
@@ -276,7 +276,7 @@ import { v7 as uuidv7 } from "uuid";
276
276
  // package.json
277
277
  var package_default = {
278
278
  name: "@posthog/agent",
279
- version: "2.1.118",
279
+ version: "2.1.124",
280
280
  repository: "https://github.com/PostHog/twig",
281
281
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
282
282
  exports: {
@@ -657,6 +657,10 @@ ${chunk.resource.text}
657
657
  function promptToClaude(prompt) {
658
658
  const content = [];
659
659
  const context = [];
660
+ const prContext = prompt._meta?.prContext;
661
+ if (typeof prContext === "string") {
662
+ content.push(sdkText(prContext));
663
+ }
660
664
  for (const chunk of prompt.prompt) {
661
665
  processPromptChunk(chunk, content, context);
662
666
  }
@@ -2103,9 +2107,10 @@ async function handleAskUserQuestionTool(context) {
2103
2107
  }
2104
2108
  });
2105
2109
  if (response.outcome?.outcome !== "selected") {
2110
+ const customMessage = response._meta?.message;
2106
2111
  return {
2107
2112
  behavior: "deny",
2108
- message: "User cancelled the questions",
2113
+ message: typeof customMessage === "string" ? customMessage : "User cancelled the questions",
2109
2114
  interrupt: true
2110
2115
  };
2111
2116
  }
@@ -3475,6 +3480,16 @@ var PostHogAPIClient = class {
3475
3480
  }
3476
3481
  );
3477
3482
  }
3483
+ async relayMessage(taskId, runId, text2) {
3484
+ const teamId = this.getTeamId();
3485
+ await this.apiRequest(
3486
+ `/api/projects/${teamId}/tasks/${taskId}/runs/${runId}/relay_message/`,
3487
+ {
3488
+ method: "POST",
3489
+ body: JSON.stringify({ text: text2 })
3490
+ }
3491
+ );
3492
+ }
3478
3493
  async uploadTaskArtifacts(taskId, runId, artifacts) {
3479
3494
  if (!artifacts.length) {
3480
3495
  return [];
@@ -3660,6 +3675,10 @@ var SessionLogWriter = class _SessionLogWriter {
3660
3675
  return;
3661
3676
  }
3662
3677
  this.emitCoalescedMessage(sessionId, session);
3678
+ const nonChunkAgentText = this.extractAgentMessageText(message);
3679
+ if (nonChunkAgentText) {
3680
+ session.lastAgentMessage = nonChunkAgentText;
3681
+ }
3663
3682
  const entry = {
3664
3683
  type: "notification",
3665
3684
  timestamp,
@@ -3759,6 +3778,7 @@ var SessionLogWriter = class _SessionLogWriter {
3759
3778
  if (!session.chunkBuffer) return;
3760
3779
  const { text: text2, firstTimestamp } = session.chunkBuffer;
3761
3780
  session.chunkBuffer = void 0;
3781
+ session.lastAgentMessage = text2;
3762
3782
  const entry = {
3763
3783
  type: "notification",
3764
3784
  timestamp: firstTimestamp,
@@ -3781,6 +3801,29 @@ var SessionLogWriter = class _SessionLogWriter {
3781
3801
  this.scheduleFlush(sessionId);
3782
3802
  }
3783
3803
  }
3804
+ getLastAgentMessage(sessionId) {
3805
+ return this.sessions.get(sessionId)?.lastAgentMessage;
3806
+ }
3807
+ extractAgentMessageText(message) {
3808
+ if (message.method !== "session/update") {
3809
+ return null;
3810
+ }
3811
+ const params = message.params;
3812
+ const update = params?.update;
3813
+ if (update?.sessionUpdate !== "agent_message") {
3814
+ return null;
3815
+ }
3816
+ const content = update.content;
3817
+ if (content?.type === "text" && typeof content.text === "string") {
3818
+ const trimmed = content.text.trim();
3819
+ return trimmed.length > 0 ? trimmed : null;
3820
+ }
3821
+ if (typeof update.message === "string") {
3822
+ const trimmed = update.message.trim();
3823
+ return trimmed.length > 0 ? trimmed : null;
3824
+ }
3825
+ return null;
3826
+ }
3784
3827
  scheduleFlush(sessionId) {
3785
3828
  const existing = this.flushTimeouts.get(sessionId);
3786
3829
  if (existing) clearTimeout(existing);