@posthog/agent 2.3.131 → 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 +57 -29
- 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 +57 -29
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +57 -29
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/claude-agent.ts +72 -38
- package/src/adapters/claude/types.ts +2 -0
package/package.json
CHANGED
|
@@ -876,58 +876,92 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
876
876
|
{ sessionId, taskId, taskRunId: meta?.taskRunId },
|
|
877
877
|
);
|
|
878
878
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
`Session ${isResume ? (forkSession ? "fork" : "resumption") : "initialization"} timed out for sessionId=${sessionId}`,
|
|
879
|
+
if (isResume) {
|
|
880
|
+
// Resume must block on initialization to validate the session is still alive.
|
|
881
|
+
// For stale sessions this throws (e.g. "No conversation found").
|
|
882
|
+
try {
|
|
883
|
+
const result = await withTimeout(
|
|
884
|
+
q.initializationResult(),
|
|
885
|
+
SESSION_VALIDATION_TIMEOUT_MS,
|
|
887
886
|
);
|
|
887
|
+
if (result.result === "timeout") {
|
|
888
|
+
throw new Error(
|
|
889
|
+
`Session ${forkSession ? "fork" : "resumption"} timed out for sessionId=${sessionId}`,
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
} catch (err) {
|
|
893
|
+
settingsManager.dispose();
|
|
894
|
+
if (
|
|
895
|
+
err instanceof Error &&
|
|
896
|
+
err.message === "Query closed before response received"
|
|
897
|
+
) {
|
|
898
|
+
throw RequestError.resourceNotFound(sessionId);
|
|
899
|
+
}
|
|
900
|
+
this.logger.error(
|
|
901
|
+
forkSession ? "Session fork failed" : "Session resumption failed",
|
|
902
|
+
{
|
|
903
|
+
sessionId,
|
|
904
|
+
taskId,
|
|
905
|
+
taskRunId: meta?.taskRunId,
|
|
906
|
+
error: err instanceof Error ? err.message : String(err),
|
|
907
|
+
},
|
|
908
|
+
);
|
|
909
|
+
throw err;
|
|
888
910
|
}
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
this.
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Kick off SDK initialization for new sessions so it runs concurrently
|
|
914
|
+
// with the model config fetch below (the gateway REST call is independent).
|
|
915
|
+
const initPromise = !isResume
|
|
916
|
+
? withTimeout(q.initializationResult(), SESSION_VALIDATION_TIMEOUT_MS)
|
|
917
|
+
: undefined;
|
|
918
|
+
|
|
919
|
+
const [modelOptions] = await Promise.all([
|
|
920
|
+
this.getModelConfigOptions(
|
|
921
|
+
settingsManager.getSettings().model || meta?.model || undefined,
|
|
922
|
+
),
|
|
923
|
+
...(meta?.taskRunId
|
|
924
|
+
? [
|
|
925
|
+
this.client.extNotification("_posthog/sdk_session", {
|
|
926
|
+
taskRunId: meta.taskRunId,
|
|
927
|
+
sessionId,
|
|
928
|
+
adapter: "claude",
|
|
929
|
+
}),
|
|
930
|
+
]
|
|
931
|
+
: []),
|
|
932
|
+
]);
|
|
933
|
+
|
|
934
|
+
if (initPromise) {
|
|
935
|
+
try {
|
|
936
|
+
const initResult = await initPromise;
|
|
937
|
+
if (initResult.result === "timeout") {
|
|
938
|
+
settingsManager.dispose();
|
|
939
|
+
throw new Error(
|
|
940
|
+
`Session initialization timed out for sessionId=${sessionId}`,
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
} catch (err) {
|
|
944
|
+
settingsManager.dispose();
|
|
945
|
+
this.logger.error("Session initialization failed", {
|
|
905
946
|
sessionId,
|
|
906
947
|
taskId,
|
|
907
948
|
taskRunId: meta?.taskRunId,
|
|
908
949
|
error: err instanceof Error ? err.message : String(err),
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
if (meta?.taskRunId) {
|
|
915
|
-
await this.client.extNotification("_posthog/sdk_session", {
|
|
916
|
-
taskRunId: meta.taskRunId,
|
|
917
|
-
sessionId,
|
|
918
|
-
adapter: "claude",
|
|
919
|
-
});
|
|
950
|
+
});
|
|
951
|
+
throw err;
|
|
952
|
+
}
|
|
920
953
|
}
|
|
921
954
|
|
|
922
|
-
// Resolve model: settings model takes priority, then gateway
|
|
923
955
|
const settingsModel = settingsManager.getSettings().model;
|
|
924
|
-
const
|
|
925
|
-
const resolvedModelId =
|
|
956
|
+
const metaModel = meta?.model;
|
|
957
|
+
const resolvedModelId =
|
|
958
|
+
settingsModel || metaModel || modelOptions.currentModelId;
|
|
926
959
|
session.modelId = resolvedModelId;
|
|
927
960
|
session.lastContextWindowSize =
|
|
928
961
|
this.getContextWindowForModel(resolvedModelId);
|
|
929
962
|
|
|
930
963
|
const resolvedSdkModel = toSdkModelId(resolvedModelId);
|
|
964
|
+
|
|
931
965
|
if (!isResume && resolvedSdkModel !== DEFAULT_MODEL) {
|
|
932
966
|
await this.session.query.setModel(resolvedSdkModel);
|
|
933
967
|
}
|
|
@@ -108,6 +108,8 @@ export type NewSessionMeta = {
|
|
|
108
108
|
persistence?: { taskId?: string; runId?: string; logUrl?: string };
|
|
109
109
|
additionalRoots?: string[];
|
|
110
110
|
allowedDomains?: string[];
|
|
111
|
+
/** Model ID to use for this session (e.g. "claude-sonnet-4-6") */
|
|
112
|
+
model?: string;
|
|
111
113
|
claudeCode?: {
|
|
112
114
|
options?: Options;
|
|
113
115
|
};
|