dsh-phone-bridge 0.2.5 → 0.2.6
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/index.js +27 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -957,22 +957,45 @@ export function apply(ctx, config = {}) {
|
|
|
957
957
|
}, signal);
|
|
958
958
|
|
|
959
959
|
const texts = [];
|
|
960
|
-
|
|
960
|
+
const allRecords = page?.records ?? [];
|
|
961
|
+
const typeTally = {};
|
|
962
|
+
let firstUserEvent = null;
|
|
963
|
+
for (const record of allRecords) {
|
|
961
964
|
const event = record?.event;
|
|
962
|
-
if (event
|
|
965
|
+
if (!event) continue;
|
|
966
|
+
const key = event.type ?? "(none)";
|
|
967
|
+
typeTally[key] = (typeTally[key] ?? 0) + 1;
|
|
968
|
+
if (event.type !== "user/message") continue;
|
|
969
|
+
if (!firstUserEvent) firstUserEvent = event;
|
|
963
970
|
if (event?.data?.source?.kind !== "user") continue;
|
|
964
971
|
const text = textFromContentBlocks(event.data.content);
|
|
965
972
|
if (!text) continue;
|
|
966
973
|
texts.push({ at: event.time ?? null, text });
|
|
967
974
|
}
|
|
968
975
|
|
|
969
|
-
|
|
976
|
+
const payload = {
|
|
970
977
|
ok: true,
|
|
971
978
|
sessionId,
|
|
972
979
|
total: texts.length,
|
|
973
980
|
// Newest last, so the caller can slice from the end.
|
|
974
981
|
messages: texts.slice(-limit),
|
|
975
|
-
}
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
// Opt-in shape report. The history event format is not a documented
|
|
985
|
+
// surface, so when a read comes back empty the only quick way to find out
|
|
986
|
+
// why is to look at what actually arrived. Loopback-only, and truncated.
|
|
987
|
+
if ((url.searchParams.get("debug") ?? "") === "1") {
|
|
988
|
+
payload.diagnostics = {
|
|
989
|
+
recordCount: allRecords.length,
|
|
990
|
+
hasMore: page?.hasMore ?? null,
|
|
991
|
+
recordKeys: allRecords[0] ? Object.keys(allRecords[0]) : [],
|
|
992
|
+
eventTypes: typeTally,
|
|
993
|
+
firstRecordSample: allRecords[0] ? JSON.stringify(allRecords[0]).slice(0, 700) : null,
|
|
994
|
+
firstUserEventSample: firstUserEvent ? JSON.stringify(firstUserEvent).slice(0, 1400) : null,
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
sendJson(res, 200, payload);
|
|
976
999
|
} catch (error) {
|
|
977
1000
|
sendJson(res, 500, { ok: false, error: String(error?.message ?? error) });
|
|
978
1001
|
}
|