feat: mcp and backfill fixes
This commit is contained in:
1 parent
c6984a7286
commit
17cd31c41e
20 files changed
+566
-37
No files matched your search
@@ -280,6 +280,10 @@ export function getJob(jobId: number): Promise<JobView> {
|
||||
return request<JobView>(`/jobs/${jobId}`, { account: true });
|
||||
}
|
||||
|
||||
export function cancelJob(jobId: number): Promise<JobView> {
|
||||
return request<JobView>(`/jobs/${jobId}/cancel`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function listJobs(status?: JobStatus): Promise<JobView[]> {
|
||||
return request<JobView[]>("/jobs", {
|
||||
account: true,
|
||||
@@ -350,6 +354,20 @@ export function fetchMedia(
|
||||
});
|
||||
}
|
||||
|
||||
export function transcribeMedia(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<{ job_id: number }> {
|
||||
return request<{ job_id: number }>("/media/transcribe", {
|
||||
method: "POST",
|
||||
body: {
|
||||
account_id: accounts.selectedId,
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function listWatches(): Promise<Watch[]> {
|
||||
return request<Watch[]>("/watches", { account: true });
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { requestMedia } from "$lib/api/client";
|
||||
import { getMessageMedia } from "$lib/api/endpoints";
|
||||
import { getMessageMedia, transcribeMedia } from "$lib/api/endpoints";
|
||||
import type { MediaRef } from "$lib/api/types";
|
||||
import { accounts } from "$lib/stores/accounts.svelte";
|
||||
|
||||
const TRANSCRIBE_TRIES = 10;
|
||||
const TRANSCRIBE_DELAY = 2000;
|
||||
|
||||
export type InlineMedia =
|
||||
| {
|
||||
state: "ready";
|
||||
@@ -143,6 +146,43 @@ export function loadMediaItem(media: MediaRef): Promise<InlineMedia> {
|
||||
return promise;
|
||||
}
|
||||
|
||||
function patchTranscript(
|
||||
chatId: number,
|
||||
messageId: number,
|
||||
text: string
|
||||
): void {
|
||||
const account = accounts.selectedId;
|
||||
if (account === null) {
|
||||
return;
|
||||
}
|
||||
const cached = ready.get(cacheKey(account, chatId, messageId));
|
||||
if (cached?.state === "ready") {
|
||||
cached.transcript = text;
|
||||
}
|
||||
}
|
||||
|
||||
export async function requestTranscription(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
): Promise<string | null> {
|
||||
await transcribeMedia(chatId, messageId);
|
||||
for (let i = 0; i < TRANSCRIBE_TRIES; i++) {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, TRANSCRIBE_DELAY);
|
||||
});
|
||||
try {
|
||||
const meta = await getMessageMedia(chatId, messageId);
|
||||
if (meta.extracted_text) {
|
||||
patchTranscript(chatId, messageId, meta.extracted_text);
|
||||
return meta.extracted_text;
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function loadInlineMedia(
|
||||
chatId: number,
|
||||
messageId: number
|
||||
|
||||
Reference in new issue
Block a user