forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanual-source.ts
More file actions
33 lines (31 loc) · 1.07 KB
/
Copy pathmanual-source.ts
File metadata and controls
33 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { TranscriptSourceProvider } from "./provider-types.js";
function parseSpeakerLine(line: string): { speakerLabel?: string; text: string } {
const match = /^([^:\n]{1,80}):\s+(.+)$/.exec(line.trim());
if (!match) {
return { text: line.trim() };
}
return { speakerLabel: match[1]?.trim(), text: match[2]?.trim() ?? "" };
}
export const manualTranscriptSourceProvider: TranscriptSourceProvider = {
id: "manual-transcript",
aliases: ["import", "transcript"],
name: "Manual Transcript Import",
sourceKinds: ["posthoc-transcript"],
async importTranscript(request) {
const now = new Date().toISOString();
return request.text
.split(/\r?\n/)
.map((line) => parseSpeakerLine(line))
.filter((entry) => entry.text)
.map((entry, index) => ({
id: `${request.session.sessionId}-${index + 1}`,
sessionId: request.session.sessionId,
startedAt: now,
final: true,
speaker: {
label: entry.speakerLabel ?? request.speakerLabel ?? "Speaker",
},
text: entry.text,
}));
},
};