@posthog/agent 2.1.53 → 2.1.60
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 +59 -29
- package/dist/agent.js.map +1 -1
- package/dist/index.js +59 -29
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +59 -29
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +59 -29
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -2
- package/src/adapters/claude/conversion/sdk-to-acp.ts +62 -23
- package/src/adapters/claude/types.ts +1 -0
package/dist/server/bin.cjs
CHANGED
|
@@ -1175,7 +1175,7 @@ var import_uuid = require("uuid");
|
|
|
1175
1175
|
// package.json
|
|
1176
1176
|
var package_default = {
|
|
1177
1177
|
name: "@posthog/agent",
|
|
1178
|
-
version: "2.1.
|
|
1178
|
+
version: "2.1.60",
|
|
1179
1179
|
repository: "https://github.com/PostHog/twig",
|
|
1180
1180
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
1181
1181
|
exports: {
|
|
@@ -1240,7 +1240,8 @@ var package_default = {
|
|
|
1240
1240
|
test: "vitest run",
|
|
1241
1241
|
"test:watch": "vitest",
|
|
1242
1242
|
typecheck: "pnpm exec tsc --noEmit",
|
|
1243
|
-
prepublishOnly: "pnpm run build"
|
|
1243
|
+
prepublishOnly: "pnpm run build",
|
|
1244
|
+
clean: "rm -rf dist .turbo"
|
|
1244
1245
|
},
|
|
1245
1246
|
engines: {
|
|
1246
1247
|
node: ">=20.0.0"
|
|
@@ -2051,14 +2052,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
|
|
|
2051
2052
|
function messageUpdateType(role) {
|
|
2052
2053
|
return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
|
|
2053
2054
|
}
|
|
2054
|
-
function toolMeta(toolName, toolResponse) {
|
|
2055
|
-
|
|
2055
|
+
function toolMeta(toolName, toolResponse, parentToolCallId) {
|
|
2056
|
+
const meta = { toolName };
|
|
2057
|
+
if (toolResponse !== void 0) meta.toolResponse = toolResponse;
|
|
2058
|
+
if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
|
|
2059
|
+
return { claudeCode: meta };
|
|
2056
2060
|
}
|
|
2057
|
-
function handleTextChunk(chunk, role) {
|
|
2058
|
-
|
|
2061
|
+
function handleTextChunk(chunk, role, parentToolCallId) {
|
|
2062
|
+
const update = {
|
|
2059
2063
|
sessionUpdate: messageUpdateType(role),
|
|
2060
2064
|
content: text(chunk.text)
|
|
2061
2065
|
};
|
|
2066
|
+
if (parentToolCallId) {
|
|
2067
|
+
update._meta = toolMeta(
|
|
2068
|
+
"__text__",
|
|
2069
|
+
void 0,
|
|
2070
|
+
parentToolCallId
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2073
|
+
return update;
|
|
2062
2074
|
}
|
|
2063
2075
|
function handleImageChunk(chunk, role) {
|
|
2064
2076
|
return {
|
|
@@ -2070,11 +2082,19 @@ function handleImageChunk(chunk, role) {
|
|
|
2070
2082
|
)
|
|
2071
2083
|
};
|
|
2072
2084
|
}
|
|
2073
|
-
function handleThinkingChunk(chunk) {
|
|
2074
|
-
|
|
2085
|
+
function handleThinkingChunk(chunk, parentToolCallId) {
|
|
2086
|
+
const update = {
|
|
2075
2087
|
sessionUpdate: "agent_thought_chunk",
|
|
2076
2088
|
content: text(chunk.thinking)
|
|
2077
2089
|
};
|
|
2090
|
+
if (parentToolCallId) {
|
|
2091
|
+
update._meta = toolMeta(
|
|
2092
|
+
"__thinking__",
|
|
2093
|
+
void 0,
|
|
2094
|
+
parentToolCallId
|
|
2095
|
+
);
|
|
2096
|
+
}
|
|
2097
|
+
return update;
|
|
2078
2098
|
}
|
|
2079
2099
|
function handleToolUseChunk(chunk, ctx) {
|
|
2080
2100
|
ctx.toolUseCache[chunk.id] = chunk;
|
|
@@ -2095,7 +2115,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2095
2115
|
await ctx.client.sessionUpdate({
|
|
2096
2116
|
sessionId: ctx.sessionId,
|
|
2097
2117
|
update: {
|
|
2098
|
-
_meta: toolMeta(toolUse.name, toolResponse),
|
|
2118
|
+
_meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
|
|
2099
2119
|
toolCallId: toolUseId,
|
|
2100
2120
|
sessionUpdate: "tool_call_update"
|
|
2101
2121
|
}
|
|
@@ -2113,7 +2133,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2113
2133
|
} catch {
|
|
2114
2134
|
}
|
|
2115
2135
|
return {
|
|
2116
|
-
_meta: toolMeta(chunk.name),
|
|
2136
|
+
_meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
|
|
2117
2137
|
toolCallId: chunk.id,
|
|
2118
2138
|
sessionUpdate: "tool_call",
|
|
2119
2139
|
rawInput,
|
|
@@ -2133,7 +2153,7 @@ function handleToolResultChunk(chunk, ctx) {
|
|
|
2133
2153
|
return null;
|
|
2134
2154
|
}
|
|
2135
2155
|
return {
|
|
2136
|
-
_meta: toolMeta(toolUse.name),
|
|
2156
|
+
_meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
|
|
2137
2157
|
toolCallId: chunk.tool_use_id,
|
|
2138
2158
|
sessionUpdate: "tool_call_update",
|
|
2139
2159
|
status: chunk.is_error ? "failed" : "completed",
|
|
@@ -2147,12 +2167,12 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2147
2167
|
switch (chunk.type) {
|
|
2148
2168
|
case "text":
|
|
2149
2169
|
case "text_delta":
|
|
2150
|
-
return handleTextChunk(chunk, role);
|
|
2170
|
+
return handleTextChunk(chunk, role, ctx.parentToolCallId);
|
|
2151
2171
|
case "image":
|
|
2152
2172
|
return handleImageChunk(chunk, role);
|
|
2153
2173
|
case "thinking":
|
|
2154
2174
|
case "thinking_delta":
|
|
2155
|
-
return handleThinkingChunk(chunk);
|
|
2175
|
+
return handleThinkingChunk(chunk, ctx.parentToolCallId);
|
|
2156
2176
|
case "tool_use":
|
|
2157
2177
|
case "server_tool_use":
|
|
2158
2178
|
case "mcp_tool_use":
|
|
@@ -2182,24 +2202,28 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2182
2202
|
return null;
|
|
2183
2203
|
}
|
|
2184
2204
|
}
|
|
2185
|
-
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2205
|
+
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2186
2206
|
if (typeof content === "string") {
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2207
|
+
const update = {
|
|
2208
|
+
sessionUpdate: messageUpdateType(role),
|
|
2209
|
+
content: text(content)
|
|
2210
|
+
};
|
|
2211
|
+
if (parentToolCallId) {
|
|
2212
|
+
update._meta = toolMeta(
|
|
2213
|
+
"__text__",
|
|
2214
|
+
void 0,
|
|
2215
|
+
parentToolCallId
|
|
2216
|
+
);
|
|
2217
|
+
}
|
|
2218
|
+
return [{ sessionId, update }];
|
|
2196
2219
|
}
|
|
2197
2220
|
const ctx = {
|
|
2198
2221
|
sessionId,
|
|
2199
2222
|
toolUseCache,
|
|
2200
2223
|
fileContentCache,
|
|
2201
2224
|
client,
|
|
2202
|
-
logger
|
|
2225
|
+
logger,
|
|
2226
|
+
parentToolCallId
|
|
2203
2227
|
};
|
|
2204
2228
|
const output = [];
|
|
2205
2229
|
for (const chunk of content) {
|
|
@@ -2210,7 +2234,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
|
|
|
2210
2234
|
}
|
|
2211
2235
|
return output;
|
|
2212
2236
|
}
|
|
2213
|
-
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2237
|
+
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2214
2238
|
const event = message.event;
|
|
2215
2239
|
switch (event.type) {
|
|
2216
2240
|
case "content_block_start":
|
|
@@ -2221,7 +2245,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2221
2245
|
toolUseCache,
|
|
2222
2246
|
fileContentCache,
|
|
2223
2247
|
client,
|
|
2224
|
-
logger
|
|
2248
|
+
logger,
|
|
2249
|
+
parentToolCallId
|
|
2225
2250
|
);
|
|
2226
2251
|
case "content_block_delta":
|
|
2227
2252
|
return toAcpNotifications(
|
|
@@ -2231,7 +2256,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2231
2256
|
toolUseCache,
|
|
2232
2257
|
fileContentCache,
|
|
2233
2258
|
client,
|
|
2234
|
-
logger
|
|
2259
|
+
logger,
|
|
2260
|
+
parentToolCallId
|
|
2235
2261
|
);
|
|
2236
2262
|
case "message_start":
|
|
2237
2263
|
case "message_delta":
|
|
@@ -2344,13 +2370,15 @@ function handleResultMessage(message, context) {
|
|
|
2344
2370
|
}
|
|
2345
2371
|
async function handleStreamEvent(message, context) {
|
|
2346
2372
|
const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
|
|
2373
|
+
const parentToolCallId = message.parent_tool_use_id ?? void 0;
|
|
2347
2374
|
for (const notification of streamEventToAcpNotifications(
|
|
2348
2375
|
message,
|
|
2349
2376
|
sessionId,
|
|
2350
2377
|
toolUseCache,
|
|
2351
2378
|
fileContentCache,
|
|
2352
2379
|
client,
|
|
2353
|
-
logger
|
|
2380
|
+
logger,
|
|
2381
|
+
parentToolCallId
|
|
2354
2382
|
)) {
|
|
2355
2383
|
await client.sessionUpdate(notification);
|
|
2356
2384
|
context.session.notificationHistory.push(notification);
|
|
@@ -2402,6 +2430,7 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2402
2430
|
}
|
|
2403
2431
|
const content = message.message.content;
|
|
2404
2432
|
const contentToProcess = filterMessageContent(content);
|
|
2433
|
+
const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
|
|
2405
2434
|
for (const notification of toAcpNotifications(
|
|
2406
2435
|
contentToProcess,
|
|
2407
2436
|
message.message.role,
|
|
@@ -2409,7 +2438,8 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2409
2438
|
toolUseCache,
|
|
2410
2439
|
fileContentCache,
|
|
2411
2440
|
client,
|
|
2412
|
-
logger
|
|
2441
|
+
logger,
|
|
2442
|
+
parentToolCallId
|
|
2413
2443
|
)) {
|
|
2414
2444
|
await client.sessionUpdate(notification);
|
|
2415
2445
|
session.notificationHistory.push(notification);
|