granola-toolkit 0.6.0 → 0.7.0
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/cli.js +36 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -906,7 +906,40 @@ function parseCacheContents(contents) {
|
|
|
906
906
|
}
|
|
907
907
|
//#endregion
|
|
908
908
|
//#region src/transcripts.ts
|
|
909
|
-
function
|
|
909
|
+
function transcriptSegmentKey(segment) {
|
|
910
|
+
if (segment.id) return `id:${segment.id}`;
|
|
911
|
+
return [
|
|
912
|
+
segment.documentId,
|
|
913
|
+
segment.source,
|
|
914
|
+
segment.startTimestamp,
|
|
915
|
+
segment.endTimestamp
|
|
916
|
+
].join("|");
|
|
917
|
+
}
|
|
918
|
+
function compareSegmentTimestamps(left, right) {
|
|
919
|
+
if (left === right) return 0;
|
|
920
|
+
const leftTime = Date.parse(left);
|
|
921
|
+
const rightTime = Date.parse(right);
|
|
922
|
+
if (!Number.isNaN(leftTime) && !Number.isNaN(rightTime)) return leftTime - rightTime;
|
|
923
|
+
return compareStrings(left, right);
|
|
924
|
+
}
|
|
925
|
+
function compareTranscriptSegments(left, right) {
|
|
926
|
+
return compareSegmentTimestamps(left.startTimestamp, right.startTimestamp) || compareSegmentTimestamps(left.endTimestamp, right.endTimestamp) || compareStrings(left.source, right.source) || compareStrings(left.id, right.id) || compareStrings(left.text, right.text);
|
|
927
|
+
}
|
|
928
|
+
function preferredTranscriptSegment(current, candidate) {
|
|
929
|
+
if (!current) return candidate;
|
|
930
|
+
if (candidate.isFinal !== current.isFinal) return candidate.isFinal ? candidate : current;
|
|
931
|
+
return compareSegmentTimestamps(candidate.endTimestamp, current.endTimestamp) > 0 || candidate.text.length > current.text.length ? candidate : current;
|
|
932
|
+
}
|
|
933
|
+
function normaliseTranscriptSegments(segments) {
|
|
934
|
+
const selected = /* @__PURE__ */ new Map();
|
|
935
|
+
for (const segment of [...segments].sort(compareTranscriptSegments)) {
|
|
936
|
+
const key = transcriptSegmentKey(segment);
|
|
937
|
+
const current = selected.get(key);
|
|
938
|
+
selected.set(key, preferredTranscriptSegment(current, segment));
|
|
939
|
+
}
|
|
940
|
+
return [...selected.values()].sort(compareTranscriptSegments);
|
|
941
|
+
}
|
|
942
|
+
function buildTranscriptExport(document, segments, rawSegments = segments) {
|
|
910
943
|
const renderedSegments = segments.map((segment) => ({
|
|
911
944
|
endTimestamp: segment.endTimestamp,
|
|
912
945
|
id: segment.id,
|
|
@@ -921,7 +954,7 @@ function buildTranscriptExport(document, segments) {
|
|
|
921
954
|
id: document.id,
|
|
922
955
|
raw: {
|
|
923
956
|
document,
|
|
924
|
-
segments
|
|
957
|
+
segments: rawSegments
|
|
925
958
|
},
|
|
926
959
|
segments: renderedSegments,
|
|
927
960
|
title: document.title,
|
|
@@ -990,7 +1023,7 @@ async function writeTranscripts(cacheData, outputDir, format = "text") {
|
|
|
990
1023
|
title: documentId,
|
|
991
1024
|
updatedAt: ""
|
|
992
1025
|
};
|
|
993
|
-
const content = renderTranscriptExport(buildTranscriptExport(document, segments), format);
|
|
1026
|
+
const content = renderTranscriptExport(buildTranscriptExport(document, normaliseTranscriptSegments(segments), segments), format);
|
|
994
1027
|
if (!content) return [];
|
|
995
1028
|
return [{
|
|
996
1029
|
content,
|