@posthog/agent 2.3.233 → 2.3.259

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.
@@ -5683,7 +5683,7 @@ var import_hono = require("hono");
5683
5683
  // package.json
5684
5684
  var package_default = {
5685
5685
  name: "@posthog/agent",
5686
- version: "2.3.233",
5686
+ version: "2.3.259",
5687
5687
  repository: "https://github.com/PostHog/code",
5688
5688
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
5689
5689
  exports: {
@@ -5779,6 +5779,7 @@ var package_default = {
5779
5779
  },
5780
5780
  dependencies: {
5781
5781
  "@agentclientprotocol/sdk": "0.16.1",
5782
+ ajv: "^8.17.1",
5782
5783
  "@anthropic-ai/claude-agent-sdk": "0.2.76",
5783
5784
  "@anthropic-ai/sdk": "^0.78.0",
5784
5785
  "@hono/node-server": "^1.19.9",
@@ -8630,6 +8631,7 @@ function buildSessionOptions(params) {
8630
8631
  params.settingsManager,
8631
8632
  params.logger
8632
8633
  ),
8634
+ outputFormat: params.outputFormat,
8633
8635
  abortController: getAbortController(
8634
8636
  params.userProvidedOptions?.abortController
8635
8637
  ),
@@ -9217,6 +9219,11 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9217
9219
  };
9218
9220
  const result = handleResultMessage(message);
9219
9221
  if (result.error) throw result.error;
9222
+ if (message.subtype === "success" && message.structured_output != null && this.options?.onStructuredOutput) {
9223
+ await this.options.onStructuredOutput(
9224
+ message.structured_output
9225
+ );
9226
+ }
9220
9227
  if (isLocalOnlyCommand && message.subtype === "success" && message.result) {
9221
9228
  await this.client.sessionUpdate({
9222
9229
  sessionId: params.sessionId,
@@ -9442,6 +9449,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9442
9449
  const earlyModelId = settingsManager.getSettings().model || meta?.model || "";
9443
9450
  const mcpServers = supportsMcpInjection(earlyModelId) ? parseMcpServers(params) : {};
9444
9451
  const systemPrompt = buildSystemPrompt(meta?.systemPrompt);
9452
+ const outputFormat = meta?.jsonSchema && this.options?.onStructuredOutput ? { type: "json_schema", schema: meta.jsonSchema } : void 0;
9445
9453
  this.logger.info(isResume ? "Resuming session" : "Creating new session", {
9446
9454
  sessionId,
9447
9455
  taskId,
@@ -9465,6 +9473,7 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
9465
9473
  ...meta?.additionalRoots ?? []
9466
9474
  ],
9467
9475
  disableBuiltInTools: meta?.disableBuiltInTools,
9476
+ outputFormat,
9468
9477
  settingsManager,
9469
9478
  onModeChange: this.createOnModeChange(),
9470
9479
  onProcessSpawned: this.options?.onProcessSpawned,
@@ -10424,7 +10433,10 @@ function createClaudeConnection(config) {
10424
10433
  const agentStream = (0, import_sdk4.ndJsonStream)(agentWritable, streams.agent.readable);
10425
10434
  let agent = null;
10426
10435
  const agentConnection = new import_sdk4.AgentSideConnection((client) => {
10427
- agent = new ClaudeAcpAgent(client, config.processCallbacks);
10436
+ agent = new ClaudeAcpAgent(client, {
10437
+ ...config.processCallbacks,
10438
+ onStructuredOutput: config.onStructuredOutput
10439
+ });
10428
10440
  logger.info(`Created ${agent.adapterName} agent`);
10429
10441
  return agent;
10430
10442
  }, agentStream);
@@ -10656,6 +10668,15 @@ var PostHogAPIClient = class {
10656
10668
  }
10657
10669
  );
10658
10670
  }
10671
+ async setTaskRunOutput(taskId, runId, output) {
10672
+ return this.apiRequest(
10673
+ `/api/projects/${this.getTeamId()}/tasks/${taskId}/runs/${runId}/set_output/`,
10674
+ {
10675
+ method: "PATCH",
10676
+ body: JSON.stringify(output)
10677
+ }
10678
+ );
10679
+ }
10659
10680
  async appendTaskRunLog(taskId, runId, entries) {
10660
10681
  const teamId = this.getTeamId();
10661
10682
  return this.apiRequest(
@@ -12704,7 +12725,16 @@ You MUST NOT create a new branch, close the existing PR, or create a new PR.`
12704
12725
  taskRunId: payload.run_id,
12705
12726
  taskId: payload.task_id,
12706
12727
  deviceType: deviceInfo.type,
12707
- logWriter
12728
+ logWriter,
12729
+ onStructuredOutput: async (output) => {
12730
+ await this.posthogAPI.setTaskRunOutput(
12731
+ payload.task_id,
12732
+ payload.run_id,
12733
+ {
12734
+ output
12735
+ }
12736
+ );
12737
+ }
12708
12738
  });
12709
12739
  const onAcpMessage = (message) => {
12710
12740
  this.broadcastEvent({
@@ -12732,18 +12762,23 @@ You MUST NOT create a new branch, close the existing PR, or create a new PR.`
12732
12762
  protocolVersion: import_sdk5.PROTOCOL_VERSION,
12733
12763
  clientCapabilities: {}
12734
12764
  });
12735
- let preTaskRun = null;
12736
- try {
12737
- preTaskRun = await this.posthogAPI.getTaskRun(
12738
- payload.task_id,
12739
- payload.run_id
12740
- );
12741
- } catch {
12742
- this.logger.warn("Failed to fetch task run for session context", {
12743
- taskId: payload.task_id,
12744
- runId: payload.run_id
12745
- });
12746
- }
12765
+ const [preTaskRun, preTask] = await Promise.all([
12766
+ this.posthogAPI.getTaskRun(payload.task_id, payload.run_id).catch((err) => {
12767
+ this.logger.warn("Failed to fetch task run for session context", {
12768
+ taskId: payload.task_id,
12769
+ runId: payload.run_id,
12770
+ error: err
12771
+ });
12772
+ return null;
12773
+ }),
12774
+ this.posthogAPI.getTask(payload.task_id).catch((err) => {
12775
+ this.logger.warn("Failed to fetch task for session context", {
12776
+ taskId: payload.task_id,
12777
+ error: err
12778
+ });
12779
+ return null;
12780
+ })
12781
+ ]);
12747
12782
  const prUrl = typeof preTaskRun?.state?.slack_notified_pr_url === "string" ? (preTaskRun?.state).slack_notified_pr_url : null;
12748
12783
  if (prUrl) {
12749
12784
  this.detectedPrUrl = prUrl;
@@ -12756,6 +12791,7 @@ You MUST NOT create a new branch, close the existing PR, or create a new PR.`
12756
12791
  taskRunId: payload.run_id,
12757
12792
  systemPrompt: this.buildSessionSystemPrompt(prUrl),
12758
12793
  allowedDomains: this.config.allowedDomains,
12794
+ jsonSchema: preTask?.json_schema ?? null,
12759
12795
  ...this.config.claudeCode?.plugins?.length && {
12760
12796
  claudeCode: {
12761
12797
  options: {