Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160// The export extension's routes (/extensions/export): the local redaction// tagger the daemon may download, and the redacted trace exports of a// session. The daemon checks every gate; nothing here decides what may leave.
import type { components } from './api.gen';import { failure, request } from './api';
const BASE = '/extensions/export';
type Schemas = components['schemas'];
export type Tagger = Schemas['ExportTagger'];export type TaggerState = Tagger['state'];export type ExportJob = Schemas['ExportJob'];export type ExportScope = ExportJob['scope'];export type TaggerError = Schemas['ExportTaggerError'];export type JobError = Schemas['ExportJobError'];export type OmissionKind = Schemas['ExportOmissionKind'];/** One trace.jsonl row, or a piece of a long one: `offset` is its UTF-8 byte offset in the row, `complete` marks the row's last piece. */export type PreviewLine = Schemas['ExportPreviewLine'];export type PreviewPage = Schemas['ExportPreviewPage'];/** One redaction: Unicode scalar offsets into the redacted string at `path` (a JSON Pointer into row `line`), or into that key. */export type Finding = Schemas['ExportFinding'];export type FindingPage = Schemas['ExportFindingPage'];export type FindingCategory = Schemas['ExportCategory'];
/** The tagger as this daemon has it: absent, downloading, verifying, ready, or failed. */export function readTagger(signal?: AbortSignal): Promise<Tagger> { return request('GET', `${BASE}/tagger`, { signal });}
/** Starts or resumes the model download; the daemon answers with the tagger's new state. */export function installTagger(): Promise<Tagger> { return request('POST', `${BASE}/tagger/install`);}
/** Stops a download, keeping verified partial files to resume from. */export function cancelTagger(): Promise<Tagger> { return request('POST', `${BASE}/tagger/cancel`);}
/** Deletes the downloaded model; the daemon refuses while an export uses it. */export function removeTagger(): Promise<Tagger> { return request('DELETE', `${BASE}/tagger`);}
/** Starts an export. Sending the same id and scope again replays it; another scope under that id is a 409. */export function createExport( sessionId: string, id: string, scope: ExportScope,): Promise<ExportJob> { return request( 'POST', `${BASE}/sessions/${encodeURIComponent(sessionId)}/exports`, { body: { id, scope } }, );}
/** The session's newest exports, newest first. */export async function listExports( sessionId: string, signal?: AbortSignal,): Promise<ExportJob[]> { const page = await request<Schemas['ExportJobPage']>( 'GET', `${BASE}/sessions/${encodeURIComponent(sessionId)}/exports`, { signal }, ); return page.items;}
/** One export and the validator approving it needs. */export async function readExport( id: string, signal?: AbortSignal,): Promise<{ job: ExportJob; etag: string }> { const response = await fetch( `/api${BASE}/exports/${encodeURIComponent(id)}`, { signal, headers: { accept: 'application/json' } }, ); if (!response.ok) throw await failure(response); return { job: await response.json(), etag: response.headers.get('etag') ?? '', };}
/** One bounded page of the redacted trace.jsonl, the exact rows the archive holds. */export function readPreview( id: string, next: string | null, signal?: AbortSignal,): Promise<PreviewPage> { return request( 'GET', `${BASE}/exports/${encodeURIComponent(id)}/preview?${page(next, 50)}`, { signal, }, );}
/** One page of what the scan redacted, the same data as redaction-report.json. */export function readFindings( id: string, from: { next: string | null; line: number }, signal?: AbortSignal,): Promise<FindingPage> { const query = page(from.next, 200); if (!from.next) query.set('line_from', String(from.line)); return request( 'GET', `${BASE}/exports/${encodeURIComponent(id)}/findings?${query}`, { signal, }, );}
function page(next: string | null, limit: number): URLSearchParams { const query = new URLSearchParams({ limit: String(limit) }); if (next) query.set('next', next); return query;}
/** Approves the reviewed copy at the revision read; a stale `etag` is refused. */export function approveExport(id: string, etag: string): Promise<ExportJob> { return request('POST', `${BASE}/exports/${encodeURIComponent(id)}/approve`, { body: { reviewed: true }, headers: { 'if-match': etag }, });}
/** Stops a scan; nothing of it can be downloaded. */export function cancelExport(id: string): Promise<ExportJob> { return request('POST', `${BASE}/exports/${encodeURIComponent(id)}/cancel`);}
/** Deletes this export's redacted copy; the session is untouched. */export function deleteExport(id: string): Promise<unknown> { return request('DELETE', `${BASE}/exports/${encodeURIComponent(id)}`);}
/** * Starts the browser's own download of an approved export's zip. It is a * same-origin link, so the web cookie signs it and the daemon's answer * streams to disk under the name its Content-Disposition gives, with no * copy held in the page. A refusal shows in the browser's downloads. */export function downloadArchive(id: string) { const link = document.createElement('a'); link.href = `/api${BASE}/exports/${encodeURIComponent(id)}/archive`; link.download = ''; link.rel = 'noopener'; document.body.append(link); link.click(); link.remove();}