@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.
- package/dist/adapters/claude/session/jsonl-hydration.d.ts +1 -1
- package/dist/adapters/claude/session/jsonl-hydration.js +6 -4
- package/dist/adapters/claude/session/jsonl-hydration.js.map +1 -1
- package/dist/agent.js +24 -2
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.d.ts +1 -0
- package/dist/posthog-api.js +11 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +51 -15
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +51 -15
- package/dist/server/bin.cjs.map +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +2 -1
- package/src/adapters/acp-connection.ts +6 -1
- package/src/adapters/claude/claude-agent.ts +19 -0
- package/src/adapters/claude/session/jsonl-hydration.ts +7 -5
- package/src/adapters/claude/session/options.ts +3 -0
- package/src/adapters/claude/types.ts +1 -0
- package/src/agent.ts +1 -0
- package/src/posthog-api.ts +14 -0
- package/src/server/agent-server.ts +29 -12
- package/src/types.ts +2 -0
package/dist/server/bin.cjs
CHANGED
|
@@ -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.
|
|
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,
|
|
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
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
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: {
|