@posthog/agent 2.3.126 → 2.3.137

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
@@ -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.126",
374
+ version: "2.3.137",
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: {
@@ -3767,42 +3767,70 @@ var ClaudeAcpAgent = class extends BaseAcpAgent {
3767
3767
  isResume ? "Session query initialized, awaiting resumption" : "Session query initialized, awaiting initialization",
3768
3768
  { sessionId, taskId, taskRunId: meta?.taskRunId }
3769
3769
  );
3770
- try {
3771
- const result = await withTimeout(
3772
- q.initializationResult(),
3773
- SESSION_VALIDATION_TIMEOUT_MS
3774
- );
3775
- if (result.result === "timeout") {
3776
- throw new Error(
3777
- `Session ${isResume ? forkSession ? "fork" : "resumption" : "initialization"} timed out for sessionId=${sessionId}`
3770
+ if (isResume) {
3771
+ try {
3772
+ const result = await withTimeout(
3773
+ q.initializationResult(),
3774
+ SESSION_VALIDATION_TIMEOUT_MS
3778
3775
  );
3776
+ if (result.result === "timeout") {
3777
+ throw new Error(
3778
+ `Session ${forkSession ? "fork" : "resumption"} timed out for sessionId=${sessionId}`
3779
+ );
3780
+ }
3781
+ } catch (err) {
3782
+ settingsManager.dispose();
3783
+ if (err instanceof Error && err.message === "Query closed before response received") {
3784
+ throw RequestError2.resourceNotFound(sessionId);
3785
+ }
3786
+ this.logger.error(
3787
+ forkSession ? "Session fork failed" : "Session resumption failed",
3788
+ {
3789
+ sessionId,
3790
+ taskId,
3791
+ taskRunId: meta?.taskRunId,
3792
+ error: err instanceof Error ? err.message : String(err)
3793
+ }
3794
+ );
3795
+ throw err;
3779
3796
  }
3780
- } catch (err) {
3781
- settingsManager.dispose();
3782
- if (isResume && err instanceof Error && err.message === "Query closed before response received") {
3783
- throw RequestError2.resourceNotFound(sessionId);
3784
- }
3785
- this.logger.error(
3786
- isResume ? forkSession ? "Session fork failed" : "Session resumption failed" : "Session initialization failed",
3787
- {
3797
+ }
3798
+ const initPromise = !isResume ? withTimeout(q.initializationResult(), SESSION_VALIDATION_TIMEOUT_MS) : void 0;
3799
+ const [modelOptions] = await Promise.all([
3800
+ this.getModelConfigOptions(
3801
+ settingsManager.getSettings().model || meta?.model || void 0
3802
+ ),
3803
+ ...meta?.taskRunId ? [
3804
+ this.client.extNotification("_posthog/sdk_session", {
3805
+ taskRunId: meta.taskRunId,
3806
+ sessionId,
3807
+ adapter: "claude"
3808
+ })
3809
+ ] : []
3810
+ ]);
3811
+ if (initPromise) {
3812
+ try {
3813
+ const initResult = await initPromise;
3814
+ if (initResult.result === "timeout") {
3815
+ settingsManager.dispose();
3816
+ throw new Error(
3817
+ `Session initialization timed out for sessionId=${sessionId}`
3818
+ );
3819
+ }
3820
+ } catch (err) {
3821
+ settingsManager.dispose();
3822
+ this.logger.error("Session initialization failed", {
3788
3823
  sessionId,
3789
3824
  taskId,
3790
3825
  taskRunId: meta?.taskRunId,
3791
3826
  error: err instanceof Error ? err.message : String(err)
3792
- }
3793
- );
3794
- throw err;
3795
- }
3796
- if (meta?.taskRunId) {
3797
- await this.client.extNotification("_posthog/sdk_session", {
3798
- taskRunId: meta.taskRunId,
3799
- sessionId,
3800
- adapter: "claude"
3801
- });
3827
+ });
3828
+ throw err;
3829
+ }
3802
3830
  }
3803
3831
  const settingsModel = settingsManager.getSettings().model;
3804
- const modelOptions = await this.getModelConfigOptions();
3805
- const resolvedModelId = settingsModel || modelOptions.currentModelId;
3832
+ const metaModel = meta?.model;
3833
+ const resolvedModelId = settingsModel || metaModel || modelOptions.currentModelId;
3806
3834
  session.modelId = resolvedModelId;
3807
3835
  session.lastContextWindowSize = this.getContextWindowForModel(resolvedModelId);
3808
3836
  const resolvedSdkModel = toSdkModelId(resolvedModelId);