Andrey Epifancev 3f6debc18b feat(core): HttpClient port and byte-exact multipart builder
Refs #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa
2026-09-28 00:00:08 +04:00

59 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Порты core. Реализации — в src/obsidian (позже) и tests/fakes.ts.
export interface RecordingStore {
write(path: string, data: ArrayBuffer): Promise<void>;
read(path: string): Promise<ArrayBuffer>;
}
export interface ListedNote {
path: string;
frontmatter: Record<string, unknown>;
}
export interface NoteStore {
exists(path: string): Promise<boolean>;
create(path: string, content: string): Promise<void>;
// Все заметки vault, у которых во frontmatter есть voice-id, с их frontmatter.
// КОНТРАКТ: реализация MUST брать данные из metadataCache и MUST NOT читать
// содержимое файлов (vault.read / cachedRead / adapter). Вызывается на каждом
// tick, в том числе на телефоне. Данные могут отставать от диска — core
// перепроверяет состояние внутри process().
list(): Promise<ListedNote[]>;
// Атомарное чтение-изменение-запись. false, если заметки нет.
process(path: string, fn: (content: string) => string): Promise<boolean>;
}
export type TranscribeResult =
| { ok: true; text: string }
| { ok: false; kind: 'temporary' | 'permanent'; message: string };
export interface Transcriber {
transcribe(audio: ArrayBuffer, mime: string, signal: AbortSignal): Promise<TranscribeResult>;
}
export interface Env {
now(): Date;
random(): number;
readonly deviceId: string;
}
export interface HttpRequest {
url: string;
headers: Record<string, string>;
// Тип тела передаётся отдельно от headers: адаптер requestUrl кладёт его в
// параметр contentType, иначе boundary может потеряться.
contentType: string;
body: ArrayBuffer;
}
export interface HttpResponse {
status: number;
text: string;
}
// Любой HTTP-статус — ответ, не исключение. Исключение — только сетевой сбой.
// Сигнала и таймаута нет: requestUrl их не умеет, это делает провайдер в core.
export interface HttpClient {
post(req: HttpRequest): Promise<HttpResponse>;
}