@posthog/agent 2.1.59 → 2.1.62
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 +62 -28
- package/dist/agent.js.map +1 -1
- package/dist/index.js +62 -28
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +62 -28
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +62 -28
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/conversion/sdk-to-acp.ts +62 -23
- package/src/adapters/claude/types.ts +1 -0
- package/src/adapters/codex/spawn.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -1174,7 +1174,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
1174
1174
|
// package.json
|
|
1175
1175
|
var package_default = {
|
|
1176
1176
|
name: "@posthog/agent",
|
|
1177
|
-
version: "2.1.
|
|
1177
|
+
version: "2.1.62",
|
|
1178
1178
|
repository: "https://github.com/PostHog/twig",
|
|
1179
1179
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
1180
1180
|
exports: {
|
|
@@ -2095,14 +2095,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
|
|
|
2095
2095
|
function messageUpdateType(role) {
|
|
2096
2096
|
return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
|
|
2097
2097
|
}
|
|
2098
|
-
function toolMeta(toolName, toolResponse) {
|
|
2099
|
-
|
|
2098
|
+
function toolMeta(toolName, toolResponse, parentToolCallId) {
|
|
2099
|
+
const meta = { toolName };
|
|
2100
|
+
if (toolResponse !== void 0) meta.toolResponse = toolResponse;
|
|
2101
|
+
if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
|
|
2102
|
+
return { claudeCode: meta };
|
|
2100
2103
|
}
|
|
2101
|
-
function handleTextChunk(chunk, role) {
|
|
2102
|
-
|
|
2104
|
+
function handleTextChunk(chunk, role, parentToolCallId) {
|
|
2105
|
+
const update = {
|
|
2103
2106
|
sessionUpdate: messageUpdateType(role),
|
|
2104
2107
|
content: text(chunk.text)
|
|
2105
2108
|
};
|
|
2109
|
+
if (parentToolCallId) {
|
|
2110
|
+
update._meta = toolMeta(
|
|
2111
|
+
"__text__",
|
|
2112
|
+
void 0,
|
|
2113
|
+
parentToolCallId
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
return update;
|
|
2106
2117
|
}
|
|
2107
2118
|
function handleImageChunk(chunk, role) {
|
|
2108
2119
|
return {
|
|
@@ -2114,11 +2125,19 @@ function handleImageChunk(chunk, role) {
|
|
|
2114
2125
|
)
|
|
2115
2126
|
};
|
|
2116
2127
|
}
|
|
2117
|
-
function handleThinkingChunk(chunk) {
|
|
2118
|
-
|
|
2128
|
+
function handleThinkingChunk(chunk, parentToolCallId) {
|
|
2129
|
+
const update = {
|
|
2119
2130
|
sessionUpdate: "agent_thought_chunk",
|
|
2120
2131
|
content: text(chunk.thinking)
|
|
2121
2132
|
};
|
|
2133
|
+
if (parentToolCallId) {
|
|
2134
|
+
update._meta = toolMeta(
|
|
2135
|
+
"__thinking__",
|
|
2136
|
+
void 0,
|
|
2137
|
+
parentToolCallId
|
|
2138
|
+
);
|
|
2139
|
+
}
|
|
2140
|
+
return update;
|
|
2122
2141
|
}
|
|
2123
2142
|
function handleToolUseChunk(chunk, ctx) {
|
|
2124
2143
|
ctx.toolUseCache[chunk.id] = chunk;
|
|
@@ -2139,7 +2158,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2139
2158
|
await ctx.client.sessionUpdate({
|
|
2140
2159
|
sessionId: ctx.sessionId,
|
|
2141
2160
|
update: {
|
|
2142
|
-
_meta: toolMeta(toolUse.name, toolResponse),
|
|
2161
|
+
_meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
|
|
2143
2162
|
toolCallId: toolUseId,
|
|
2144
2163
|
sessionUpdate: "tool_call_update"
|
|
2145
2164
|
}
|
|
@@ -2157,7 +2176,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2157
2176
|
} catch {
|
|
2158
2177
|
}
|
|
2159
2178
|
return {
|
|
2160
|
-
_meta: toolMeta(chunk.name),
|
|
2179
|
+
_meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
|
|
2161
2180
|
toolCallId: chunk.id,
|
|
2162
2181
|
sessionUpdate: "tool_call",
|
|
2163
2182
|
rawInput,
|
|
@@ -2177,7 +2196,7 @@ function handleToolResultChunk(chunk, ctx) {
|
|
|
2177
2196
|
return null;
|
|
2178
2197
|
}
|
|
2179
2198
|
return {
|
|
2180
|
-
_meta: toolMeta(toolUse.name),
|
|
2199
|
+
_meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
|
|
2181
2200
|
toolCallId: chunk.tool_use_id,
|
|
2182
2201
|
sessionUpdate: "tool_call_update",
|
|
2183
2202
|
status: chunk.is_error ? "failed" : "completed",
|
|
@@ -2191,12 +2210,12 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2191
2210
|
switch (chunk.type) {
|
|
2192
2211
|
case "text":
|
|
2193
2212
|
case "text_delta":
|
|
2194
|
-
return handleTextChunk(chunk, role);
|
|
2213
|
+
return handleTextChunk(chunk, role, ctx.parentToolCallId);
|
|
2195
2214
|
case "image":
|
|
2196
2215
|
return handleImageChunk(chunk, role);
|
|
2197
2216
|
case "thinking":
|
|
2198
2217
|
case "thinking_delta":
|
|
2199
|
-
return handleThinkingChunk(chunk);
|
|
2218
|
+
return handleThinkingChunk(chunk, ctx.parentToolCallId);
|
|
2200
2219
|
case "tool_use":
|
|
2201
2220
|
case "server_tool_use":
|
|
2202
2221
|
case "mcp_tool_use":
|
|
@@ -2226,24 +2245,28 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2226
2245
|
return null;
|
|
2227
2246
|
}
|
|
2228
2247
|
}
|
|
2229
|
-
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2248
|
+
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2230
2249
|
if (typeof content === "string") {
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2250
|
+
const update = {
|
|
2251
|
+
sessionUpdate: messageUpdateType(role),
|
|
2252
|
+
content: text(content)
|
|
2253
|
+
};
|
|
2254
|
+
if (parentToolCallId) {
|
|
2255
|
+
update._meta = toolMeta(
|
|
2256
|
+
"__text__",
|
|
2257
|
+
void 0,
|
|
2258
|
+
parentToolCallId
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
return [{ sessionId, update }];
|
|
2240
2262
|
}
|
|
2241
2263
|
const ctx = {
|
|
2242
2264
|
sessionId,
|
|
2243
2265
|
toolUseCache,
|
|
2244
2266
|
fileContentCache,
|
|
2245
2267
|
client,
|
|
2246
|
-
logger
|
|
2268
|
+
logger,
|
|
2269
|
+
parentToolCallId
|
|
2247
2270
|
};
|
|
2248
2271
|
const output = [];
|
|
2249
2272
|
for (const chunk of content) {
|
|
@@ -2254,7 +2277,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
|
|
|
2254
2277
|
}
|
|
2255
2278
|
return output;
|
|
2256
2279
|
}
|
|
2257
|
-
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2280
|
+
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2258
2281
|
const event = message.event;
|
|
2259
2282
|
switch (event.type) {
|
|
2260
2283
|
case "content_block_start":
|
|
@@ -2265,7 +2288,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2265
2288
|
toolUseCache,
|
|
2266
2289
|
fileContentCache,
|
|
2267
2290
|
client,
|
|
2268
|
-
logger
|
|
2291
|
+
logger,
|
|
2292
|
+
parentToolCallId
|
|
2269
2293
|
);
|
|
2270
2294
|
case "content_block_delta":
|
|
2271
2295
|
return toAcpNotifications(
|
|
@@ -2275,7 +2299,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2275
2299
|
toolUseCache,
|
|
2276
2300
|
fileContentCache,
|
|
2277
2301
|
client,
|
|
2278
|
-
logger
|
|
2302
|
+
logger,
|
|
2303
|
+
parentToolCallId
|
|
2279
2304
|
);
|
|
2280
2305
|
case "message_start":
|
|
2281
2306
|
case "message_delta":
|
|
@@ -2388,13 +2413,15 @@ function handleResultMessage(message, context) {
|
|
|
2388
2413
|
}
|
|
2389
2414
|
async function handleStreamEvent(message, context) {
|
|
2390
2415
|
const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
|
|
2416
|
+
const parentToolCallId = message.parent_tool_use_id ?? void 0;
|
|
2391
2417
|
for (const notification of streamEventToAcpNotifications(
|
|
2392
2418
|
message,
|
|
2393
2419
|
sessionId,
|
|
2394
2420
|
toolUseCache,
|
|
2395
2421
|
fileContentCache,
|
|
2396
2422
|
client,
|
|
2397
|
-
logger
|
|
2423
|
+
logger,
|
|
2424
|
+
parentToolCallId
|
|
2398
2425
|
)) {
|
|
2399
2426
|
await client.sessionUpdate(notification);
|
|
2400
2427
|
context.session.notificationHistory.push(notification);
|
|
@@ -2446,6 +2473,7 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2446
2473
|
}
|
|
2447
2474
|
const content = message.message.content;
|
|
2448
2475
|
const contentToProcess = filterMessageContent(content);
|
|
2476
|
+
const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
|
|
2449
2477
|
for (const notification of toAcpNotifications(
|
|
2450
2478
|
contentToProcess,
|
|
2451
2479
|
message.message.role,
|
|
@@ -2453,7 +2481,8 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2453
2481
|
toolUseCache,
|
|
2454
2482
|
fileContentCache,
|
|
2455
2483
|
client,
|
|
2456
|
-
logger
|
|
2484
|
+
logger,
|
|
2485
|
+
parentToolCallId
|
|
2457
2486
|
)) {
|
|
2458
2487
|
await client.sessionUpdate(notification);
|
|
2459
2488
|
session.notificationHistory.push(notification);
|
|
@@ -3735,6 +3764,11 @@ function findCodexBinary(options) {
|
|
|
3735
3764
|
if (options.binaryPath && existsSync3(options.binaryPath)) {
|
|
3736
3765
|
return { command: options.binaryPath, args: configArgs };
|
|
3737
3766
|
}
|
|
3767
|
+
if (options.binaryPath) {
|
|
3768
|
+
throw new Error(
|
|
3769
|
+
`codex-acp binary not found at ${options.binaryPath}. Run "node apps/twig/scripts/download-binaries.mjs" to download it.`
|
|
3770
|
+
);
|
|
3771
|
+
}
|
|
3738
3772
|
return { command: "npx", args: ["@zed-industries/codex-acp", ...configArgs] };
|
|
3739
3773
|
}
|
|
3740
3774
|
function spawnCodexProcess(options) {
|