@dev-anywhere/proxy 0.5.28 → 0.5.29
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/{chunk-J7YXXMSM.js → chunk-K6SGC7GL.js} +97 -5
- package/dist/chunk-K6SGC7GL.js.map +1 -0
- package/dist/{chunk-5TN3ZVT5.js → chunk-OA7PG4YZ.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/serve.js +176 -53
- package/dist/serve.js.map +1 -1
- package/dist/session-worker.js +1 -1
- package/dist/{terminal-VGCVESF6.js → terminal-I4L4DLDZ.js} +3 -3
- package/dist/terminal-worker.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-J7YXXMSM.js.map +0 -1
- /package/dist/{chunk-5TN3ZVT5.js.map → chunk-OA7PG4YZ.js.map} +0 -0
- /package/dist/{terminal-VGCVESF6.js.map → terminal-I4L4DLDZ.js.map} +0 -0
package/dist/serve.js
CHANGED
|
@@ -54,8 +54,9 @@ import {
|
|
|
54
54
|
providerValues,
|
|
55
55
|
serializeControl,
|
|
56
56
|
serializeIpc,
|
|
57
|
-
serializeWorkerMsg
|
|
58
|
-
|
|
57
|
+
serializeWorkerMsg,
|
|
58
|
+
summarizeToolActivity
|
|
59
|
+
} from "./chunk-K6SGC7GL.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
|
-
|
|
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,162 @@ 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
|
|
1138
|
-
if (
|
|
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 toolUseHistoryItem(toolId, rawToolName, input, timestamp) {
|
|
1177
|
+
if (!toolId || !rawToolName) return null;
|
|
1178
|
+
const toolName = normalizeHistoryToolName(rawToolName);
|
|
1179
|
+
const parameters = parseToolInput(input);
|
|
1180
|
+
return {
|
|
1181
|
+
kind: "message",
|
|
1182
|
+
message: {
|
|
1183
|
+
role: "activity",
|
|
1184
|
+
text: summarizeToolActivity(toolName, parameters),
|
|
1185
|
+
toolId,
|
|
1186
|
+
toolName,
|
|
1187
|
+
status: "running",
|
|
1188
|
+
...timestamp !== void 0 ? { timestamp } : {}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function extractClaudeContentItems(role, content, timestamp) {
|
|
1193
|
+
if (typeof content === "string") {
|
|
1194
|
+
const payload = extractConversationString(content);
|
|
1195
|
+
return payload ? [
|
|
1196
|
+
{
|
|
1197
|
+
kind: "message",
|
|
1198
|
+
message: {
|
|
1199
|
+
role: payload.role ?? role,
|
|
1200
|
+
text: payload.text,
|
|
1201
|
+
...timestamp !== void 0 ? { timestamp } : {}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
] : [];
|
|
1205
|
+
}
|
|
1206
|
+
if (!Array.isArray(content)) return [];
|
|
1207
|
+
const items = [];
|
|
1208
|
+
const pushTextMessage = (payload) => {
|
|
1209
|
+
const messageRole = payload.role ?? role;
|
|
1210
|
+
const previous = items.at(-1);
|
|
1211
|
+
if (previous?.kind === "message" && previous.message.role !== "activity" && previous.message.role === messageRole) {
|
|
1212
|
+
previous.message = {
|
|
1213
|
+
...previous.message,
|
|
1214
|
+
text: `${previous.message.text}
|
|
1215
|
+
${payload.text}`
|
|
1216
|
+
};
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
items.push({
|
|
1220
|
+
kind: "message",
|
|
1221
|
+
message: {
|
|
1222
|
+
role: messageRole,
|
|
1223
|
+
text: payload.text,
|
|
1224
|
+
...timestamp !== void 0 ? { timestamp } : {}
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
};
|
|
1228
|
+
for (const rawBlock of content) {
|
|
1229
|
+
const block = asRecord(rawBlock);
|
|
1230
|
+
if (!block || typeof block.type !== "string") continue;
|
|
1231
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
1232
|
+
const payload = extractConversationString(block.text);
|
|
1233
|
+
if (payload) pushTextMessage(payload);
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
if (role === "assistant" && block.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
|
|
1237
|
+
const item = toolUseHistoryItem(block.id, block.name, block.input, timestamp);
|
|
1238
|
+
if (item) items.push(item);
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
if (role === "user" && block.type === "tool_result" && typeof block.tool_use_id === "string") {
|
|
1242
|
+
items.push({
|
|
1243
|
+
kind: "tool-result",
|
|
1244
|
+
toolId: block.tool_use_id,
|
|
1245
|
+
isError: block.is_error === true
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
return items;
|
|
1250
|
+
}
|
|
1251
|
+
function extractConversationItemsFromJson(obj) {
|
|
1252
|
+
if (!obj || typeof obj !== "object") return [];
|
|
1139
1253
|
const record = obj;
|
|
1254
|
+
const timestamp = historyTimestamp(record.timestamp);
|
|
1140
1255
|
if (record.type === "event_msg") {
|
|
1141
1256
|
const payload = record.payload && typeof record.payload === "object" ? record.payload : null;
|
|
1142
|
-
if (!payload || typeof payload.message !== "string") return
|
|
1257
|
+
if (!payload || typeof payload.message !== "string") return [];
|
|
1143
1258
|
const role = payload.type === "user_message" ? "user" : payload.type === "agent_message" ? "assistant" : null;
|
|
1144
|
-
if (!role) return
|
|
1259
|
+
if (!role) return [];
|
|
1145
1260
|
const text = normalizeConversationText(payload.message);
|
|
1146
|
-
if (!text) return
|
|
1147
|
-
|
|
1148
|
-
|
|
1261
|
+
if (!text) return [];
|
|
1262
|
+
return [
|
|
1263
|
+
{
|
|
1264
|
+
kind: "message",
|
|
1265
|
+
message: { role, text, ...timestamp !== void 0 ? { timestamp } : {} }
|
|
1266
|
+
}
|
|
1267
|
+
];
|
|
1268
|
+
}
|
|
1269
|
+
if (record.type === "response_item") {
|
|
1270
|
+
const payload = asRecord(record.payload);
|
|
1271
|
+
if (!payload || typeof payload.type !== "string") return [];
|
|
1272
|
+
if (payload.type === "function_call" || payload.type === "custom_tool_call") {
|
|
1273
|
+
const toolId = typeof payload.call_id === "string" ? payload.call_id : typeof payload.id === "string" ? payload.id : "";
|
|
1274
|
+
const toolName = typeof payload.name === "string" ? payload.name : "";
|
|
1275
|
+
const input = payload.arguments ?? payload.input;
|
|
1276
|
+
const item = toolUseHistoryItem(toolId, toolName, input, timestamp);
|
|
1277
|
+
return item ? [item] : [];
|
|
1278
|
+
}
|
|
1279
|
+
if (payload.type === "function_call_output" || payload.type === "custom_tool_call_output") {
|
|
1280
|
+
const toolId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
1281
|
+
return toolId ? [{ kind: "tool-result", toolId, isError: payload.status === "failed" }] : [];
|
|
1282
|
+
}
|
|
1283
|
+
return [];
|
|
1149
1284
|
}
|
|
1150
1285
|
if (record.type === "user") {
|
|
1151
|
-
if (record.isMeta) return
|
|
1152
|
-
const
|
|
1153
|
-
|
|
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 };
|
|
1286
|
+
if (record.isMeta) return [];
|
|
1287
|
+
const message = asRecord(record.message);
|
|
1288
|
+
return extractClaudeContentItems("user", message?.content ?? record.message, timestamp);
|
|
1156
1289
|
}
|
|
1157
1290
|
if (record.type === "assistant") {
|
|
1158
|
-
const
|
|
1159
|
-
|
|
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 };
|
|
1291
|
+
const message = asRecord(record.message);
|
|
1292
|
+
return extractClaudeContentItems("assistant", message?.content ?? record.message, timestamp);
|
|
1162
1293
|
}
|
|
1163
|
-
return
|
|
1294
|
+
return [];
|
|
1164
1295
|
}
|
|
1165
1296
|
function splitLineSegments(block, blockStart) {
|
|
1166
1297
|
const segments = [];
|
|
@@ -1186,6 +1317,7 @@ async function readSessionMessagesPageFromFile(filePath, options = {}) {
|
|
|
1186
1317
|
let position = endOffset;
|
|
1187
1318
|
let carry = Buffer.alloc(0);
|
|
1188
1319
|
const collected = [];
|
|
1320
|
+
const toolResults = /* @__PURE__ */ new Map();
|
|
1189
1321
|
while (position > 0 && collected.length <= limit) {
|
|
1190
1322
|
const readSize = Math.min(HISTORY_READ_CHUNK_BYTES, position);
|
|
1191
1323
|
position -= readSize;
|
|
@@ -1202,9 +1334,24 @@ async function readSessionMessagesPageFromFile(filePath, options = {}) {
|
|
|
1202
1334
|
if (line.length === 0) continue;
|
|
1203
1335
|
try {
|
|
1204
1336
|
const parsed = JSON.parse(line.toString("utf-8"));
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1207
|
-
|
|
1337
|
+
const items = extractConversationItemsFromJson(parsed);
|
|
1338
|
+
for (let itemIndex = items.length - 1; itemIndex >= 0; itemIndex -= 1) {
|
|
1339
|
+
const item = items[itemIndex];
|
|
1340
|
+
if (!item) continue;
|
|
1341
|
+
if (item.kind === "tool-result") {
|
|
1342
|
+
toolResults.set(item.toolId, item.isError);
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1345
|
+
const message = item.message.role === "activity" ? {
|
|
1346
|
+
...item.message,
|
|
1347
|
+
status: toolResults.has(item.message.toolId) ? toolResults.get(item.message.toolId) ? "error" : "done" : "running"
|
|
1348
|
+
} : item.message;
|
|
1349
|
+
collected.push({
|
|
1350
|
+
...message,
|
|
1351
|
+
cursor: encodeHistoryCursor(segment.start, itemIndex)
|
|
1352
|
+
});
|
|
1353
|
+
if (collected.length > limit) break;
|
|
1354
|
+
}
|
|
1208
1355
|
if (collected.length > limit) break;
|
|
1209
1356
|
} catch {
|
|
1210
1357
|
}
|
|
@@ -1322,30 +1469,6 @@ function normalizeConversationText(text) {
|
|
|
1322
1469
|
if (!trimmed) return null;
|
|
1323
1470
|
return trimmed;
|
|
1324
1471
|
}
|
|
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
1472
|
async function extractTitleAndCwd(filePath) {
|
|
1350
1473
|
return new Promise((resolve3) => {
|
|
1351
1474
|
const input = createReadStream(filePath, { encoding: "utf-8" });
|
|
@@ -4852,7 +4975,7 @@ var PermissionBroker = class {
|
|
|
4852
4975
|
};
|
|
4853
4976
|
|
|
4854
4977
|
// src/serve/hook-payload-helpers.ts
|
|
4855
|
-
function
|
|
4978
|
+
function asRecord2(value) {
|
|
4856
4979
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4857
4980
|
}
|
|
4858
4981
|
function asProvider(value) {
|
|
@@ -4862,7 +4985,7 @@ function toolNameFromPayload(payload) {
|
|
|
4862
4985
|
return typeof payload.toolName === "string" ? payload.toolName : typeof payload.tool_name === "string" ? payload.tool_name : "unknown";
|
|
4863
4986
|
}
|
|
4864
4987
|
function toolInputFromPayload(payload) {
|
|
4865
|
-
return
|
|
4988
|
+
return asRecord2(payload.input ?? payload.tool_input);
|
|
4866
4989
|
}
|
|
4867
4990
|
|
|
4868
4991
|
// src/serve/hook-event-router.ts
|
|
@@ -5807,7 +5930,7 @@ var HookServer = class {
|
|
|
5807
5930
|
this.writeNeutralProviderResponse(res);
|
|
5808
5931
|
return;
|
|
5809
5932
|
}
|
|
5810
|
-
const payload =
|
|
5933
|
+
const payload = asRecord2(parsed.payload);
|
|
5811
5934
|
const requestId = typeof parsed.requestId === "string" ? parsed.requestId : typeof payload.tool_use_id === "string" ? payload.tool_use_id : void 0;
|
|
5812
5935
|
const event = {
|
|
5813
5936
|
sessionId: binding.sessionId,
|
|
@@ -5826,7 +5949,7 @@ var HookServer = class {
|
|
|
5826
5949
|
async handlePermissionRequest(event, res) {
|
|
5827
5950
|
const requestId = event.requestId ?? (typeof event.payload.tool_use_id === "string" ? event.payload.tool_use_id : void 0) ?? this.nextFallbackRequestId(event.sessionId);
|
|
5828
5951
|
const toolName = toolNameFromPayload(event.payload);
|
|
5829
|
-
const input =
|
|
5952
|
+
const input = asRecord2(event.payload.input ?? event.payload.tool_input);
|
|
5830
5953
|
this.options.onEvent?.({ ...event, requestId });
|
|
5831
5954
|
const decision = await this.options.permissionBroker.request({
|
|
5832
5955
|
requestId,
|