/** * Widget-side ergonomics over the typed ArtifactsClient. * * The same arrangement `services/sessions.ts` makes, for the same reason: the * typed client reports failures two ways (a `TorukErrorResponse` envelope for * HTTP errors, a thrown `TorukSdkError` for network/config failures) and the * widget has to render both as one "artifact unavailable" state. * * This is NOT a second artifact API. Every call delegates to * `client.artifacts.*`, which talks only to the deployment-scoped external * plane. Core remains the sole source of truth: an artifact that has not been * fetched is simply not loaded, and nothing here ever synthesizes one. */ import { type WidgetClientParams } from './toruk-client'; import type { TorukArtifact, TorukArtifactList, TorukArtifactDownload, TorukArtifactType } from '@/artifacts/artifacts.types'; import { type SessionResult } from './sessions'; export type ArtifactResult = SessionResult; export type WidgetArtifactParams = WidgetClientParams; export declare const widgetArtifacts: { /** The artifacts generated in one conversation, newest first. */ list(params: WidgetArtifactParams, input: { sessionId: string; page?: number; limit?: number; type?: TorukArtifactType; }): Promise>; /** One artifact, with its inline content when it has any. */ get(params: WidgetArtifactParams, sessionId: string, artifactId: string): Promise>; /** * The artifact's bytes. * * `download()` rejects rather than returning an envelope — there is no partial * file — so it is wrapped to reach the same result shape as everything else. */ download(params: WidgetArtifactParams, sessionId: string, artifactId: string): Promise>; }; /** * * An `artifact-ref` block cannot fetch on its own — it is handed this. Two * things make that worth a factory rather than an object literal at the call * site: * * Deduplication. The same artifact id legitimately appears more than once: the * model may reference one artifact across several turns, and a transcript * replayed from history re-mounts every block at once. Without a shared cache * that is one request per occurrence, all for the same bytes. In-flight requests * are joined rather than reissued, so N blocks appearing together produce one * call. * * Stable identity. The returned object is created once per session, so a block * holding it does not see `props.artifacts` change on unrelated re-renders and * re-run its load effect. * * Failures are deliberately NOT cached. A cached failure would make the Retry * button inert and would pin a transient network error for the life of the * conversation; dropping it means the next attempt is a real one. */ export declare function createArtifactAccess(params: WidgetArtifactParams, sessionId: string): { load: (artifactId: string) => Promise<{ ok: true; data: TorukArtifact; } | { ok: false; message: string; }>; /** */ list: () => Promise<{ ok: true; data: TorukArtifact[]; } | { ok: false; message: string; }>; /** */ invalidateList: () => void; /** * Downloads are joined only while in flight — a double-click sends one * request — but never cached: saving the same artifact twice is a thing a * user may legitimately ask for, and the second ask should reach the server. */ save: (artifactId: string) => Promise<{ ok: true; data: TorukArtifactDownload; } | { ok: false; message: string; }>; bytes: (artifactId: string) => Promise<{ ok: true; data: TorukArtifactDownload; } | { ok: false; message: string; }>; }; /** */ export type ArtifactAccess = ReturnType; /** * Hand a downloaded artifact to the browser as a file save. * * The object URL is revoked on the next frame rather than immediately: the * click has to be dispatched before the URL is torn down, and revoking in the * same tick cancels the download in some browsers. */ export declare function saveArtifactDownload(download: TorukArtifactDownload): void;