@hasna/microservices 0.0.7 → 0.0.9
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/microservices/microservice-social/package.json +2 -1
- package/microservices/microservice-social/src/cli/index.ts +906 -12
- package/microservices/microservice-social/src/db/migrations.ts +72 -0
- package/microservices/microservice-social/src/db/social.ts +33 -3
- package/microservices/microservice-social/src/lib/audience.ts +353 -0
- package/microservices/microservice-social/src/lib/content-ai.ts +278 -0
- package/microservices/microservice-social/src/lib/media.ts +311 -0
- package/microservices/microservice-social/src/lib/mentions.ts +434 -0
- package/microservices/microservice-social/src/lib/metrics-sync.ts +264 -0
- package/microservices/microservice-social/src/lib/publisher.ts +377 -0
- package/microservices/microservice-social/src/lib/scheduler.ts +229 -0
- package/microservices/microservice-social/src/lib/sentiment.ts +256 -0
- package/microservices/microservice-social/src/lib/threads.ts +291 -0
- package/microservices/microservice-social/src/mcp/index.ts +776 -6
- package/microservices/microservice-social/src/server/index.ts +441 -0
- package/microservices/microservice-transcriber/src/cli/index.ts +247 -1
- package/microservices/microservice-transcriber/src/db/comments.ts +166 -0
- package/microservices/microservice-transcriber/src/db/migrations.ts +46 -0
- package/microservices/microservice-transcriber/src/db/proofread.ts +119 -0
- package/microservices/microservice-transcriber/src/lib/downloader.ts +68 -0
- package/microservices/microservice-transcriber/src/lib/proofread.ts +296 -0
- package/microservices/microservice-transcriber/src/mcp/index.ts +263 -3
- package/package.json +1 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI-powered non-destructive spellcheck/proofread for transcripts.
|
|
3
|
+
* Uses OpenAI or Anthropic to find spelling, grammar, punctuation, and clarity issues.
|
|
4
|
+
* NEVER modifies transcript_text directly — issues are stored in proofread_issues table
|
|
5
|
+
* and must be explicitly applied one by one.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getTranscript, updateTranscript } from "../db/transcripts.js";
|
|
9
|
+
import {
|
|
10
|
+
createProofreadIssue,
|
|
11
|
+
listProofreadIssues,
|
|
12
|
+
getProofreadIssue,
|
|
13
|
+
updateIssueStatus,
|
|
14
|
+
getProofreadStats as getDbProofreadStats,
|
|
15
|
+
type ProofreadIssue,
|
|
16
|
+
type IssueType,
|
|
17
|
+
type IssueStatus,
|
|
18
|
+
type ListProofreadIssuesOptions,
|
|
19
|
+
type ProofreadStats,
|
|
20
|
+
} from "../db/proofread.js";
|
|
21
|
+
import { getDefaultSummaryProvider, type SummaryProvider } from "./summarizer.js";
|
|
22
|
+
|
|
23
|
+
export type { ProofreadIssue, ProofreadStats, IssueType, IssueStatus };
|
|
24
|
+
|
|
25
|
+
export interface ProofreadOptions {
|
|
26
|
+
types?: IssueType[];
|
|
27
|
+
confidence_threshold?: number;
|
|
28
|
+
provider?: SummaryProvider;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface RawProofreadIssue {
|
|
32
|
+
issue_type: string;
|
|
33
|
+
position_start: number;
|
|
34
|
+
position_end: number;
|
|
35
|
+
original_text: string;
|
|
36
|
+
suggestion: string;
|
|
37
|
+
confidence: number;
|
|
38
|
+
explanation: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const PROOFREAD_PROMPT = (text: string, types?: IssueType[]) => {
|
|
42
|
+
const typeFilter = types && types.length > 0
|
|
43
|
+
? `Only check for these issue types: ${types.join(", ")}.`
|
|
44
|
+
: "Check for all issue types: spelling, grammar, punctuation, clarity.";
|
|
45
|
+
|
|
46
|
+
return `You are a professional proofreader. Analyze the following transcript text and find all issues.
|
|
47
|
+
|
|
48
|
+
${typeFilter}
|
|
49
|
+
|
|
50
|
+
For each issue found, return a JSON object with:
|
|
51
|
+
- "issue_type": one of "spelling", "grammar", "punctuation", "clarity"
|
|
52
|
+
- "position_start": character index where the issue starts in the original text
|
|
53
|
+
- "position_end": character index where the issue ends in the original text
|
|
54
|
+
- "original_text": the exact text that has the issue
|
|
55
|
+
- "suggestion": the corrected text
|
|
56
|
+
- "confidence": a number 0-1 indicating how confident you are this is an issue
|
|
57
|
+
- "explanation": brief explanation of the issue
|
|
58
|
+
|
|
59
|
+
Return ONLY a valid JSON array of issue objects. If no issues found, return [].
|
|
60
|
+
Do not wrap in markdown code fences.
|
|
61
|
+
|
|
62
|
+
Transcript text:
|
|
63
|
+
${text.slice(0, 15000)}`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async function callOpenAI(prompt: string, maxTokens: number): Promise<string> {
|
|
67
|
+
const apiKey = process.env["OPENAI_API_KEY"];
|
|
68
|
+
if (!apiKey) throw new Error("OPENAI_API_KEY is not set");
|
|
69
|
+
|
|
70
|
+
const res = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
73
|
+
body: JSON.stringify({
|
|
74
|
+
model: "gpt-4o-mini",
|
|
75
|
+
messages: [{ role: "user", content: prompt }],
|
|
76
|
+
max_tokens: maxTokens,
|
|
77
|
+
temperature: 0.2,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (!res.ok) { const body = await res.text(); throw new Error(`OpenAI API error ${res.status}: ${body}`); }
|
|
82
|
+
const data = (await res.json()) as { choices: Array<{ message: { content: string } }> };
|
|
83
|
+
return data.choices[0]?.message?.content?.trim() ?? "";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function callAnthropic(prompt: string, maxTokens: number): Promise<string> {
|
|
87
|
+
const apiKey = process.env["ANTHROPIC_API_KEY"];
|
|
88
|
+
if (!apiKey) throw new Error("ANTHROPIC_API_KEY is not set");
|
|
89
|
+
|
|
90
|
+
const res = await fetch("https://api.anthropic.com/v1/messages", {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: { "x-api-key": apiKey, "anthropic-version": "2023-06-01", "Content-Type": "application/json" },
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
model: "claude-haiku-4-5-20251001",
|
|
95
|
+
max_tokens: maxTokens,
|
|
96
|
+
messages: [{ role: "user", content: prompt }],
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!res.ok) { const body = await res.text(); throw new Error(`Anthropic API error ${res.status}: ${body}`); }
|
|
101
|
+
const data = (await res.json()) as { content: Array<{ type: string; text: string }> };
|
|
102
|
+
return data.content.find((b) => b.type === "text")?.text?.trim() ?? "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseAIResponse(raw: string): RawProofreadIssue[] {
|
|
106
|
+
const cleaned = raw.replace(/```json\n?/g, "").replace(/```\n?/g, "").trim();
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(cleaned);
|
|
109
|
+
if (!Array.isArray(parsed)) return [];
|
|
110
|
+
return parsed.filter(
|
|
111
|
+
(item: unknown) =>
|
|
112
|
+
typeof item === "object" &&
|
|
113
|
+
item !== null &&
|
|
114
|
+
"issue_type" in item &&
|
|
115
|
+
"original_text" in item
|
|
116
|
+
);
|
|
117
|
+
} catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const VALID_ISSUE_TYPES: Set<string> = new Set(["spelling", "grammar", "punctuation", "clarity"]);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Run AI proofreading on a transcript. Stores issues in DB. Never changes transcript_text.
|
|
126
|
+
*/
|
|
127
|
+
export async function proofreadTranscript(
|
|
128
|
+
transcriptId: string,
|
|
129
|
+
options: ProofreadOptions = {}
|
|
130
|
+
): Promise<ProofreadIssue[]> {
|
|
131
|
+
const transcript = getTranscript(transcriptId);
|
|
132
|
+
if (!transcript) throw new Error(`Transcript '${transcriptId}' not found.`);
|
|
133
|
+
if (!transcript.transcript_text) throw new Error(`Transcript '${transcriptId}' has no text.`);
|
|
134
|
+
|
|
135
|
+
const provider = options.provider ?? getDefaultSummaryProvider();
|
|
136
|
+
if (!provider) throw new Error("No AI provider configured. Set OPENAI_API_KEY or ANTHROPIC_API_KEY.");
|
|
137
|
+
|
|
138
|
+
const prompt = PROOFREAD_PROMPT(transcript.transcript_text, options.types);
|
|
139
|
+
const confidenceThreshold = options.confidence_threshold ?? 0.7;
|
|
140
|
+
|
|
141
|
+
let raw: string;
|
|
142
|
+
if (provider === "openai") {
|
|
143
|
+
raw = await callOpenAI(prompt, 3000);
|
|
144
|
+
} else {
|
|
145
|
+
raw = await callAnthropic(prompt, 3000);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const rawIssues = parseAIResponse(raw);
|
|
149
|
+
const created: ProofreadIssue[] = [];
|
|
150
|
+
|
|
151
|
+
for (const issue of rawIssues) {
|
|
152
|
+
// Validate issue_type
|
|
153
|
+
if (!VALID_ISSUE_TYPES.has(issue.issue_type)) continue;
|
|
154
|
+
|
|
155
|
+
// Filter by confidence threshold
|
|
156
|
+
const confidence = typeof issue.confidence === "number" ? issue.confidence : 0.8;
|
|
157
|
+
if (confidence < confidenceThreshold) continue;
|
|
158
|
+
|
|
159
|
+
// Filter by types if specified
|
|
160
|
+
if (options.types && options.types.length > 0 && !options.types.includes(issue.issue_type as IssueType)) continue;
|
|
161
|
+
|
|
162
|
+
const created_issue = createProofreadIssue({
|
|
163
|
+
transcript_id: transcriptId,
|
|
164
|
+
issue_type: issue.issue_type as IssueType,
|
|
165
|
+
position_start: typeof issue.position_start === "number" ? issue.position_start : undefined,
|
|
166
|
+
position_end: typeof issue.position_end === "number" ? issue.position_end : undefined,
|
|
167
|
+
original_text: String(issue.original_text),
|
|
168
|
+
suggestion: issue.suggestion ? String(issue.suggestion) : undefined,
|
|
169
|
+
confidence,
|
|
170
|
+
explanation: issue.explanation ? String(issue.explanation) : undefined,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
created.push(created_issue);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return created;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* List proofread issues for a transcript with optional filters.
|
|
181
|
+
*/
|
|
182
|
+
export function listIssues(
|
|
183
|
+
transcriptId: string,
|
|
184
|
+
filters?: ListProofreadIssuesOptions
|
|
185
|
+
): ProofreadIssue[] {
|
|
186
|
+
return listProofreadIssues(transcriptId, filters);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Apply a suggestion: replaces the original_text in transcript_text at the
|
|
191
|
+
* specified position with the suggestion, and marks the issue as 'applied'.
|
|
192
|
+
*/
|
|
193
|
+
export function applySuggestion(issueId: string): ProofreadIssue | null {
|
|
194
|
+
const issue = getProofreadIssue(issueId);
|
|
195
|
+
if (!issue) return null;
|
|
196
|
+
if (issue.status !== "pending") return issue; // already handled
|
|
197
|
+
|
|
198
|
+
if (!issue.suggestion) {
|
|
199
|
+
// No suggestion to apply, just dismiss
|
|
200
|
+
return updateIssueStatus(issueId, "dismissed");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const transcript = getTranscript(issue.transcript_id);
|
|
204
|
+
if (!transcript || !transcript.transcript_text) return null;
|
|
205
|
+
|
|
206
|
+
let newText: string;
|
|
207
|
+
|
|
208
|
+
if (issue.position_start !== null && issue.position_end !== null) {
|
|
209
|
+
// Apply at exact position if the text at that position matches
|
|
210
|
+
const textAtPosition = transcript.transcript_text.slice(issue.position_start, issue.position_end);
|
|
211
|
+
if (textAtPosition === issue.original_text) {
|
|
212
|
+
newText =
|
|
213
|
+
transcript.transcript_text.slice(0, issue.position_start) +
|
|
214
|
+
issue.suggestion +
|
|
215
|
+
transcript.transcript_text.slice(issue.position_end);
|
|
216
|
+
} else {
|
|
217
|
+
// Position mismatch (text may have shifted from prior edits), fall back to first occurrence
|
|
218
|
+
newText = transcript.transcript_text.replace(issue.original_text, issue.suggestion);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
// No position info, replace first occurrence
|
|
222
|
+
newText = transcript.transcript_text.replace(issue.original_text, issue.suggestion);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Only update if text actually changed
|
|
226
|
+
if (newText !== transcript.transcript_text) {
|
|
227
|
+
updateTranscript(issue.transcript_id, { transcript_text: newText });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return updateIssueStatus(issueId, "applied");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Dismiss an issue without changing the transcript text.
|
|
235
|
+
*/
|
|
236
|
+
export function dismissIssue(issueId: string): ProofreadIssue | null {
|
|
237
|
+
const issue = getProofreadIssue(issueId);
|
|
238
|
+
if (!issue) return null;
|
|
239
|
+
return updateIssueStatus(issueId, "dismissed");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Get proofread statistics for a transcript.
|
|
244
|
+
*/
|
|
245
|
+
export { getDbProofreadStats as getProofreadStats };
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Export annotated transcript text with inline markers showing issues.
|
|
249
|
+
* Format: [TYPE: "original" -> "suggestion"]
|
|
250
|
+
*/
|
|
251
|
+
export function exportAnnotated(transcriptId: string): string {
|
|
252
|
+
const transcript = getTranscript(transcriptId);
|
|
253
|
+
if (!transcript || !transcript.transcript_text) {
|
|
254
|
+
throw new Error(`Transcript '${transcriptId}' not found or has no text.`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const issues = listProofreadIssues(transcriptId, { status: "pending" });
|
|
258
|
+
if (issues.length === 0) return transcript.transcript_text;
|
|
259
|
+
|
|
260
|
+
// Sort issues by position_start descending so we can safely replace from end to start
|
|
261
|
+
// without shifting positions. Issues without positions are handled via string replacement.
|
|
262
|
+
const positionalIssues = issues
|
|
263
|
+
.filter((i) => i.position_start !== null && i.position_end !== null)
|
|
264
|
+
.sort((a, b) => (b.position_start ?? 0) - (a.position_start ?? 0));
|
|
265
|
+
|
|
266
|
+
const nonPositionalIssues = issues.filter((i) => i.position_start === null || i.position_end === null);
|
|
267
|
+
|
|
268
|
+
let text = transcript.transcript_text;
|
|
269
|
+
|
|
270
|
+
// Apply positional annotations from end to start
|
|
271
|
+
for (const issue of positionalIssues) {
|
|
272
|
+
const start = issue.position_start!;
|
|
273
|
+
const end = issue.position_end!;
|
|
274
|
+
const marker = formatMarker(issue);
|
|
275
|
+
text = text.slice(0, start) + marker + text.slice(end);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Apply non-positional annotations via first occurrence replacement
|
|
279
|
+
for (const issue of nonPositionalIssues) {
|
|
280
|
+
const marker = formatMarker(issue);
|
|
281
|
+
const idx = text.indexOf(issue.original_text);
|
|
282
|
+
if (idx !== -1) {
|
|
283
|
+
text = text.slice(0, idx) + marker + text.slice(idx + issue.original_text.length);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return text;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function formatMarker(issue: ProofreadIssue): string {
|
|
291
|
+
const type = issue.issue_type.toUpperCase();
|
|
292
|
+
if (issue.suggestion) {
|
|
293
|
+
return `[${type}: "${issue.original_text}" -> "${issue.suggestion}"]`;
|
|
294
|
+
}
|
|
295
|
+
return `[${type}: "${issue.original_text}"]`;
|
|
296
|
+
}
|
|
@@ -23,7 +23,8 @@ import {
|
|
|
23
23
|
type TranscriptStatus,
|
|
24
24
|
type TranscriptSourceType,
|
|
25
25
|
} from "../db/transcripts.js";
|
|
26
|
-
import { prepareAudio, detectSourceType, getVideoInfo, downloadAudio, downloadVideo, createClip, isPlaylistUrl, getPlaylistUrls, type TrimOptions } from "../lib/downloader.js";
|
|
26
|
+
import { prepareAudio, detectSourceType, getVideoInfo, downloadAudio, downloadVideo, createClip, isPlaylistUrl, getPlaylistUrls, fetchComments, type TrimOptions } from "../lib/downloader.js";
|
|
27
|
+
import { listComments, getTopComments, searchComments, getCommentStats, importComments } from "../db/comments.js";
|
|
27
28
|
import { getConfig, setConfig, resetConfig } from "../lib/config.js";
|
|
28
29
|
import { summarizeText, extractHighlights, generateMeetingNotes, getDefaultSummaryProvider } from "../lib/summarizer.js";
|
|
29
30
|
import { translateText } from "../lib/translator.js";
|
|
@@ -31,6 +32,7 @@ import { fetchFeedEpisodes } from "../lib/feeds.js";
|
|
|
31
32
|
import { createAnnotation, listAnnotations, deleteAnnotation } from "../db/annotations.js";
|
|
32
33
|
import { wordDiff, diffStats, formatDiff } from "../lib/diff.js";
|
|
33
34
|
import { transcribeFile, checkProviders, toSrt, toVtt, toAss, toMarkdown, segmentByChapters, formatWithConfidence } from "../lib/providers.js";
|
|
35
|
+
import { proofreadTranscript, listIssues, applySuggestion, dismissIssue, getProofreadStats, exportAnnotated, type IssueType } from "../lib/proofread.js";
|
|
34
36
|
|
|
35
37
|
const server = new McpServer({
|
|
36
38
|
name: "microservice-transcriber",
|
|
@@ -63,9 +65,10 @@ server.registerTool(
|
|
|
63
65
|
diarize: z.boolean().optional().describe("Identify different speakers — ElevenLabs only"),
|
|
64
66
|
vocab: z.array(z.string()).optional().describe("Custom vocabulary hints for accuracy (e.g. ['Karpathy', 'MicroGPT'])"),
|
|
65
67
|
force: z.boolean().optional().describe("Re-transcribe even if URL already exists in DB"),
|
|
68
|
+
comments: z.boolean().optional().describe("Also fetch and store YouTube/Vimeo comments"),
|
|
66
69
|
},
|
|
67
70
|
},
|
|
68
|
-
async ({ source, provider = "elevenlabs", language, title, start, end, diarize, vocab, force }) => {
|
|
71
|
+
async ({ source, provider = "elevenlabs", language, title, start, end, diarize, vocab, force, comments: fetchCommentsFlag }) => {
|
|
69
72
|
// Duplicate detection
|
|
70
73
|
if (!force) {
|
|
71
74
|
const existing = findBySourceUrl(source);
|
|
@@ -129,8 +132,33 @@ server.registerTool(
|
|
|
129
132
|
},
|
|
130
133
|
});
|
|
131
134
|
|
|
135
|
+
// Fetch comments if requested
|
|
136
|
+
let commentCount = 0;
|
|
137
|
+
if (fetchCommentsFlag && (sourceType === "youtube" || sourceType === "vimeo")) {
|
|
138
|
+
try {
|
|
139
|
+
const rawComments = await fetchComments(source);
|
|
140
|
+
if (rawComments.length > 0) {
|
|
141
|
+
const mapped = rawComments.map((c) => ({
|
|
142
|
+
platform: sourceType,
|
|
143
|
+
author: c.author,
|
|
144
|
+
author_handle: c.author_id,
|
|
145
|
+
comment_text: c.text,
|
|
146
|
+
likes: c.like_count,
|
|
147
|
+
reply_count: 0,
|
|
148
|
+
is_reply: c.parent !== null,
|
|
149
|
+
parent_comment_id: c.parent,
|
|
150
|
+
published_at: c.timestamp ? new Date(c.timestamp * 1000).toISOString() : null,
|
|
151
|
+
}));
|
|
152
|
+
commentCount = importComments(record.id, mapped);
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
// Comment fetch is best-effort — don't fail the transcription
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const finalResult = { ...getTranscript(record.id), comments_imported: commentCount };
|
|
132
160
|
return {
|
|
133
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
161
|
+
content: [{ type: "text", text: JSON.stringify(finalResult, null, 2) }],
|
|
134
162
|
};
|
|
135
163
|
} catch (error) {
|
|
136
164
|
const msg = error instanceof Error ? error.message : String(error);
|
|
@@ -943,6 +971,86 @@ server.registerTool(
|
|
|
943
971
|
}
|
|
944
972
|
);
|
|
945
973
|
|
|
974
|
+
// ---------------------------------------------------------------------------
|
|
975
|
+
// list_comments
|
|
976
|
+
// ---------------------------------------------------------------------------
|
|
977
|
+
|
|
978
|
+
server.registerTool(
|
|
979
|
+
"list_comments",
|
|
980
|
+
{
|
|
981
|
+
title: "List Comments",
|
|
982
|
+
description: "List comments for a transcript, optionally sorted by likes.",
|
|
983
|
+
inputSchema: {
|
|
984
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
985
|
+
top: z.boolean().optional().describe("Sort by most liked"),
|
|
986
|
+
limit: z.number().optional().describe("Max results (default 50)"),
|
|
987
|
+
offset: z.number().optional().describe("Offset for pagination"),
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
async ({ transcript_id, top, limit, offset }) => {
|
|
991
|
+
const comments = listComments(transcript_id, { top, limit, offset });
|
|
992
|
+
return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] };
|
|
993
|
+
}
|
|
994
|
+
);
|
|
995
|
+
|
|
996
|
+
// ---------------------------------------------------------------------------
|
|
997
|
+
// top_comments
|
|
998
|
+
// ---------------------------------------------------------------------------
|
|
999
|
+
|
|
1000
|
+
server.registerTool(
|
|
1001
|
+
"top_comments",
|
|
1002
|
+
{
|
|
1003
|
+
title: "Top Comments",
|
|
1004
|
+
description: "Get the most liked comments for a transcript.",
|
|
1005
|
+
inputSchema: {
|
|
1006
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
1007
|
+
limit: z.number().optional().describe("Number of top comments (default 10)"),
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
async ({ transcript_id, limit }) => {
|
|
1011
|
+
const comments = getTopComments(transcript_id, limit);
|
|
1012
|
+
return { content: [{ type: "text", text: JSON.stringify(comments, null, 2) }] };
|
|
1013
|
+
}
|
|
1014
|
+
);
|
|
1015
|
+
|
|
1016
|
+
// ---------------------------------------------------------------------------
|
|
1017
|
+
// search_comments
|
|
1018
|
+
// ---------------------------------------------------------------------------
|
|
1019
|
+
|
|
1020
|
+
server.registerTool(
|
|
1021
|
+
"search_comments",
|
|
1022
|
+
{
|
|
1023
|
+
title: "Search Comments",
|
|
1024
|
+
description: "Search comment text across all transcripts using LIKE matching.",
|
|
1025
|
+
inputSchema: {
|
|
1026
|
+
query: z.string().describe("Search query"),
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
async ({ query }) => {
|
|
1030
|
+
const results = searchComments(query);
|
|
1031
|
+
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
|
|
1032
|
+
}
|
|
1033
|
+
);
|
|
1034
|
+
|
|
1035
|
+
// ---------------------------------------------------------------------------
|
|
1036
|
+
// comment_stats
|
|
1037
|
+
// ---------------------------------------------------------------------------
|
|
1038
|
+
|
|
1039
|
+
server.registerTool(
|
|
1040
|
+
"comment_stats",
|
|
1041
|
+
{
|
|
1042
|
+
title: "Comment Stats",
|
|
1043
|
+
description: "Get comment statistics for a transcript: total, replies, unique authors, avg likes, top commenter.",
|
|
1044
|
+
inputSchema: {
|
|
1045
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
1046
|
+
},
|
|
1047
|
+
},
|
|
1048
|
+
async ({ transcript_id }) => {
|
|
1049
|
+
const stats = getCommentStats(transcript_id);
|
|
1050
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
|
|
946
1054
|
// ---------------------------------------------------------------------------
|
|
947
1055
|
// get_config / set_config
|
|
948
1056
|
// ---------------------------------------------------------------------------
|
|
@@ -991,6 +1099,142 @@ server.registerTool(
|
|
|
991
1099
|
}
|
|
992
1100
|
);
|
|
993
1101
|
|
|
1102
|
+
// ---------------------------------------------------------------------------
|
|
1103
|
+
// proofread_transcript
|
|
1104
|
+
// ---------------------------------------------------------------------------
|
|
1105
|
+
|
|
1106
|
+
server.registerTool(
|
|
1107
|
+
"proofread_transcript",
|
|
1108
|
+
{
|
|
1109
|
+
title: "Proofread Transcript",
|
|
1110
|
+
description: "Run AI-powered spellcheck/proofread on a transcript. Finds spelling, grammar, punctuation, and clarity issues. Non-destructive: stores issues in DB without modifying transcript text.",
|
|
1111
|
+
inputSchema: {
|
|
1112
|
+
id: z.string().describe("Transcript ID"),
|
|
1113
|
+
types: z.array(z.enum(["spelling", "grammar", "punctuation", "clarity"])).optional().describe("Issue types to check (default: all)"),
|
|
1114
|
+
confidence_threshold: z.number().optional().describe("Minimum confidence 0-1 (default: 0.7)"),
|
|
1115
|
+
provider: z.enum(["openai", "anthropic"]).optional().describe("AI provider (auto-detected from env)"),
|
|
1116
|
+
},
|
|
1117
|
+
},
|
|
1118
|
+
async ({ id, types, confidence_threshold, provider }) => {
|
|
1119
|
+
try {
|
|
1120
|
+
const issues = await proofreadTranscript(id, {
|
|
1121
|
+
types: types as IssueType[] | undefined,
|
|
1122
|
+
confidence_threshold,
|
|
1123
|
+
provider: provider as "openai" | "anthropic" | undefined,
|
|
1124
|
+
});
|
|
1125
|
+
return { content: [{ type: "text", text: JSON.stringify(issues, null, 2) }] };
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
return { content: [{ type: "text", text: `Proofread failed: ${error instanceof Error ? error.message : error}` }], isError: true };
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1132
|
+
// ---------------------------------------------------------------------------
|
|
1133
|
+
// list_proofread_issues
|
|
1134
|
+
// ---------------------------------------------------------------------------
|
|
1135
|
+
|
|
1136
|
+
server.registerTool(
|
|
1137
|
+
"list_proofread_issues",
|
|
1138
|
+
{
|
|
1139
|
+
title: "List Proofread Issues",
|
|
1140
|
+
description: "List proofread issues for a transcript with optional filters.",
|
|
1141
|
+
inputSchema: {
|
|
1142
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
1143
|
+
issue_type: z.enum(["spelling", "grammar", "punctuation", "clarity"]).optional().describe("Filter by issue type"),
|
|
1144
|
+
status: z.enum(["pending", "applied", "dismissed"]).optional().describe("Filter by status"),
|
|
1145
|
+
},
|
|
1146
|
+
},
|
|
1147
|
+
async ({ transcript_id, issue_type, status }) => {
|
|
1148
|
+
const issues = listIssues(transcript_id, {
|
|
1149
|
+
issue_type: issue_type as IssueType | undefined,
|
|
1150
|
+
status: status as "pending" | "applied" | "dismissed" | undefined,
|
|
1151
|
+
});
|
|
1152
|
+
return { content: [{ type: "text", text: JSON.stringify(issues, null, 2) }] };
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
1155
|
+
|
|
1156
|
+
// ---------------------------------------------------------------------------
|
|
1157
|
+
// apply_suggestion
|
|
1158
|
+
// ---------------------------------------------------------------------------
|
|
1159
|
+
|
|
1160
|
+
server.registerTool(
|
|
1161
|
+
"apply_suggestion",
|
|
1162
|
+
{
|
|
1163
|
+
title: "Apply Proofread Suggestion",
|
|
1164
|
+
description: "Apply a proofread suggestion to the transcript text. Replaces the original text with the suggestion and marks the issue as applied.",
|
|
1165
|
+
inputSchema: {
|
|
1166
|
+
issue_id: z.string().describe("Proofread issue ID"),
|
|
1167
|
+
},
|
|
1168
|
+
},
|
|
1169
|
+
async ({ issue_id }) => {
|
|
1170
|
+
const result = applySuggestion(issue_id);
|
|
1171
|
+
if (!result) return { content: [{ type: "text", text: `Issue '${issue_id}' not found.` }], isError: true };
|
|
1172
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1173
|
+
}
|
|
1174
|
+
);
|
|
1175
|
+
|
|
1176
|
+
// ---------------------------------------------------------------------------
|
|
1177
|
+
// dismiss_issue
|
|
1178
|
+
// ---------------------------------------------------------------------------
|
|
1179
|
+
|
|
1180
|
+
server.registerTool(
|
|
1181
|
+
"dismiss_issue",
|
|
1182
|
+
{
|
|
1183
|
+
title: "Dismiss Proofread Issue",
|
|
1184
|
+
description: "Dismiss a proofread issue without modifying the transcript text.",
|
|
1185
|
+
inputSchema: {
|
|
1186
|
+
issue_id: z.string().describe("Proofread issue ID"),
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
async ({ issue_id }) => {
|
|
1190
|
+
const result = dismissIssue(issue_id);
|
|
1191
|
+
if (!result) return { content: [{ type: "text", text: `Issue '${issue_id}' not found.` }], isError: true };
|
|
1192
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1193
|
+
}
|
|
1194
|
+
);
|
|
1195
|
+
|
|
1196
|
+
// ---------------------------------------------------------------------------
|
|
1197
|
+
// proofread_stats
|
|
1198
|
+
// ---------------------------------------------------------------------------
|
|
1199
|
+
|
|
1200
|
+
server.registerTool(
|
|
1201
|
+
"proofread_stats",
|
|
1202
|
+
{
|
|
1203
|
+
title: "Proofread Stats",
|
|
1204
|
+
description: "Get proofread issue statistics for a transcript: total, by type, pending/applied/dismissed counts.",
|
|
1205
|
+
inputSchema: {
|
|
1206
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
1207
|
+
},
|
|
1208
|
+
},
|
|
1209
|
+
async ({ transcript_id }) => {
|
|
1210
|
+
const stats = getProofreadStats(transcript_id);
|
|
1211
|
+
return { content: [{ type: "text", text: JSON.stringify(stats, null, 2) }] };
|
|
1212
|
+
}
|
|
1213
|
+
);
|
|
1214
|
+
|
|
1215
|
+
// ---------------------------------------------------------------------------
|
|
1216
|
+
// export_annotated
|
|
1217
|
+
// ---------------------------------------------------------------------------
|
|
1218
|
+
|
|
1219
|
+
server.registerTool(
|
|
1220
|
+
"export_annotated",
|
|
1221
|
+
{
|
|
1222
|
+
title: "Export Annotated Transcript",
|
|
1223
|
+
description: "Export transcript text with inline proofread annotations showing pending issues as [TYPE: \"original\" -> \"suggestion\"] markers.",
|
|
1224
|
+
inputSchema: {
|
|
1225
|
+
transcript_id: z.string().describe("Transcript ID"),
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
async ({ transcript_id }) => {
|
|
1229
|
+
try {
|
|
1230
|
+
const text = exportAnnotated(transcript_id);
|
|
1231
|
+
return { content: [{ type: "text", text }] };
|
|
1232
|
+
} catch (error) {
|
|
1233
|
+
return { content: [{ type: "text", text: `Export failed: ${error instanceof Error ? error.message : error}` }], isError: true };
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
);
|
|
1237
|
+
|
|
994
1238
|
// ---------------------------------------------------------------------------
|
|
995
1239
|
// search_tools / describe_tools
|
|
996
1240
|
// ---------------------------------------------------------------------------
|
|
@@ -1021,6 +1265,16 @@ server.registerTool(
|
|
|
1021
1265
|
"get_config",
|
|
1022
1266
|
"set_config",
|
|
1023
1267
|
"reset_config",
|
|
1268
|
+
"list_comments",
|
|
1269
|
+
"top_comments",
|
|
1270
|
+
"search_comments",
|
|
1271
|
+
"comment_stats",
|
|
1272
|
+
"proofread_transcript",
|
|
1273
|
+
"list_proofread_issues",
|
|
1274
|
+
"apply_suggestion",
|
|
1275
|
+
"dismiss_issue",
|
|
1276
|
+
"proofread_stats",
|
|
1277
|
+
"export_annotated",
|
|
1024
1278
|
"search_tools",
|
|
1025
1279
|
"describe_tools",
|
|
1026
1280
|
];
|
|
@@ -1048,6 +1302,12 @@ server.registerTool(
|
|
|
1048
1302
|
export_transcript: "Export as txt/srt/json. Params: id, format?",
|
|
1049
1303
|
transcript_stats: "Counts by status and provider.",
|
|
1050
1304
|
check_providers: "Check which API keys are configured.",
|
|
1305
|
+
proofread_transcript: "AI spellcheck/proofread. Params: id, types?, confidence_threshold?, provider?",
|
|
1306
|
+
list_proofread_issues: "List proofread issues. Params: transcript_id, issue_type?, status?",
|
|
1307
|
+
apply_suggestion: "Apply a proofread suggestion. Params: issue_id",
|
|
1308
|
+
dismiss_issue: "Dismiss a proofread issue. Params: issue_id",
|
|
1309
|
+
proofread_stats: "Proofread stats. Params: transcript_id",
|
|
1310
|
+
export_annotated: "Export with inline annotations. Params: transcript_id",
|
|
1051
1311
|
};
|
|
1052
1312
|
const result = names.map((n) => `${n}: ${descriptions[n] || "See tool schema"}`).join("\n");
|
|
1053
1313
|
return { content: [{ type: "text" as const, text: result }] };
|
package/package.json
CHANGED