MCPcopy Create free account
hub / github.com/fastrepl/anarlog / getRenderTranscriptRequestKey

Function getRenderTranscriptRequestKey

apps/desktop/src/stt/render-transcript.ts:60–145  ·  view source on GitHub ↗
(
  request: RenderTranscriptRequest | null | undefined,
)

Source from the content-addressed store, hash-verified

58}
59
60export function getRenderTranscriptRequestKey(
61 request: RenderTranscriptRequest | null | undefined,
62): string {
63 if (!request) {
64 return "empty";
65 }
66
67 let hash = 2_166_136_261;
68 let wordCount = 0;
69 let assignmentCount = 0;
70
71 const writeString = (value: string) => {
72 for (let index = 0; index < value.length; index += 1) {
73 hash = Math.imul(hash ^ value.charCodeAt(index), 16_777_619) >>> 0;
74 }
75 hash = Math.imul(hash ^ 31, 16_777_619) >>> 0;
76 };
77
78 const writeValue = (value: unknown) => {
79 if (value == null) {
80 writeString("");
81 return;
82 }
83
84 if (typeof value === "object") {
85 try {
86 writeString(JSON.stringify(value));
87 } catch {
88 writeString("[object]");
89 }
90 return;
91 }
92
93 writeString(String(value));
94 };
95
96 writeValue(request.self_human_id);
97
98 for (const humanId of request.participant_human_ids) {
99 writeValue(humanId);
100 }
101
102 for (const human of request.humans) {
103 writeValue(human.human_id);
104 writeValue(human.name);
105 }
106
107 for (const transcript of request.transcripts) {
108 writeValue(transcript.started_at);
109 wordCount += transcript.words.length;
110 assignmentCount += transcript.assignments.length;
111
112 for (const word of transcript.words) {
113 writeValue(word.id);
114 writeValue(word.text);
115 writeValue(word.start_ms);
116 writeValue(word.end_ms);
117 writeValue(word.channel);

Callers 3

Calls 1

writeValueFunction · 0.85

Tested by

no test coverage detected