@hasna/microservices 0.0.2 → 0.0.4
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/bin/index.js +70 -0
- package/bin/mcp.js +71 -1
- package/dist/index.js +70 -0
- package/microservices/microservice-ads/package.json +27 -0
- package/microservices/microservice-ads/src/cli/index.ts +407 -0
- package/microservices/microservice-ads/src/db/campaigns.ts +493 -0
- package/microservices/microservice-ads/src/db/database.ts +93 -0
- package/microservices/microservice-ads/src/db/migrations.ts +60 -0
- package/microservices/microservice-ads/src/index.ts +39 -0
- package/microservices/microservice-ads/src/mcp/index.ts +320 -0
- package/microservices/microservice-contracts/package.json +27 -0
- package/microservices/microservice-contracts/src/cli/index.ts +383 -0
- package/microservices/microservice-contracts/src/db/contracts.ts +496 -0
- package/microservices/microservice-contracts/src/db/database.ts +93 -0
- package/microservices/microservice-contracts/src/db/migrations.ts +58 -0
- package/microservices/microservice-contracts/src/index.ts +43 -0
- package/microservices/microservice-contracts/src/mcp/index.ts +308 -0
- package/microservices/microservice-domains/package.json +27 -0
- package/microservices/microservice-domains/src/cli/index.ts +438 -0
- package/microservices/microservice-domains/src/db/database.ts +93 -0
- package/microservices/microservice-domains/src/db/domains.ts +551 -0
- package/microservices/microservice-domains/src/db/migrations.ts +60 -0
- package/microservices/microservice-domains/src/index.ts +44 -0
- package/microservices/microservice-domains/src/mcp/index.ts +368 -0
- package/microservices/microservice-hiring/package.json +27 -0
- package/microservices/microservice-hiring/src/cli/index.ts +431 -0
- package/microservices/microservice-hiring/src/db/database.ts +93 -0
- package/microservices/microservice-hiring/src/db/hiring.ts +582 -0
- package/microservices/microservice-hiring/src/db/migrations.ts +68 -0
- package/microservices/microservice-hiring/src/index.ts +51 -0
- package/microservices/microservice-hiring/src/mcp/index.ts +464 -0
- package/microservices/microservice-payments/package.json +27 -0
- package/microservices/microservice-payments/src/cli/index.ts +357 -0
- package/microservices/microservice-payments/src/db/database.ts +93 -0
- package/microservices/microservice-payments/src/db/migrations.ts +63 -0
- package/microservices/microservice-payments/src/db/payments.ts +652 -0
- package/microservices/microservice-payments/src/index.ts +51 -0
- package/microservices/microservice-payments/src/mcp/index.ts +460 -0
- package/microservices/microservice-payroll/package.json +27 -0
- package/microservices/microservice-payroll/src/cli/index.ts +374 -0
- package/microservices/microservice-payroll/src/db/database.ts +93 -0
- package/microservices/microservice-payroll/src/db/migrations.ts +69 -0
- package/microservices/microservice-payroll/src/db/payroll.ts +741 -0
- package/microservices/microservice-payroll/src/index.ts +48 -0
- package/microservices/microservice-payroll/src/mcp/index.ts +420 -0
- package/microservices/microservice-shipping/package.json +27 -0
- package/microservices/microservice-shipping/src/cli/index.ts +398 -0
- package/microservices/microservice-shipping/src/db/database.ts +93 -0
- package/microservices/microservice-shipping/src/db/migrations.ts +61 -0
- package/microservices/microservice-shipping/src/db/shipping.ts +643 -0
- package/microservices/microservice-shipping/src/index.ts +53 -0
- package/microservices/microservice-shipping/src/mcp/index.ts +385 -0
- package/microservices/microservice-social/package.json +27 -0
- package/microservices/microservice-social/src/cli/index.ts +447 -0
- package/microservices/microservice-social/src/db/database.ts +93 -0
- package/microservices/microservice-social/src/db/migrations.ts +55 -0
- package/microservices/microservice-social/src/db/social.ts +672 -0
- package/microservices/microservice-social/src/index.ts +46 -0
- package/microservices/microservice-social/src/mcp/index.ts +435 -0
- package/microservices/microservice-subscriptions/package.json +27 -0
- package/microservices/microservice-subscriptions/src/cli/index.ts +400 -0
- package/microservices/microservice-subscriptions/src/db/database.ts +93 -0
- package/microservices/microservice-subscriptions/src/db/migrations.ts +57 -0
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +692 -0
- package/microservices/microservice-subscriptions/src/index.ts +41 -0
- package/microservices/microservice-subscriptions/src/mcp/index.ts +365 -0
- package/microservices/microservice-transcriber/package.json +28 -0
- package/microservices/microservice-transcriber/src/cli/index.ts +1347 -0
- package/microservices/microservice-transcriber/src/db/annotations.ts +37 -0
- package/microservices/microservice-transcriber/src/db/database.ts +82 -0
- package/microservices/microservice-transcriber/src/db/migrations.ts +72 -0
- package/microservices/microservice-transcriber/src/db/transcripts.ts +395 -0
- package/microservices/microservice-transcriber/src/index.ts +43 -0
- package/microservices/microservice-transcriber/src/lib/config.ts +77 -0
- package/microservices/microservice-transcriber/src/lib/diff.ts +91 -0
- package/microservices/microservice-transcriber/src/lib/downloader.ts +570 -0
- package/microservices/microservice-transcriber/src/lib/feeds.ts +62 -0
- package/microservices/microservice-transcriber/src/lib/live.ts +94 -0
- package/microservices/microservice-transcriber/src/lib/notion.ts +129 -0
- package/microservices/microservice-transcriber/src/lib/providers.ts +713 -0
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +147 -0
- package/microservices/microservice-transcriber/src/lib/translator.ts +75 -0
- package/microservices/microservice-transcriber/src/lib/webhook.ts +37 -0
- package/microservices/microservice-transcriber/src/mcp/index.ts +1070 -0
- package/microservices/microservice-transcriber/src/server/index.ts +199 -0
- package/package.json +1 -1
- package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
- package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
- package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getDatabase } from "./database.js";
|
|
2
|
+
|
|
3
|
+
export interface Annotation {
|
|
4
|
+
id: string;
|
|
5
|
+
transcript_id: string;
|
|
6
|
+
timestamp_sec: number;
|
|
7
|
+
note: string;
|
|
8
|
+
created_at: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createAnnotation(transcriptId: string, timestampSec: number, note: string): Annotation {
|
|
12
|
+
const db = getDatabase();
|
|
13
|
+
const id = crypto.randomUUID();
|
|
14
|
+
db.prepare("INSERT INTO annotations (id, transcript_id, timestamp_sec, note) VALUES (?, ?, ?, ?)").run(id, transcriptId, timestampSec, note);
|
|
15
|
+
return getAnnotation(id)!;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getAnnotation(id: string): Annotation | null {
|
|
19
|
+
const db = getDatabase();
|
|
20
|
+
return db.prepare("SELECT * FROM annotations WHERE id = ?").get(id) as Annotation | null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function listAnnotations(transcriptId: string): Annotation[] {
|
|
24
|
+
const db = getDatabase();
|
|
25
|
+
return db.prepare("SELECT * FROM annotations WHERE transcript_id = ? ORDER BY timestamp_sec ASC").all(transcriptId) as Annotation[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function deleteAnnotation(id: string): boolean {
|
|
29
|
+
const db = getDatabase();
|
|
30
|
+
return db.prepare("DELETE FROM annotations WHERE id = ?").run(id).changes > 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function formatTimestamp(sec: number): string {
|
|
34
|
+
const m = Math.floor(sec / 60);
|
|
35
|
+
const s = Math.floor(sec % 60);
|
|
36
|
+
return `${m}:${String(s).padStart(2, "0")}`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection for microservice-transcriber
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Database } from "bun:sqlite";
|
|
6
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { MIGRATIONS } from "./migrations.js";
|
|
9
|
+
|
|
10
|
+
let _db: Database | null = null;
|
|
11
|
+
|
|
12
|
+
function getDbPath(): string {
|
|
13
|
+
if (process.env["MICROSERVICES_DIR"]) {
|
|
14
|
+
return join(process.env["MICROSERVICES_DIR"], "microservice-transcriber", "data.db");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let dir = resolve(process.cwd());
|
|
18
|
+
while (true) {
|
|
19
|
+
const msDir = join(dir, ".microservices");
|
|
20
|
+
if (existsSync(msDir)) return join(msDir, "microservice-transcriber", "data.db");
|
|
21
|
+
const parent = dirname(dir);
|
|
22
|
+
if (parent === dir) break;
|
|
23
|
+
dir = parent;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
27
|
+
return join(home, ".microservices", "microservice-transcriber", "data.db");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getDatabase(): Database {
|
|
31
|
+
if (_db) return _db;
|
|
32
|
+
|
|
33
|
+
const dbPath = getDbPath();
|
|
34
|
+
const dataDir = dirname(dbPath);
|
|
35
|
+
if (!existsSync(dataDir)) {
|
|
36
|
+
mkdirSync(dataDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_db = new Database(dbPath);
|
|
40
|
+
_db.exec("PRAGMA journal_mode = WAL");
|
|
41
|
+
_db.exec("PRAGMA foreign_keys = ON");
|
|
42
|
+
|
|
43
|
+
_db.exec(`
|
|
44
|
+
CREATE TABLE IF NOT EXISTS _migrations (
|
|
45
|
+
id INTEGER PRIMARY KEY,
|
|
46
|
+
name TEXT NOT NULL,
|
|
47
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
48
|
+
)
|
|
49
|
+
`);
|
|
50
|
+
|
|
51
|
+
const applied = _db
|
|
52
|
+
.query("SELECT id FROM _migrations ORDER BY id")
|
|
53
|
+
.all() as { id: number }[];
|
|
54
|
+
const appliedIds = new Set(applied.map((r) => r.id));
|
|
55
|
+
|
|
56
|
+
for (const migration of MIGRATIONS) {
|
|
57
|
+
if (appliedIds.has(migration.id)) continue;
|
|
58
|
+
_db.exec("BEGIN");
|
|
59
|
+
try {
|
|
60
|
+
_db.exec(migration.sql);
|
|
61
|
+
_db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
|
|
62
|
+
migration.id,
|
|
63
|
+
migration.name
|
|
64
|
+
);
|
|
65
|
+
_db.exec("COMMIT");
|
|
66
|
+
} catch (error) {
|
|
67
|
+
_db.exec("ROLLBACK");
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return _db;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function closeDatabase(): void {
|
|
78
|
+
if (_db) {
|
|
79
|
+
_db.close();
|
|
80
|
+
_db = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface MigrationEntry {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
sql: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const MIGRATIONS: MigrationEntry[] = [
|
|
8
|
+
{
|
|
9
|
+
id: 1,
|
|
10
|
+
name: "initial_schema",
|
|
11
|
+
sql: `
|
|
12
|
+
CREATE TABLE IF NOT EXISTS transcripts (
|
|
13
|
+
id TEXT PRIMARY KEY,
|
|
14
|
+
title TEXT,
|
|
15
|
+
source_url TEXT,
|
|
16
|
+
source_type TEXT NOT NULL DEFAULT 'file',
|
|
17
|
+
provider TEXT NOT NULL DEFAULT 'elevenlabs',
|
|
18
|
+
language TEXT DEFAULT 'en',
|
|
19
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
20
|
+
transcript_text TEXT,
|
|
21
|
+
error_message TEXT,
|
|
22
|
+
metadata TEXT NOT NULL DEFAULT '{}',
|
|
23
|
+
created_at TEXT NOT NULL,
|
|
24
|
+
updated_at TEXT NOT NULL,
|
|
25
|
+
duration_seconds REAL,
|
|
26
|
+
word_count INTEGER
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE INDEX IF NOT EXISTS idx_transcripts_status ON transcripts(status);
|
|
30
|
+
CREATE INDEX IF NOT EXISTS idx_transcripts_source_type ON transcripts(source_type);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_transcripts_provider ON transcripts(provider);
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_transcripts_created_at ON transcripts(created_at);
|
|
33
|
+
`,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 2,
|
|
37
|
+
name: "add_source_transcript_id",
|
|
38
|
+
sql: `
|
|
39
|
+
ALTER TABLE transcripts ADD COLUMN source_transcript_id TEXT;
|
|
40
|
+
CREATE INDEX IF NOT EXISTS idx_transcripts_source_transcript_id ON transcripts(source_transcript_id);
|
|
41
|
+
`,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 3,
|
|
45
|
+
name: "add_transcript_tags",
|
|
46
|
+
sql: `
|
|
47
|
+
CREATE TABLE IF NOT EXISTS transcript_tags (
|
|
48
|
+
transcript_id TEXT NOT NULL,
|
|
49
|
+
tag TEXT NOT NULL,
|
|
50
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
51
|
+
PRIMARY KEY (transcript_id, tag),
|
|
52
|
+
FOREIGN KEY (transcript_id) REFERENCES transcripts(id) ON DELETE CASCADE
|
|
53
|
+
);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_transcript_tags_tag ON transcript_tags(tag);
|
|
55
|
+
`,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 4,
|
|
59
|
+
name: "add_annotations",
|
|
60
|
+
sql: `
|
|
61
|
+
CREATE TABLE IF NOT EXISTS annotations (
|
|
62
|
+
id TEXT PRIMARY KEY,
|
|
63
|
+
transcript_id TEXT NOT NULL,
|
|
64
|
+
timestamp_sec REAL NOT NULL,
|
|
65
|
+
note TEXT NOT NULL,
|
|
66
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
67
|
+
FOREIGN KEY (transcript_id) REFERENCES transcripts(id) ON DELETE CASCADE
|
|
68
|
+
);
|
|
69
|
+
CREATE INDEX IF NOT EXISTS idx_annotations_transcript ON annotations(transcript_id);
|
|
70
|
+
`,
|
|
71
|
+
},
|
|
72
|
+
];
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { getDatabase } from "./database.js";
|
|
2
|
+
|
|
3
|
+
export type TranscriptStatus = "pending" | "processing" | "completed" | "failed";
|
|
4
|
+
export type TranscriptProvider = "elevenlabs" | "openai" | "deepgram";
|
|
5
|
+
export type TranscriptSourceType = "file" | "youtube" | "vimeo" | "wistia" | "url" | "translated";
|
|
6
|
+
|
|
7
|
+
export interface TranscriptWord {
|
|
8
|
+
text: string;
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
type?: string;
|
|
12
|
+
speaker_id?: string;
|
|
13
|
+
logprob?: number; // log probability from ElevenLabs; confidence = Math.exp(logprob)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TranscriptSpeakerSegment {
|
|
17
|
+
speaker_id: string;
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
text: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TranscriptSegment {
|
|
24
|
+
start: number;
|
|
25
|
+
end: number;
|
|
26
|
+
text: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface TranscriptChapterSegment {
|
|
30
|
+
title: string;
|
|
31
|
+
start_time: number;
|
|
32
|
+
end_time: number;
|
|
33
|
+
text: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface TranscriptMetadata {
|
|
37
|
+
model?: string;
|
|
38
|
+
words?: TranscriptWord[];
|
|
39
|
+
segments?: TranscriptSegment[];
|
|
40
|
+
speakers?: TranscriptSpeakerSegment[];
|
|
41
|
+
chapters?: TranscriptChapterSegment[];
|
|
42
|
+
language_probability?: number;
|
|
43
|
+
trim_start?: number;
|
|
44
|
+
trim_end?: number;
|
|
45
|
+
diarized?: boolean;
|
|
46
|
+
summary?: string;
|
|
47
|
+
highlights?: Array<{ quote: string; speaker?: string; context: string }>;
|
|
48
|
+
meeting_notes?: string;
|
|
49
|
+
cost_usd?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Transcript {
|
|
53
|
+
id: string;
|
|
54
|
+
title: string | null;
|
|
55
|
+
source_url: string | null;
|
|
56
|
+
source_type: TranscriptSourceType;
|
|
57
|
+
provider: TranscriptProvider;
|
|
58
|
+
language: string;
|
|
59
|
+
status: TranscriptStatus;
|
|
60
|
+
transcript_text: string | null;
|
|
61
|
+
error_message: string | null;
|
|
62
|
+
metadata: TranscriptMetadata;
|
|
63
|
+
created_at: string;
|
|
64
|
+
updated_at: string;
|
|
65
|
+
duration_seconds: number | null;
|
|
66
|
+
word_count: number | null;
|
|
67
|
+
source_transcript_id: string | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface CreateTranscriptInput {
|
|
71
|
+
source_url: string;
|
|
72
|
+
source_type: TranscriptSourceType;
|
|
73
|
+
provider?: TranscriptProvider;
|
|
74
|
+
language?: string;
|
|
75
|
+
title?: string;
|
|
76
|
+
source_transcript_id?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface UpdateTranscriptInput {
|
|
80
|
+
title?: string;
|
|
81
|
+
status?: TranscriptStatus;
|
|
82
|
+
transcript_text?: string;
|
|
83
|
+
error_message?: string | null;
|
|
84
|
+
metadata?: TranscriptMetadata;
|
|
85
|
+
duration_seconds?: number;
|
|
86
|
+
word_count?: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ListTranscriptsOptions {
|
|
90
|
+
status?: TranscriptStatus;
|
|
91
|
+
provider?: TranscriptProvider;
|
|
92
|
+
source_type?: TranscriptSourceType;
|
|
93
|
+
limit?: number;
|
|
94
|
+
offset?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface TranscriptRow {
|
|
98
|
+
id: string;
|
|
99
|
+
title: string | null;
|
|
100
|
+
source_url: string | null;
|
|
101
|
+
source_type: string;
|
|
102
|
+
provider: string;
|
|
103
|
+
language: string;
|
|
104
|
+
status: string;
|
|
105
|
+
transcript_text: string | null;
|
|
106
|
+
error_message: string | null;
|
|
107
|
+
metadata: string;
|
|
108
|
+
created_at: string;
|
|
109
|
+
updated_at: string;
|
|
110
|
+
duration_seconds: number | null;
|
|
111
|
+
word_count: number | null;
|
|
112
|
+
source_transcript_id: string | null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function rowToTranscript(row: TranscriptRow): Transcript {
|
|
116
|
+
return {
|
|
117
|
+
...row,
|
|
118
|
+
source_type: row.source_type as TranscriptSourceType,
|
|
119
|
+
provider: row.provider as TranscriptProvider,
|
|
120
|
+
status: row.status as TranscriptStatus,
|
|
121
|
+
metadata: JSON.parse(row.metadata || "{}"),
|
|
122
|
+
source_transcript_id: row.source_transcript_id ?? null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function now(): string {
|
|
127
|
+
return new Date().toISOString();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function createTranscript(input: CreateTranscriptInput): Transcript {
|
|
131
|
+
const db = getDatabase();
|
|
132
|
+
const id = crypto.randomUUID();
|
|
133
|
+
const ts = now();
|
|
134
|
+
|
|
135
|
+
db.prepare(`
|
|
136
|
+
INSERT INTO transcripts (id, title, source_url, source_type, provider, language, status, metadata, created_at, updated_at, source_transcript_id)
|
|
137
|
+
VALUES (?, ?, ?, ?, ?, ?, 'pending', '{}', ?, ?, ?)
|
|
138
|
+
`).run(
|
|
139
|
+
id,
|
|
140
|
+
input.title ?? null,
|
|
141
|
+
input.source_url,
|
|
142
|
+
input.source_type,
|
|
143
|
+
input.provider ?? "elevenlabs",
|
|
144
|
+
input.language ?? "en",
|
|
145
|
+
ts,
|
|
146
|
+
ts,
|
|
147
|
+
input.source_transcript_id ?? null
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return getTranscript(id)!;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function getTranscript(id: string): Transcript | null {
|
|
154
|
+
const db = getDatabase();
|
|
155
|
+
const row = db.prepare("SELECT * FROM transcripts WHERE id = ?").get(id) as TranscriptRow | null;
|
|
156
|
+
return row ? rowToTranscript(row) : null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function updateTranscript(id: string, input: UpdateTranscriptInput): Transcript | null {
|
|
160
|
+
const db = getDatabase();
|
|
161
|
+
const existing = getTranscript(id);
|
|
162
|
+
if (!existing) return null;
|
|
163
|
+
|
|
164
|
+
const fields: string[] = ["updated_at = ?"];
|
|
165
|
+
const values: unknown[] = [now()];
|
|
166
|
+
|
|
167
|
+
if (input.title !== undefined) { fields.push("title = ?"); values.push(input.title); }
|
|
168
|
+
if (input.status !== undefined) { fields.push("status = ?"); values.push(input.status); }
|
|
169
|
+
if (input.transcript_text !== undefined) { fields.push("transcript_text = ?"); values.push(input.transcript_text); }
|
|
170
|
+
if (input.error_message !== undefined) { fields.push("error_message = ?"); values.push(input.error_message); }
|
|
171
|
+
if (input.metadata !== undefined) { fields.push("metadata = ?"); values.push(JSON.stringify(input.metadata)); }
|
|
172
|
+
if (input.duration_seconds !== undefined) { fields.push("duration_seconds = ?"); values.push(input.duration_seconds); }
|
|
173
|
+
if (input.word_count !== undefined) { fields.push("word_count = ?"); values.push(input.word_count); }
|
|
174
|
+
|
|
175
|
+
values.push(id);
|
|
176
|
+
db.prepare(`UPDATE transcripts SET ${fields.join(", ")} WHERE id = ?`).run(...values);
|
|
177
|
+
|
|
178
|
+
return getTranscript(id);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function deleteTranscript(id: string): boolean {
|
|
182
|
+
const db = getDatabase();
|
|
183
|
+
const result = db.prepare("DELETE FROM transcripts WHERE id = ?").run(id);
|
|
184
|
+
return result.changes > 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function listTranscripts(options: ListTranscriptsOptions = {}): Transcript[] {
|
|
188
|
+
const db = getDatabase();
|
|
189
|
+
const conditions: string[] = [];
|
|
190
|
+
const values: unknown[] = [];
|
|
191
|
+
|
|
192
|
+
if (options.status) { conditions.push("status = ?"); values.push(options.status); }
|
|
193
|
+
if (options.provider) { conditions.push("provider = ?"); values.push(options.provider); }
|
|
194
|
+
if (options.source_type) { conditions.push("source_type = ?"); values.push(options.source_type); }
|
|
195
|
+
|
|
196
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
197
|
+
const limit = options.limit ?? 50;
|
|
198
|
+
const offset = options.offset ?? 0;
|
|
199
|
+
|
|
200
|
+
const rows = db
|
|
201
|
+
.prepare(`SELECT * FROM transcripts ${where} ORDER BY created_at DESC LIMIT ? OFFSET ?`)
|
|
202
|
+
.all(...values, limit, offset) as TranscriptRow[];
|
|
203
|
+
|
|
204
|
+
return rows.map(rowToTranscript);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function searchTranscripts(query: string): Transcript[] {
|
|
208
|
+
const db = getDatabase();
|
|
209
|
+
const q = `%${query}%`;
|
|
210
|
+
const rows = db
|
|
211
|
+
.prepare(`
|
|
212
|
+
SELECT * FROM transcripts
|
|
213
|
+
WHERE transcript_text LIKE ?
|
|
214
|
+
OR title LIKE ?
|
|
215
|
+
OR source_url LIKE ?
|
|
216
|
+
ORDER BY created_at DESC
|
|
217
|
+
LIMIT 50
|
|
218
|
+
`)
|
|
219
|
+
.all(q, q, q) as TranscriptRow[];
|
|
220
|
+
return rows.map(rowToTranscript);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Rename speakers in a transcript. Replaces labels in transcript_text,
|
|
225
|
+
* metadata.speakers[].speaker_id, and metadata.words[].speaker_id.
|
|
226
|
+
*/
|
|
227
|
+
export function renameSpeakers(
|
|
228
|
+
id: string,
|
|
229
|
+
mapping: Record<string, string> // e.g. {"Speaker 1": "Andrej Karpathy", "Speaker 2": "Sarah Guo"}
|
|
230
|
+
): Transcript | null {
|
|
231
|
+
const t = getTranscript(id);
|
|
232
|
+
if (!t) return null;
|
|
233
|
+
|
|
234
|
+
// Replace in transcript_text
|
|
235
|
+
let text = t.transcript_text ?? "";
|
|
236
|
+
for (const [from, to] of Object.entries(mapping)) {
|
|
237
|
+
text = text.replaceAll(`${from}:`, `${to}:`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Replace in metadata.speakers
|
|
241
|
+
const speakers = t.metadata.speakers?.map((s) => ({
|
|
242
|
+
...s,
|
|
243
|
+
speaker_id: mapping[s.speaker_id] ?? mapping[s.speaker_id.replace(/speaker_(\d+)/, (_, n) => `Speaker ${parseInt(n) + 1}`)] ?? s.speaker_id,
|
|
244
|
+
}));
|
|
245
|
+
|
|
246
|
+
// Replace in metadata.words
|
|
247
|
+
const words = t.metadata.words?.map((w) => {
|
|
248
|
+
if (!w.speaker_id) return w;
|
|
249
|
+
const label = w.speaker_id.replace(/speaker_(\d+)/, (_, n) => `Speaker ${parseInt(n) + 1}`);
|
|
250
|
+
const newId = mapping[label] ?? mapping[w.speaker_id] ?? w.speaker_id;
|
|
251
|
+
return { ...w, speaker_id: newId };
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return updateTranscript(id, {
|
|
255
|
+
transcript_text: text,
|
|
256
|
+
metadata: { ...t.metadata, speakers, words },
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Find a completed transcript by source URL (for duplicate detection).
|
|
262
|
+
*/
|
|
263
|
+
export function findBySourceUrl(sourceUrl: string): Transcript | null {
|
|
264
|
+
const db = getDatabase();
|
|
265
|
+
const row = db
|
|
266
|
+
.prepare("SELECT * FROM transcripts WHERE source_url = ? AND status = 'completed' ORDER BY created_at DESC LIMIT 1")
|
|
267
|
+
.get(sourceUrl) as TranscriptRow | null;
|
|
268
|
+
return row ? rowToTranscript(row) : null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// Tags
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
export function addTags(transcriptId: string, tags: string[]): string[] {
|
|
276
|
+
const db = getDatabase();
|
|
277
|
+
const stmt = db.prepare("INSERT OR IGNORE INTO transcript_tags (transcript_id, tag) VALUES (?, ?)");
|
|
278
|
+
for (const tag of tags) {
|
|
279
|
+
stmt.run(transcriptId, tag.toLowerCase().trim());
|
|
280
|
+
}
|
|
281
|
+
return getTags(transcriptId);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function removeTags(transcriptId: string, tags: string[]): string[] {
|
|
285
|
+
const db = getDatabase();
|
|
286
|
+
const stmt = db.prepare("DELETE FROM transcript_tags WHERE transcript_id = ? AND tag = ?");
|
|
287
|
+
for (const tag of tags) {
|
|
288
|
+
stmt.run(transcriptId, tag.toLowerCase().trim());
|
|
289
|
+
}
|
|
290
|
+
return getTags(transcriptId);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function getTags(transcriptId: string): string[] {
|
|
294
|
+
const db = getDatabase();
|
|
295
|
+
const rows = db
|
|
296
|
+
.prepare("SELECT tag FROM transcript_tags WHERE transcript_id = ? ORDER BY tag")
|
|
297
|
+
.all(transcriptId) as { tag: string }[];
|
|
298
|
+
return rows.map((r) => r.tag);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function listAllTags(): Array<{ tag: string; count: number }> {
|
|
302
|
+
const db = getDatabase();
|
|
303
|
+
return db
|
|
304
|
+
.prepare("SELECT tag, COUNT(*) as count FROM transcript_tags GROUP BY tag ORDER BY count DESC")
|
|
305
|
+
.all() as Array<{ tag: string; count: number }>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function listTranscriptsByTag(tag: string, limit = 50): Transcript[] {
|
|
309
|
+
const db = getDatabase();
|
|
310
|
+
const rows = db
|
|
311
|
+
.prepare(`
|
|
312
|
+
SELECT t.* FROM transcripts t
|
|
313
|
+
JOIN transcript_tags tt ON t.id = tt.transcript_id
|
|
314
|
+
WHERE tt.tag = ?
|
|
315
|
+
ORDER BY t.created_at DESC LIMIT ?
|
|
316
|
+
`)
|
|
317
|
+
.all(tag.toLowerCase().trim(), limit) as TranscriptRow[];
|
|
318
|
+
return rows.map(rowToTranscript);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface SearchMatch {
|
|
322
|
+
transcript_id: string;
|
|
323
|
+
title: string | null;
|
|
324
|
+
timestamp: string | null; // [MM:SS] if word timestamps available
|
|
325
|
+
excerpt: string; // matching text with surrounding context
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Search transcripts with surrounding context and timestamps.
|
|
330
|
+
* Returns excerpts with `contextSentences` sentences before/after each match.
|
|
331
|
+
*/
|
|
332
|
+
export function searchWithContext(query: string, contextSentences = 2): SearchMatch[] {
|
|
333
|
+
const transcripts = searchTranscripts(query);
|
|
334
|
+
const matches: SearchMatch[] = [];
|
|
335
|
+
|
|
336
|
+
for (const t of transcripts) {
|
|
337
|
+
if (!t.transcript_text) continue;
|
|
338
|
+
|
|
339
|
+
// Split into sentences
|
|
340
|
+
const sentences = t.transcript_text.split(/(?<=[.!?])\s+|(?<=\n)\s*/g).filter(Boolean);
|
|
341
|
+
const q = query.toLowerCase();
|
|
342
|
+
|
|
343
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
344
|
+
if (!sentences[i].toLowerCase().includes(q)) continue;
|
|
345
|
+
|
|
346
|
+
// Gather context window
|
|
347
|
+
const start = Math.max(0, i - contextSentences);
|
|
348
|
+
const end = Math.min(sentences.length, i + contextSentences + 1);
|
|
349
|
+
const excerpt = sentences.slice(start, end).join(" ");
|
|
350
|
+
|
|
351
|
+
// Find timestamp from word data
|
|
352
|
+
let timestamp: string | null = null;
|
|
353
|
+
if (t.metadata?.words) {
|
|
354
|
+
const matchWords = query.toLowerCase().split(/\s+/);
|
|
355
|
+
const firstWord = matchWords[0];
|
|
356
|
+
const wordEntry = t.metadata.words.find((w) => w.text.toLowerCase().includes(firstWord));
|
|
357
|
+
if (wordEntry) {
|
|
358
|
+
const m = Math.floor(wordEntry.start / 60);
|
|
359
|
+
const s = Math.floor(wordEntry.start % 60);
|
|
360
|
+
timestamp = `[${m}:${String(s).padStart(2, "0")}]`;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
matches.push({
|
|
365
|
+
transcript_id: t.id,
|
|
366
|
+
title: t.title,
|
|
367
|
+
timestamp,
|
|
368
|
+
excerpt: excerpt.length > 300 ? excerpt.slice(0, 300) + "…" : excerpt,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
break; // one match per transcript
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return matches;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export function countTranscripts(): { total: number; by_status: Record<string, number>; by_provider: Record<string, number> } {
|
|
379
|
+
const db = getDatabase();
|
|
380
|
+
const total = (db.prepare("SELECT COUNT(*) as n FROM transcripts").get() as { n: number }).n;
|
|
381
|
+
|
|
382
|
+
const byStatus = db
|
|
383
|
+
.prepare("SELECT status, COUNT(*) as n FROM transcripts GROUP BY status")
|
|
384
|
+
.all() as { status: string; n: number }[];
|
|
385
|
+
|
|
386
|
+
const byProvider = db
|
|
387
|
+
.prepare("SELECT provider, COUNT(*) as n FROM transcripts GROUP BY provider")
|
|
388
|
+
.all() as { provider: string; n: number }[];
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
total,
|
|
392
|
+
by_status: Object.fromEntries(byStatus.map((r) => [r.status, r.n])),
|
|
393
|
+
by_provider: Object.fromEntries(byProvider.map((r) => [r.provider, r.n])),
|
|
394
|
+
};
|
|
395
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createTranscript,
|
|
3
|
+
getTranscript,
|
|
4
|
+
updateTranscript,
|
|
5
|
+
deleteTranscript,
|
|
6
|
+
listTranscripts,
|
|
7
|
+
searchTranscripts,
|
|
8
|
+
countTranscripts,
|
|
9
|
+
renameSpeakers,
|
|
10
|
+
findBySourceUrl,
|
|
11
|
+
addTags,
|
|
12
|
+
removeTags,
|
|
13
|
+
getTags,
|
|
14
|
+
listAllTags,
|
|
15
|
+
listTranscriptsByTag,
|
|
16
|
+
searchWithContext,
|
|
17
|
+
type SearchMatch,
|
|
18
|
+
type Transcript,
|
|
19
|
+
type TranscriptStatus,
|
|
20
|
+
type TranscriptProvider,
|
|
21
|
+
type TranscriptSourceType,
|
|
22
|
+
type TranscriptMetadata,
|
|
23
|
+
type TranscriptWord,
|
|
24
|
+
type TranscriptSegment,
|
|
25
|
+
type TranscriptSpeakerSegment,
|
|
26
|
+
type TranscriptChapterSegment,
|
|
27
|
+
type CreateTranscriptInput,
|
|
28
|
+
type UpdateTranscriptInput,
|
|
29
|
+
type ListTranscriptsOptions,
|
|
30
|
+
} from "./db/transcripts.js";
|
|
31
|
+
|
|
32
|
+
export { getDatabase, closeDatabase } from "./db/database.js";
|
|
33
|
+
export { createAnnotation, getAnnotation, listAnnotations, deleteAnnotation, type Annotation } from "./db/annotations.js";
|
|
34
|
+
export { prepareAudio, detectSourceType, getVideoInfo, downloadAudio, downloadVideo, createClip, getAudioOutputDir, normalizeFilename, getAudioDuration, splitAudioIntoChunks, isPlaylistUrl, getPlaylistUrls, checkYtDlp, type TrimOptions, type VideoInfo, type VideoChapter, type DownloadResult, type DownloadAudioOptions, type DownloadAudioResult } from "./lib/downloader.js";
|
|
35
|
+
export { transcribeFile, checkProviders, estimateCost, toSrt, toVtt, toAss, toMarkdown, segmentByChapters, formatWithConfidence, type AssStyle } from "./lib/providers.js";
|
|
36
|
+
export { getConfig, setConfig, resetConfig, CONFIG_DEFAULTS, CONFIG_KEYS, type TranscriberConfig, type ConfigKey } from "./lib/config.js";
|
|
37
|
+
export { summarizeText, extractHighlights, generateMeetingNotes, getDefaultSummaryProvider, type SummaryProvider, type Highlight } from "./lib/summarizer.js";
|
|
38
|
+
export { translateText } from "./lib/translator.js";
|
|
39
|
+
export { wordDiff, formatDiff, diffStats, type DiffEntry } from "./lib/diff.js";
|
|
40
|
+
export { fetchFeedEpisodes, type FeedEpisode, type Feed } from "./lib/feeds.js";
|
|
41
|
+
export { fireWebhook, type WebhookPayload } from "./lib/webhook.js";
|
|
42
|
+
export { pushToNotion } from "./lib/notion.js";
|
|
43
|
+
export { startLiveTranscription, type LiveTranscribeOptions } from "./lib/live.js";
|