@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/agent.js
CHANGED
|
@@ -276,7 +276,7 @@ import { v7 as uuidv7 } from "uuid";
|
|
|
276
276
|
// package.json
|
|
277
277
|
var package_default = {
|
|
278
278
|
name: "@posthog/agent",
|
|
279
|
-
version: "2.1.
|
|
279
|
+
version: "2.1.62",
|
|
280
280
|
repository: "https://github.com/PostHog/twig",
|
|
281
281
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
282
282
|
exports: {
|
|
@@ -1189,14 +1189,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
|
|
|
1189
1189
|
function messageUpdateType(role) {
|
|
1190
1190
|
return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
|
|
1191
1191
|
}
|
|
1192
|
-
function toolMeta(toolName, toolResponse) {
|
|
1193
|
-
|
|
1192
|
+
function toolMeta(toolName, toolResponse, parentToolCallId) {
|
|
1193
|
+
const meta = { toolName };
|
|
1194
|
+
if (toolResponse !== void 0) meta.toolResponse = toolResponse;
|
|
1195
|
+
if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
|
|
1196
|
+
return { claudeCode: meta };
|
|
1194
1197
|
}
|
|
1195
|
-
function handleTextChunk(chunk, role) {
|
|
1196
|
-
|
|
1198
|
+
function handleTextChunk(chunk, role, parentToolCallId) {
|
|
1199
|
+
const update = {
|
|
1197
1200
|
sessionUpdate: messageUpdateType(role),
|
|
1198
1201
|
content: text(chunk.text)
|
|
1199
1202
|
};
|
|
1203
|
+
if (parentToolCallId) {
|
|
1204
|
+
update._meta = toolMeta(
|
|
1205
|
+
"__text__",
|
|
1206
|
+
void 0,
|
|
1207
|
+
parentToolCallId
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
return update;
|
|
1200
1211
|
}
|
|
1201
1212
|
function handleImageChunk(chunk, role) {
|
|
1202
1213
|
return {
|
|
@@ -1208,11 +1219,19 @@ function handleImageChunk(chunk, role) {
|
|
|
1208
1219
|
)
|
|
1209
1220
|
};
|
|
1210
1221
|
}
|
|
1211
|
-
function handleThinkingChunk(chunk) {
|
|
1212
|
-
|
|
1222
|
+
function handleThinkingChunk(chunk, parentToolCallId) {
|
|
1223
|
+
const update = {
|
|
1213
1224
|
sessionUpdate: "agent_thought_chunk",
|
|
1214
1225
|
content: text(chunk.thinking)
|
|
1215
1226
|
};
|
|
1227
|
+
if (parentToolCallId) {
|
|
1228
|
+
update._meta = toolMeta(
|
|
1229
|
+
"__thinking__",
|
|
1230
|
+
void 0,
|
|
1231
|
+
parentToolCallId
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
return update;
|
|
1216
1235
|
}
|
|
1217
1236
|
function handleToolUseChunk(chunk, ctx) {
|
|
1218
1237
|
ctx.toolUseCache[chunk.id] = chunk;
|
|
@@ -1233,7 +1252,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
1233
1252
|
await ctx.client.sessionUpdate({
|
|
1234
1253
|
sessionId: ctx.sessionId,
|
|
1235
1254
|
update: {
|
|
1236
|
-
_meta: toolMeta(toolUse.name, toolResponse),
|
|
1255
|
+
_meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
|
|
1237
1256
|
toolCallId: toolUseId,
|
|
1238
1257
|
sessionUpdate: "tool_call_update"
|
|
1239
1258
|
}
|
|
@@ -1251,7 +1270,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
1251
1270
|
} catch {
|
|
1252
1271
|
}
|
|
1253
1272
|
return {
|
|
1254
|
-
_meta: toolMeta(chunk.name),
|
|
1273
|
+
_meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
|
|
1255
1274
|
toolCallId: chunk.id,
|
|
1256
1275
|
sessionUpdate: "tool_call",
|
|
1257
1276
|
rawInput,
|
|
@@ -1271,7 +1290,7 @@ function handleToolResultChunk(chunk, ctx) {
|
|
|
1271
1290
|
return null;
|
|
1272
1291
|
}
|
|
1273
1292
|
return {
|
|
1274
|
-
_meta: toolMeta(toolUse.name),
|
|
1293
|
+
_meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
|
|
1275
1294
|
toolCallId: chunk.tool_use_id,
|
|
1276
1295
|
sessionUpdate: "tool_call_update",
|
|
1277
1296
|
status: chunk.is_error ? "failed" : "completed",
|
|
@@ -1285,12 +1304,12 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
1285
1304
|
switch (chunk.type) {
|
|
1286
1305
|
case "text":
|
|
1287
1306
|
case "text_delta":
|
|
1288
|
-
return handleTextChunk(chunk, role);
|
|
1307
|
+
return handleTextChunk(chunk, role, ctx.parentToolCallId);
|
|
1289
1308
|
case "image":
|
|
1290
1309
|
return handleImageChunk(chunk, role);
|
|
1291
1310
|
case "thinking":
|
|
1292
1311
|
case "thinking_delta":
|
|
1293
|
-
return handleThinkingChunk(chunk);
|
|
1312
|
+
return handleThinkingChunk(chunk, ctx.parentToolCallId);
|
|
1294
1313
|
case "tool_use":
|
|
1295
1314
|
case "server_tool_use":
|
|
1296
1315
|
case "mcp_tool_use":
|
|
@@ -1320,24 +1339,28 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
1320
1339
|
return null;
|
|
1321
1340
|
}
|
|
1322
1341
|
}
|
|
1323
|
-
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
1342
|
+
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
1324
1343
|
if (typeof content === "string") {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1344
|
+
const update = {
|
|
1345
|
+
sessionUpdate: messageUpdateType(role),
|
|
1346
|
+
content: text(content)
|
|
1347
|
+
};
|
|
1348
|
+
if (parentToolCallId) {
|
|
1349
|
+
update._meta = toolMeta(
|
|
1350
|
+
"__text__",
|
|
1351
|
+
void 0,
|
|
1352
|
+
parentToolCallId
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
return [{ sessionId, update }];
|
|
1334
1356
|
}
|
|
1335
1357
|
const ctx = {
|
|
1336
1358
|
sessionId,
|
|
1337
1359
|
toolUseCache,
|
|
1338
1360
|
fileContentCache,
|
|
1339
1361
|
client,
|
|
1340
|
-
logger
|
|
1362
|
+
logger,
|
|
1363
|
+
parentToolCallId
|
|
1341
1364
|
};
|
|
1342
1365
|
const output = [];
|
|
1343
1366
|
for (const chunk of content) {
|
|
@@ -1348,7 +1371,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
|
|
|
1348
1371
|
}
|
|
1349
1372
|
return output;
|
|
1350
1373
|
}
|
|
1351
|
-
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
1374
|
+
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
1352
1375
|
const event = message.event;
|
|
1353
1376
|
switch (event.type) {
|
|
1354
1377
|
case "content_block_start":
|
|
@@ -1359,7 +1382,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
1359
1382
|
toolUseCache,
|
|
1360
1383
|
fileContentCache,
|
|
1361
1384
|
client,
|
|
1362
|
-
logger
|
|
1385
|
+
logger,
|
|
1386
|
+
parentToolCallId
|
|
1363
1387
|
);
|
|
1364
1388
|
case "content_block_delta":
|
|
1365
1389
|
return toAcpNotifications(
|
|
@@ -1369,7 +1393,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
1369
1393
|
toolUseCache,
|
|
1370
1394
|
fileContentCache,
|
|
1371
1395
|
client,
|
|
1372
|
-
logger
|
|
1396
|
+
logger,
|
|
1397
|
+
parentToolCallId
|
|
1373
1398
|
);
|
|
1374
1399
|
case "message_start":
|
|
1375
1400
|
case "message_delta":
|
|
@@ -1482,13 +1507,15 @@ function handleResultMessage(message, context) {
|
|
|
1482
1507
|
}
|
|
1483
1508
|
async function handleStreamEvent(message, context) {
|
|
1484
1509
|
const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
|
|
1510
|
+
const parentToolCallId = message.parent_tool_use_id ?? void 0;
|
|
1485
1511
|
for (const notification of streamEventToAcpNotifications(
|
|
1486
1512
|
message,
|
|
1487
1513
|
sessionId,
|
|
1488
1514
|
toolUseCache,
|
|
1489
1515
|
fileContentCache,
|
|
1490
1516
|
client,
|
|
1491
|
-
logger
|
|
1517
|
+
logger,
|
|
1518
|
+
parentToolCallId
|
|
1492
1519
|
)) {
|
|
1493
1520
|
await client.sessionUpdate(notification);
|
|
1494
1521
|
context.session.notificationHistory.push(notification);
|
|
@@ -1540,6 +1567,7 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
1540
1567
|
}
|
|
1541
1568
|
const content = message.message.content;
|
|
1542
1569
|
const contentToProcess = filterMessageContent(content);
|
|
1570
|
+
const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
|
|
1543
1571
|
for (const notification of toAcpNotifications(
|
|
1544
1572
|
contentToProcess,
|
|
1545
1573
|
message.message.role,
|
|
@@ -1547,7 +1575,8 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
1547
1575
|
toolUseCache,
|
|
1548
1576
|
fileContentCache,
|
|
1549
1577
|
client,
|
|
1550
|
-
logger
|
|
1578
|
+
logger,
|
|
1579
|
+
parentToolCallId
|
|
1551
1580
|
)) {
|
|
1552
1581
|
await client.sessionUpdate(notification);
|
|
1553
1582
|
session.notificationHistory.push(notification);
|
|
@@ -2829,6 +2858,11 @@ function findCodexBinary(options) {
|
|
|
2829
2858
|
if (options.binaryPath && existsSync3(options.binaryPath)) {
|
|
2830
2859
|
return { command: options.binaryPath, args: configArgs };
|
|
2831
2860
|
}
|
|
2861
|
+
if (options.binaryPath) {
|
|
2862
|
+
throw new Error(
|
|
2863
|
+
`codex-acp binary not found at ${options.binaryPath}. Run "node apps/twig/scripts/download-binaries.mjs" to download it.`
|
|
2864
|
+
);
|
|
2865
|
+
}
|
|
2832
2866
|
return { command: "npx", args: ["@zed-industries/codex-acp", ...configArgs] };
|
|
2833
2867
|
}
|
|
2834
2868
|
function spawnCodexProcess(options) {
|