@posthog/agent 2.1.59 → 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 +57 -28
- package/dist/agent.js.map +1 -1
- package/dist/index.js +57 -28
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +57 -28
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +57 -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/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: {
|
|
@@ -2052,14 +2052,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
|
|
|
2052
2052
|
function messageUpdateType(role) {
|
|
2053
2053
|
return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
|
|
2054
2054
|
}
|
|
2055
|
-
function toolMeta(toolName, toolResponse) {
|
|
2056
|
-
|
|
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 };
|
|
2057
2060
|
}
|
|
2058
|
-
function handleTextChunk(chunk, role) {
|
|
2059
|
-
|
|
2061
|
+
function handleTextChunk(chunk, role, parentToolCallId) {
|
|
2062
|
+
const update = {
|
|
2060
2063
|
sessionUpdate: messageUpdateType(role),
|
|
2061
2064
|
content: text(chunk.text)
|
|
2062
2065
|
};
|
|
2066
|
+
if (parentToolCallId) {
|
|
2067
|
+
update._meta = toolMeta(
|
|
2068
|
+
"__text__",
|
|
2069
|
+
void 0,
|
|
2070
|
+
parentToolCallId
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2073
|
+
return update;
|
|
2063
2074
|
}
|
|
2064
2075
|
function handleImageChunk(chunk, role) {
|
|
2065
2076
|
return {
|
|
@@ -2071,11 +2082,19 @@ function handleImageChunk(chunk, role) {
|
|
|
2071
2082
|
)
|
|
2072
2083
|
};
|
|
2073
2084
|
}
|
|
2074
|
-
function handleThinkingChunk(chunk) {
|
|
2075
|
-
|
|
2085
|
+
function handleThinkingChunk(chunk, parentToolCallId) {
|
|
2086
|
+
const update = {
|
|
2076
2087
|
sessionUpdate: "agent_thought_chunk",
|
|
2077
2088
|
content: text(chunk.thinking)
|
|
2078
2089
|
};
|
|
2090
|
+
if (parentToolCallId) {
|
|
2091
|
+
update._meta = toolMeta(
|
|
2092
|
+
"__thinking__",
|
|
2093
|
+
void 0,
|
|
2094
|
+
parentToolCallId
|
|
2095
|
+
);
|
|
2096
|
+
}
|
|
2097
|
+
return update;
|
|
2079
2098
|
}
|
|
2080
2099
|
function handleToolUseChunk(chunk, ctx) {
|
|
2081
2100
|
ctx.toolUseCache[chunk.id] = chunk;
|
|
@@ -2096,7 +2115,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2096
2115
|
await ctx.client.sessionUpdate({
|
|
2097
2116
|
sessionId: ctx.sessionId,
|
|
2098
2117
|
update: {
|
|
2099
|
-
_meta: toolMeta(toolUse.name, toolResponse),
|
|
2118
|
+
_meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
|
|
2100
2119
|
toolCallId: toolUseId,
|
|
2101
2120
|
sessionUpdate: "tool_call_update"
|
|
2102
2121
|
}
|
|
@@ -2114,7 +2133,7 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
2114
2133
|
} catch {
|
|
2115
2134
|
}
|
|
2116
2135
|
return {
|
|
2117
|
-
_meta: toolMeta(chunk.name),
|
|
2136
|
+
_meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
|
|
2118
2137
|
toolCallId: chunk.id,
|
|
2119
2138
|
sessionUpdate: "tool_call",
|
|
2120
2139
|
rawInput,
|
|
@@ -2134,7 +2153,7 @@ function handleToolResultChunk(chunk, ctx) {
|
|
|
2134
2153
|
return null;
|
|
2135
2154
|
}
|
|
2136
2155
|
return {
|
|
2137
|
-
_meta: toolMeta(toolUse.name),
|
|
2156
|
+
_meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
|
|
2138
2157
|
toolCallId: chunk.tool_use_id,
|
|
2139
2158
|
sessionUpdate: "tool_call_update",
|
|
2140
2159
|
status: chunk.is_error ? "failed" : "completed",
|
|
@@ -2148,12 +2167,12 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2148
2167
|
switch (chunk.type) {
|
|
2149
2168
|
case "text":
|
|
2150
2169
|
case "text_delta":
|
|
2151
|
-
return handleTextChunk(chunk, role);
|
|
2170
|
+
return handleTextChunk(chunk, role, ctx.parentToolCallId);
|
|
2152
2171
|
case "image":
|
|
2153
2172
|
return handleImageChunk(chunk, role);
|
|
2154
2173
|
case "thinking":
|
|
2155
2174
|
case "thinking_delta":
|
|
2156
|
-
return handleThinkingChunk(chunk);
|
|
2175
|
+
return handleThinkingChunk(chunk, ctx.parentToolCallId);
|
|
2157
2176
|
case "tool_use":
|
|
2158
2177
|
case "server_tool_use":
|
|
2159
2178
|
case "mcp_tool_use":
|
|
@@ -2183,24 +2202,28 @@ function processContentChunk(chunk, role, ctx) {
|
|
|
2183
2202
|
return null;
|
|
2184
2203
|
}
|
|
2185
2204
|
}
|
|
2186
|
-
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2205
|
+
function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2187
2206
|
if (typeof content === "string") {
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
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 }];
|
|
2197
2219
|
}
|
|
2198
2220
|
const ctx = {
|
|
2199
2221
|
sessionId,
|
|
2200
2222
|
toolUseCache,
|
|
2201
2223
|
fileContentCache,
|
|
2202
2224
|
client,
|
|
2203
|
-
logger
|
|
2225
|
+
logger,
|
|
2226
|
+
parentToolCallId
|
|
2204
2227
|
};
|
|
2205
2228
|
const output = [];
|
|
2206
2229
|
for (const chunk of content) {
|
|
@@ -2211,7 +2234,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
|
|
|
2211
2234
|
}
|
|
2212
2235
|
return output;
|
|
2213
2236
|
}
|
|
2214
|
-
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
|
|
2237
|
+
function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
|
|
2215
2238
|
const event = message.event;
|
|
2216
2239
|
switch (event.type) {
|
|
2217
2240
|
case "content_block_start":
|
|
@@ -2222,7 +2245,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2222
2245
|
toolUseCache,
|
|
2223
2246
|
fileContentCache,
|
|
2224
2247
|
client,
|
|
2225
|
-
logger
|
|
2248
|
+
logger,
|
|
2249
|
+
parentToolCallId
|
|
2226
2250
|
);
|
|
2227
2251
|
case "content_block_delta":
|
|
2228
2252
|
return toAcpNotifications(
|
|
@@ -2232,7 +2256,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
|
|
|
2232
2256
|
toolUseCache,
|
|
2233
2257
|
fileContentCache,
|
|
2234
2258
|
client,
|
|
2235
|
-
logger
|
|
2259
|
+
logger,
|
|
2260
|
+
parentToolCallId
|
|
2236
2261
|
);
|
|
2237
2262
|
case "message_start":
|
|
2238
2263
|
case "message_delta":
|
|
@@ -2345,13 +2370,15 @@ function handleResultMessage(message, context) {
|
|
|
2345
2370
|
}
|
|
2346
2371
|
async function handleStreamEvent(message, context) {
|
|
2347
2372
|
const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
|
|
2373
|
+
const parentToolCallId = message.parent_tool_use_id ?? void 0;
|
|
2348
2374
|
for (const notification of streamEventToAcpNotifications(
|
|
2349
2375
|
message,
|
|
2350
2376
|
sessionId,
|
|
2351
2377
|
toolUseCache,
|
|
2352
2378
|
fileContentCache,
|
|
2353
2379
|
client,
|
|
2354
|
-
logger
|
|
2380
|
+
logger,
|
|
2381
|
+
parentToolCallId
|
|
2355
2382
|
)) {
|
|
2356
2383
|
await client.sessionUpdate(notification);
|
|
2357
2384
|
context.session.notificationHistory.push(notification);
|
|
@@ -2403,6 +2430,7 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2403
2430
|
}
|
|
2404
2431
|
const content = message.message.content;
|
|
2405
2432
|
const contentToProcess = filterMessageContent(content);
|
|
2433
|
+
const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
|
|
2406
2434
|
for (const notification of toAcpNotifications(
|
|
2407
2435
|
contentToProcess,
|
|
2408
2436
|
message.message.role,
|
|
@@ -2410,7 +2438,8 @@ async function handleUserAssistantMessage(message, context) {
|
|
|
2410
2438
|
toolUseCache,
|
|
2411
2439
|
fileContentCache,
|
|
2412
2440
|
client,
|
|
2413
|
-
logger
|
|
2441
|
+
logger,
|
|
2442
|
+
parentToolCallId
|
|
2414
2443
|
)) {
|
|
2415
2444
|
await client.sessionUpdate(notification);
|
|
2416
2445
|
session.notificationHistory.push(notification);
|