@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.
@@ -1183,7 +1183,7 @@ import { v7 as uuidv7 } from "uuid";
1183
1183
  // package.json
1184
1184
  var package_default = {
1185
1185
  name: "@posthog/agent",
1186
- version: "2.1.53",
1186
+ version: "2.1.60",
1187
1187
  repository: "https://github.com/PostHog/twig",
1188
1188
  description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
1189
1189
  exports: {
@@ -1248,7 +1248,8 @@ var package_default = {
1248
1248
  test: "vitest run",
1249
1249
  "test:watch": "vitest",
1250
1250
  typecheck: "pnpm exec tsc --noEmit",
1251
- prepublishOnly: "pnpm run build"
1251
+ prepublishOnly: "pnpm run build",
1252
+ clean: "rm -rf dist .turbo"
1252
1253
  },
1253
1254
  engines: {
1254
1255
  node: ">=20.0.0"
@@ -2059,14 +2060,25 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
2059
2060
  function messageUpdateType(role) {
2060
2061
  return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
2061
2062
  }
2062
- function toolMeta(toolName, toolResponse) {
2063
- return toolResponse ? { claudeCode: { toolName, toolResponse } } : { claudeCode: { toolName } };
2063
+ function toolMeta(toolName, toolResponse, parentToolCallId) {
2064
+ const meta = { toolName };
2065
+ if (toolResponse !== void 0) meta.toolResponse = toolResponse;
2066
+ if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
2067
+ return { claudeCode: meta };
2064
2068
  }
2065
- function handleTextChunk(chunk, role) {
2066
- return {
2069
+ function handleTextChunk(chunk, role, parentToolCallId) {
2070
+ const update = {
2067
2071
  sessionUpdate: messageUpdateType(role),
2068
2072
  content: text(chunk.text)
2069
2073
  };
2074
+ if (parentToolCallId) {
2075
+ update._meta = toolMeta(
2076
+ "__text__",
2077
+ void 0,
2078
+ parentToolCallId
2079
+ );
2080
+ }
2081
+ return update;
2070
2082
  }
2071
2083
  function handleImageChunk(chunk, role) {
2072
2084
  return {
@@ -2078,11 +2090,19 @@ function handleImageChunk(chunk, role) {
2078
2090
  )
2079
2091
  };
2080
2092
  }
2081
- function handleThinkingChunk(chunk) {
2082
- return {
2093
+ function handleThinkingChunk(chunk, parentToolCallId) {
2094
+ const update = {
2083
2095
  sessionUpdate: "agent_thought_chunk",
2084
2096
  content: text(chunk.thinking)
2085
2097
  };
2098
+ if (parentToolCallId) {
2099
+ update._meta = toolMeta(
2100
+ "__thinking__",
2101
+ void 0,
2102
+ parentToolCallId
2103
+ );
2104
+ }
2105
+ return update;
2086
2106
  }
2087
2107
  function handleToolUseChunk(chunk, ctx) {
2088
2108
  ctx.toolUseCache[chunk.id] = chunk;
@@ -2103,7 +2123,7 @@ function handleToolUseChunk(chunk, ctx) {
2103
2123
  await ctx.client.sessionUpdate({
2104
2124
  sessionId: ctx.sessionId,
2105
2125
  update: {
2106
- _meta: toolMeta(toolUse.name, toolResponse),
2126
+ _meta: toolMeta(toolUse.name, toolResponse, ctx.parentToolCallId),
2107
2127
  toolCallId: toolUseId,
2108
2128
  sessionUpdate: "tool_call_update"
2109
2129
  }
@@ -2121,7 +2141,7 @@ function handleToolUseChunk(chunk, ctx) {
2121
2141
  } catch {
2122
2142
  }
2123
2143
  return {
2124
- _meta: toolMeta(chunk.name),
2144
+ _meta: toolMeta(chunk.name, void 0, ctx.parentToolCallId),
2125
2145
  toolCallId: chunk.id,
2126
2146
  sessionUpdate: "tool_call",
2127
2147
  rawInput,
@@ -2141,7 +2161,7 @@ function handleToolResultChunk(chunk, ctx) {
2141
2161
  return null;
2142
2162
  }
2143
2163
  return {
2144
- _meta: toolMeta(toolUse.name),
2164
+ _meta: toolMeta(toolUse.name, void 0, ctx.parentToolCallId),
2145
2165
  toolCallId: chunk.tool_use_id,
2146
2166
  sessionUpdate: "tool_call_update",
2147
2167
  status: chunk.is_error ? "failed" : "completed",
@@ -2155,12 +2175,12 @@ function processContentChunk(chunk, role, ctx) {
2155
2175
  switch (chunk.type) {
2156
2176
  case "text":
2157
2177
  case "text_delta":
2158
- return handleTextChunk(chunk, role);
2178
+ return handleTextChunk(chunk, role, ctx.parentToolCallId);
2159
2179
  case "image":
2160
2180
  return handleImageChunk(chunk, role);
2161
2181
  case "thinking":
2162
2182
  case "thinking_delta":
2163
- return handleThinkingChunk(chunk);
2183
+ return handleThinkingChunk(chunk, ctx.parentToolCallId);
2164
2184
  case "tool_use":
2165
2185
  case "server_tool_use":
2166
2186
  case "mcp_tool_use":
@@ -2190,24 +2210,28 @@ function processContentChunk(chunk, role, ctx) {
2190
2210
  return null;
2191
2211
  }
2192
2212
  }
2193
- function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger) {
2213
+ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
2194
2214
  if (typeof content === "string") {
2195
- return [
2196
- {
2197
- sessionId,
2198
- update: {
2199
- sessionUpdate: messageUpdateType(role),
2200
- content: text(content)
2201
- }
2202
- }
2203
- ];
2215
+ const update = {
2216
+ sessionUpdate: messageUpdateType(role),
2217
+ content: text(content)
2218
+ };
2219
+ if (parentToolCallId) {
2220
+ update._meta = toolMeta(
2221
+ "__text__",
2222
+ void 0,
2223
+ parentToolCallId
2224
+ );
2225
+ }
2226
+ return [{ sessionId, update }];
2204
2227
  }
2205
2228
  const ctx = {
2206
2229
  sessionId,
2207
2230
  toolUseCache,
2208
2231
  fileContentCache,
2209
2232
  client,
2210
- logger
2233
+ logger,
2234
+ parentToolCallId
2211
2235
  };
2212
2236
  const output = [];
2213
2237
  for (const chunk of content) {
@@ -2218,7 +2242,7 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, fileContentC
2218
2242
  }
2219
2243
  return output;
2220
2244
  }
2221
- function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger) {
2245
+ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileContentCache, client, logger, parentToolCallId) {
2222
2246
  const event = message.event;
2223
2247
  switch (event.type) {
2224
2248
  case "content_block_start":
@@ -2229,7 +2253,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
2229
2253
  toolUseCache,
2230
2254
  fileContentCache,
2231
2255
  client,
2232
- logger
2256
+ logger,
2257
+ parentToolCallId
2233
2258
  );
2234
2259
  case "content_block_delta":
2235
2260
  return toAcpNotifications(
@@ -2239,7 +2264,8 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, fileCon
2239
2264
  toolUseCache,
2240
2265
  fileContentCache,
2241
2266
  client,
2242
- logger
2267
+ logger,
2268
+ parentToolCallId
2243
2269
  );
2244
2270
  case "message_start":
2245
2271
  case "message_delta":
@@ -2352,13 +2378,15 @@ function handleResultMessage(message, context) {
2352
2378
  }
2353
2379
  async function handleStreamEvent(message, context) {
2354
2380
  const { sessionId, client, toolUseCache, fileContentCache, logger } = context;
2381
+ const parentToolCallId = message.parent_tool_use_id ?? void 0;
2355
2382
  for (const notification of streamEventToAcpNotifications(
2356
2383
  message,
2357
2384
  sessionId,
2358
2385
  toolUseCache,
2359
2386
  fileContentCache,
2360
2387
  client,
2361
- logger
2388
+ logger,
2389
+ parentToolCallId
2362
2390
  )) {
2363
2391
  await client.sessionUpdate(notification);
2364
2392
  context.session.notificationHistory.push(notification);
@@ -2410,6 +2438,7 @@ async function handleUserAssistantMessage(message, context) {
2410
2438
  }
2411
2439
  const content = message.message.content;
2412
2440
  const contentToProcess = filterMessageContent(content);
2441
+ const parentToolCallId = "parent_tool_use_id" in message ? message.parent_tool_use_id ?? void 0 : void 0;
2413
2442
  for (const notification of toAcpNotifications(
2414
2443
  contentToProcess,
2415
2444
  message.message.role,
@@ -2417,7 +2446,8 @@ async function handleUserAssistantMessage(message, context) {
2417
2446
  toolUseCache,
2418
2447
  fileContentCache,
2419
2448
  client,
2420
- logger
2449
+ logger,
2450
+ parentToolCallId
2421
2451
  )) {
2422
2452
  await client.sessionUpdate(notification);
2423
2453
  session.notificationHistory.push(notification);