@dev-anywhere/proxy 0.5.28 → 0.5.30

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/serve.js CHANGED
@@ -54,8 +54,9 @@ import {
54
54
  providerValues,
55
55
  serializeControl,
56
56
  serializeIpc,
57
- serializeWorkerMsg
58
- } from "./chunk-J7YXXMSM.js";
57
+ serializeWorkerMsg,
58
+ summarizeToolActivity
59
+ } from "./chunk-HRGSR2CX.js";
59
60
  import {
60
61
  buildProviderEnv,
61
62
  loadConfig,
@@ -1084,13 +1085,14 @@ function normalizeHistoryPageLimit(limit) {
1084
1085
  if (typeof limit !== "number" || !Number.isFinite(limit)) return DEFAULT_HISTORY_PAGE_LIMIT;
1085
1086
  return Math.max(1, Math.min(MAX_HISTORY_PAGE_LIMIT, Math.floor(limit)));
1086
1087
  }
1087
- function encodeHistoryCursor(offset) {
1088
- return `${HISTORY_CURSOR_PREFIX}${Math.max(0, Math.floor(offset))}`;
1088
+ function encodeHistoryCursor(offset, itemIndex = 0) {
1089
+ const base = `${HISTORY_CURSOR_PREFIX}${Math.max(0, Math.floor(offset))}`;
1090
+ return itemIndex > 0 ? `${base}:${itemIndex}` : base;
1089
1091
  }
1090
1092
  function decodeHistoryCursor(cursor, fileSize) {
1091
1093
  if (!cursor) return fileSize;
1092
1094
  const raw = cursor.startsWith(HISTORY_CURSOR_PREFIX) ? cursor.slice(HISTORY_CURSOR_PREFIX.length) : cursor;
1093
- const parsed = Number(raw);
1095
+ const parsed = Number(raw.match(/^\d+/u)?.[0]);
1094
1096
  if (!Number.isInteger(parsed) || parsed < 0) return fileSize;
1095
1097
  return Math.min(parsed, fileSize);
1096
1098
  }
@@ -1134,33 +1136,179 @@ async function findSessionFile(sessionId, provider) {
1134
1136
  if (provider === "codex") return findCodexSessionFile(sessionId);
1135
1137
  return await findClaudeSessionFile(sessionId) ?? await findCodexSessionFile(sessionId);
1136
1138
  }
1137
- function extractConversationMessageFromJson(obj) {
1138
- if (!obj || typeof obj !== "object") return null;
1139
+ function historyTimestamp(value) {
1140
+ if (typeof value !== "string") return void 0;
1141
+ const timestamp = new Date(value).getTime();
1142
+ return Number.isFinite(timestamp) ? timestamp : void 0;
1143
+ }
1144
+ function asRecord(value) {
1145
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
1146
+ }
1147
+ function parseToolInput(value) {
1148
+ const direct = asRecord(value);
1149
+ if (direct) return direct;
1150
+ if (typeof value !== "string") return {};
1151
+ try {
1152
+ return asRecord(JSON.parse(value)) ?? {};
1153
+ } catch {
1154
+ return {};
1155
+ }
1156
+ }
1157
+ function normalizeHistoryToolName(name) {
1158
+ switch (name) {
1159
+ case "exec":
1160
+ case "exec_command":
1161
+ case "shell":
1162
+ case "shell_command":
1163
+ return "Bash";
1164
+ case "apply_patch":
1165
+ return "Patch";
1166
+ case "read_file":
1167
+ return "Read";
1168
+ case "write_file":
1169
+ return "Write";
1170
+ case "search_query":
1171
+ return "WebSearch";
1172
+ default:
1173
+ return name;
1174
+ }
1175
+ }
1176
+ function normalizeHistoryToolParameters(rawToolName, input) {
1177
+ const parameters = parseToolInput(input);
1178
+ const toolName = normalizeHistoryToolName(rawToolName);
1179
+ if (toolName === "Bash" && typeof parameters.command !== "string") {
1180
+ const command = typeof parameters.cmd === "string" ? parameters.cmd : void 0;
1181
+ if (command) {
1182
+ const rest = { ...parameters };
1183
+ delete rest.cmd;
1184
+ return { ...rest, command };
1185
+ }
1186
+ }
1187
+ if (toolName === "Patch" && typeof input === "string" && !parameters.content) {
1188
+ return { ...parameters, content: input };
1189
+ }
1190
+ return parameters;
1191
+ }
1192
+ function toolUseHistoryItem(toolId, rawToolName, input, timestamp) {
1193
+ if (!toolId || !rawToolName) return null;
1194
+ const toolName = normalizeHistoryToolName(rawToolName);
1195
+ const parameters = normalizeHistoryToolParameters(rawToolName, input);
1196
+ return {
1197
+ kind: "message",
1198
+ message: {
1199
+ role: "activity",
1200
+ text: summarizeToolActivity(toolName, parameters),
1201
+ toolId,
1202
+ toolName,
1203
+ parameters,
1204
+ status: "running",
1205
+ ...timestamp !== void 0 ? { timestamp } : {}
1206
+ }
1207
+ };
1208
+ }
1209
+ function extractClaudeContentItems(role, content, timestamp) {
1210
+ if (typeof content === "string") {
1211
+ const payload = extractConversationString(content);
1212
+ return payload ? [
1213
+ {
1214
+ kind: "message",
1215
+ message: {
1216
+ role: payload.role ?? role,
1217
+ text: payload.text,
1218
+ ...timestamp !== void 0 ? { timestamp } : {}
1219
+ }
1220
+ }
1221
+ ] : [];
1222
+ }
1223
+ if (!Array.isArray(content)) return [];
1224
+ const items = [];
1225
+ const pushTextMessage = (payload) => {
1226
+ const messageRole = payload.role ?? role;
1227
+ const previous = items.at(-1);
1228
+ if (previous?.kind === "message" && previous.message.role !== "activity" && previous.message.role === messageRole) {
1229
+ previous.message = {
1230
+ ...previous.message,
1231
+ text: `${previous.message.text}
1232
+ ${payload.text}`
1233
+ };
1234
+ return;
1235
+ }
1236
+ items.push({
1237
+ kind: "message",
1238
+ message: {
1239
+ role: messageRole,
1240
+ text: payload.text,
1241
+ ...timestamp !== void 0 ? { timestamp } : {}
1242
+ }
1243
+ });
1244
+ };
1245
+ for (const rawBlock of content) {
1246
+ const block = asRecord(rawBlock);
1247
+ if (!block || typeof block.type !== "string") continue;
1248
+ if (block.type === "text" && typeof block.text === "string") {
1249
+ const payload = extractConversationString(block.text);
1250
+ if (payload) pushTextMessage(payload);
1251
+ continue;
1252
+ }
1253
+ if (role === "assistant" && block.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
1254
+ const item = toolUseHistoryItem(block.id, block.name, block.input, timestamp);
1255
+ if (item) items.push(item);
1256
+ continue;
1257
+ }
1258
+ if (role === "user" && block.type === "tool_result" && typeof block.tool_use_id === "string") {
1259
+ items.push({
1260
+ kind: "tool-result",
1261
+ toolId: block.tool_use_id,
1262
+ isError: block.is_error === true
1263
+ });
1264
+ }
1265
+ }
1266
+ return items;
1267
+ }
1268
+ function extractConversationItemsFromJson(obj) {
1269
+ if (!obj || typeof obj !== "object") return [];
1139
1270
  const record = obj;
1271
+ const timestamp = historyTimestamp(record.timestamp);
1140
1272
  if (record.type === "event_msg") {
1141
1273
  const payload = record.payload && typeof record.payload === "object" ? record.payload : null;
1142
- if (!payload || typeof payload.message !== "string") return null;
1274
+ if (!payload || typeof payload.message !== "string") return [];
1143
1275
  const role = payload.type === "user_message" ? "user" : payload.type === "agent_message" ? "assistant" : null;
1144
- if (!role) return null;
1276
+ if (!role) return [];
1145
1277
  const text = normalizeConversationText(payload.message);
1146
- if (!text) return null;
1147
- const ts = typeof record.timestamp === "string" ? new Date(record.timestamp).getTime() : void 0;
1148
- return { role, text, timestamp: ts };
1278
+ if (!text) return [];
1279
+ return [
1280
+ {
1281
+ kind: "message",
1282
+ message: { role, text, ...timestamp !== void 0 ? { timestamp } : {} }
1283
+ }
1284
+ ];
1285
+ }
1286
+ if (record.type === "response_item") {
1287
+ const payload = asRecord(record.payload);
1288
+ if (!payload || typeof payload.type !== "string") return [];
1289
+ if (payload.type === "function_call" || payload.type === "custom_tool_call") {
1290
+ const toolId = typeof payload.call_id === "string" ? payload.call_id : typeof payload.id === "string" ? payload.id : "";
1291
+ const toolName = typeof payload.name === "string" ? payload.name : "";
1292
+ const input = payload.arguments ?? payload.input;
1293
+ const item = toolUseHistoryItem(toolId, toolName, input, timestamp);
1294
+ return item ? [item] : [];
1295
+ }
1296
+ if (payload.type === "function_call_output" || payload.type === "custom_tool_call_output") {
1297
+ const toolId = typeof payload.call_id === "string" ? payload.call_id : "";
1298
+ return toolId ? [{ kind: "tool-result", toolId, isError: payload.status === "failed" }] : [];
1299
+ }
1300
+ return [];
1149
1301
  }
1150
1302
  if (record.type === "user") {
1151
- if (record.isMeta) return null;
1152
- const payload = extractConversationPayload(record.message);
1153
- if (!payload) return null;
1154
- const ts = typeof record.timestamp === "string" ? new Date(record.timestamp).getTime() : void 0;
1155
- return { role: payload.role ?? "user", text: payload.text, timestamp: ts };
1303
+ if (record.isMeta) return [];
1304
+ const message = asRecord(record.message);
1305
+ return extractClaudeContentItems("user", message?.content ?? record.message, timestamp);
1156
1306
  }
1157
1307
  if (record.type === "assistant") {
1158
- const payload = extractConversationPayload(record.message);
1159
- if (!payload) return null;
1160
- const ts = typeof record.timestamp === "string" ? new Date(record.timestamp).getTime() : void 0;
1161
- return { role: payload.role ?? "assistant", text: payload.text, timestamp: ts };
1308
+ const message = asRecord(record.message);
1309
+ return extractClaudeContentItems("assistant", message?.content ?? record.message, timestamp);
1162
1310
  }
1163
- return null;
1311
+ return [];
1164
1312
  }
1165
1313
  function splitLineSegments(block, blockStart) {
1166
1314
  const segments = [];
@@ -1186,6 +1334,7 @@ async function readSessionMessagesPageFromFile(filePath, options = {}) {
1186
1334
  let position = endOffset;
1187
1335
  let carry = Buffer.alloc(0);
1188
1336
  const collected = [];
1337
+ const toolResults = /* @__PURE__ */ new Map();
1189
1338
  while (position > 0 && collected.length <= limit) {
1190
1339
  const readSize = Math.min(HISTORY_READ_CHUNK_BYTES, position);
1191
1340
  position -= readSize;
@@ -1202,9 +1351,24 @@ async function readSessionMessagesPageFromFile(filePath, options = {}) {
1202
1351
  if (line.length === 0) continue;
1203
1352
  try {
1204
1353
  const parsed = JSON.parse(line.toString("utf-8"));
1205
- const message = extractConversationMessageFromJson(parsed);
1206
- if (!message) continue;
1207
- collected.push({ ...message, cursor: encodeHistoryCursor(segment.start) });
1354
+ const items = extractConversationItemsFromJson(parsed);
1355
+ for (let itemIndex = items.length - 1; itemIndex >= 0; itemIndex -= 1) {
1356
+ const item = items[itemIndex];
1357
+ if (!item) continue;
1358
+ if (item.kind === "tool-result") {
1359
+ toolResults.set(item.toolId, item.isError);
1360
+ continue;
1361
+ }
1362
+ const message = item.message.role === "activity" ? {
1363
+ ...item.message,
1364
+ status: toolResults.has(item.message.toolId) ? toolResults.get(item.message.toolId) ? "error" : "done" : "running"
1365
+ } : item.message;
1366
+ collected.push({
1367
+ ...message,
1368
+ cursor: encodeHistoryCursor(segment.start, itemIndex)
1369
+ });
1370
+ if (collected.length > limit) break;
1371
+ }
1208
1372
  if (collected.length > limit) break;
1209
1373
  } catch {
1210
1374
  }
@@ -1322,30 +1486,6 @@ function normalizeConversationText(text) {
1322
1486
  if (!trimmed) return null;
1323
1487
  return trimmed;
1324
1488
  }
1325
- function extractConversationPayload(msg) {
1326
- if (typeof msg === "string") {
1327
- return extractConversationString(msg);
1328
- }
1329
- if (msg && typeof msg === "object" && "content" in msg) {
1330
- const content = msg.content;
1331
- if (typeof content === "string") {
1332
- return extractConversationString(content);
1333
- }
1334
- if (Array.isArray(content)) {
1335
- const texts = content.filter(
1336
- (b) => b.type === "text" && typeof b.text === "string"
1337
- ).map((b) => b.text);
1338
- return extractConversationString(texts.join("\n"));
1339
- }
1340
- }
1341
- if (Array.isArray(msg)) {
1342
- const texts = msg.filter(
1343
- (b) => b.type === "text" && typeof b.text === "string"
1344
- ).map((b) => b.text);
1345
- return extractConversationString(texts.join("\n"));
1346
- }
1347
- return null;
1348
- }
1349
1489
  async function extractTitleAndCwd(filePath) {
1350
1490
  return new Promise((resolve3) => {
1351
1491
  const input = createReadStream(filePath, { encoding: "utf-8" });
@@ -4852,7 +4992,7 @@ var PermissionBroker = class {
4852
4992
  };
4853
4993
 
4854
4994
  // src/serve/hook-payload-helpers.ts
4855
- function asRecord(value) {
4995
+ function asRecord2(value) {
4856
4996
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4857
4997
  }
4858
4998
  function asProvider(value) {
@@ -4862,7 +5002,7 @@ function toolNameFromPayload(payload) {
4862
5002
  return typeof payload.toolName === "string" ? payload.toolName : typeof payload.tool_name === "string" ? payload.tool_name : "unknown";
4863
5003
  }
4864
5004
  function toolInputFromPayload(payload) {
4865
- return asRecord(payload.input ?? payload.tool_input);
5005
+ return asRecord2(payload.input ?? payload.tool_input);
4866
5006
  }
4867
5007
 
4868
5008
  // src/serve/hook-event-router.ts
@@ -5807,7 +5947,7 @@ var HookServer = class {
5807
5947
  this.writeNeutralProviderResponse(res);
5808
5948
  return;
5809
5949
  }
5810
- const payload = asRecord(parsed.payload);
5950
+ const payload = asRecord2(parsed.payload);
5811
5951
  const requestId = typeof parsed.requestId === "string" ? parsed.requestId : typeof payload.tool_use_id === "string" ? payload.tool_use_id : void 0;
5812
5952
  const event = {
5813
5953
  sessionId: binding.sessionId,
@@ -5826,7 +5966,7 @@ var HookServer = class {
5826
5966
  async handlePermissionRequest(event, res) {
5827
5967
  const requestId = event.requestId ?? (typeof event.payload.tool_use_id === "string" ? event.payload.tool_use_id : void 0) ?? this.nextFallbackRequestId(event.sessionId);
5828
5968
  const toolName = toolNameFromPayload(event.payload);
5829
- const input = asRecord(event.payload.input ?? event.payload.tool_input);
5969
+ const input = asRecord2(event.payload.input ?? event.payload.tool_input);
5830
5970
  this.options.onEvent?.({ ...event, requestId });
5831
5971
  const decision = await this.options.permissionBroker.request({
5832
5972
  requestId,