refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -2,7 +2,6 @@ import { useLayoutEffect } from "react";
|
||||
import { useMediaQuery } from "@/hooks/useMediaQuery";
|
||||
import { isNativeRuntime } from "@/lib/runtime";
|
||||
|
||||
/** One viewport owner for navigation, workbench composers and ordinary threads. */
|
||||
export function useAppViewport() {
|
||||
const touch = useMediaQuery("(any-pointer: coarse)");
|
||||
useLayoutEffect(() => {
|
||||
|
||||
@@ -4,12 +4,6 @@ import type { LocalAttachment } from "../../../packages/client-events/attachment
|
||||
import { encodeImage, type EncodeFailure } from "@/lib/imageEncode";
|
||||
import type { WebUIIngressLimits } from "@/lib/types";
|
||||
|
||||
/** Lifecycle stages of one attachment:
|
||||
*
|
||||
* - ``encoding`` — posted to the Worker / read from disk; chip shows a spinner
|
||||
* - ``ready`` — ``dataUrl`` available; safe to submit
|
||||
* - ``error`` — validation / decode failure; chip shows inline error
|
||||
*/
|
||||
type AttachmentStatus = "encoding" | "ready" | "error";
|
||||
export type AttachmentKind = "image" | "video" | "file";
|
||||
|
||||
@@ -18,17 +12,16 @@ interface AttachedAttachment {
|
||||
kind: AttachmentKind;
|
||||
file: Pick<File, "name" | "size" | "type">;
|
||||
local?: LocalAttachment;
|
||||
/** Optimistic ``blob:`` preview URL; revoked on ``remove`` / ``clear`` /
|
||||
* unmount. */
|
||||
/** Preview URL; owned ``blob:`` URLs are revoked on removal, clearing or unmount. */
|
||||
previewUrl?: string;
|
||||
status: AttachmentStatus;
|
||||
/** Populated when ``status === "ready"``. */
|
||||
/** Encoded payload; ready local attachments use ``local`` instead. */
|
||||
dataUrl?: string;
|
||||
/** Size of the final encoded payload (base64 bytes decoded). */
|
||||
encodedBytes?: number;
|
||||
/** Whether the Worker re-encoded the image to hit the size budget. */
|
||||
/** Whether image bytes were re-encoded to meet the size budget. */
|
||||
normalized?: boolean;
|
||||
/** Human-readable validation / encoding error when ``status === "error"``. */
|
||||
/** Machine-readable error code for callers to localize when ``status === "error"``. */
|
||||
error?: AttachmentError;
|
||||
}
|
||||
|
||||
@@ -47,12 +40,12 @@ export type RestoredReadyImage = RestoredReadyAttachment;
|
||||
*
|
||||
* Callers localize these via the ``composer.imageRejected.*`` i18n table. */
|
||||
export type AttachmentError =
|
||||
| "unsupported_type" // server whitelist excludes this MIME
|
||||
| "empty_file" // attachments must contain bytes
|
||||
| "unsupported_type"
|
||||
| "empty_file"
|
||||
| "too_many_attachments" // non-video per-message cap reached before enqueue
|
||||
| "too_many_videos" // video slot is already occupied
|
||||
| "total_too_large" // decoded attachments exceed the business-policy total
|
||||
| "magic_mismatch" // extension lies about the real content
|
||||
| "magic_mismatch" // bytes lack a supported image signature
|
||||
| "decode_failed" // Worker couldn't decode / re-encode
|
||||
| "too_large" // even after normalization we exceed the budget
|
||||
| "io"; // file read failed at the browser layer
|
||||
@@ -231,17 +224,15 @@ export interface UseAttachedImagesApi {
|
||||
};
|
||||
addLocal: (attachment: LocalAttachment, options?: { restoringDraft: boolean }) => AttachmentCountError | null;
|
||||
remove: (id: string) => { nextFocusId: string | null };
|
||||
/** Revoke every staged blob URL and drop all attachments. Called after a
|
||||
* successful submit — the optimistic bubble holds onto an independent
|
||||
* ``data:`` URL so tearing down blob previews here is safe. */
|
||||
/** Revoke owned blob previews and clear staged entries; submitted attachments
|
||||
* retain independent data URLs or local references. */
|
||||
clear: () => void;
|
||||
/** Restore already-encoded attachments, e.g. a queued composer draft moving
|
||||
* back into the input. These entries are immediately sendable and use image
|
||||
* ``data:`` URLs as stable previews. */
|
||||
/** Restore ready encoded payloads or local references, preserving draft overflow
|
||||
* for the user to resolve before sending. */
|
||||
restoreReadyImages: (images: RestoredReadyAttachment[]) => void;
|
||||
/** ``true`` when at least one attachment is still encoding — Send should wait. */
|
||||
encoding: boolean;
|
||||
/** ``true`` when we've hit ``MAX_ATTACHMENTS_PER_MESSAGE``. */
|
||||
/** ``true`` when both the non-video and video attachment quotas are full. */
|
||||
full: boolean;
|
||||
}
|
||||
|
||||
@@ -249,14 +240,6 @@ interface UseAttachedImagesOptions {
|
||||
ingressLimits?: WebUIIngressLimits | null;
|
||||
}
|
||||
|
||||
/** Manage the lifecycle of attachments in the Composer.
|
||||
*
|
||||
* Responsibilities in one place:
|
||||
* - validation (MIME whitelist, count cap)
|
||||
* - blob URL creation + revocation
|
||||
* - Worker orchestration
|
||||
* - focus bookkeeping so keyboard delete doesn't strand the user
|
||||
*/
|
||||
export function useAttachedImages({
|
||||
ingressLimits = null,
|
||||
}: UseAttachedImagesOptions = {}): UseAttachedImagesApi {
|
||||
@@ -410,7 +393,6 @@ export function useAttachedImages({
|
||||
}
|
||||
const next = [...prev.slice(0, idx), ...prev.slice(idx + 1)];
|
||||
imagesRef.current = next;
|
||||
// Prefer moving focus to the chip at the same index, else previous.
|
||||
const candidate = next[idx] ?? next[idx - 1];
|
||||
nextFocusId = candidate?.id ?? null;
|
||||
return next;
|
||||
|
||||
@@ -26,7 +26,6 @@ function extractImageFilesFromPaste(
|
||||
return files;
|
||||
}
|
||||
|
||||
/** Extract dropped attachment files, mirroring ``extractImageFilesFromPaste``. */
|
||||
function extractImageFilesFromDrop(
|
||||
event: DragEvent | React.DragEvent,
|
||||
): File[] {
|
||||
@@ -41,7 +40,6 @@ function extractImageFilesFromDrop(
|
||||
}
|
||||
|
||||
export interface UseClipboardAndDropApi {
|
||||
/** Whether a drag is currently hovering the drop zone (toggle dragover UI). */
|
||||
isDragging: boolean;
|
||||
onPaste: (
|
||||
event: React.ClipboardEvent,
|
||||
|
||||
@@ -49,7 +49,6 @@ const VISIBLE_STREAM_FLUSH_INTERVAL_MS = 50;
|
||||
const EMPTY_INITIAL_MESSAGES: UIMessage[] = [];
|
||||
const EMPTY_COMPLETED_TURN_IDS: readonly string[] = [];
|
||||
|
||||
/** Own the received transcript, accepting fetched pages and live events together. */
|
||||
/** Payload passed to ``send`` when the user attaches one or more files.
|
||||
*
|
||||
* ``media`` is handed to the wire client verbatim; ``preview`` powers the
|
||||
@@ -153,7 +152,6 @@ export function useNanobotStream(
|
||||
isStreaming: boolean;
|
||||
/** Unix epoch seconds when the current user turn started (WebSocket ``goal_status``). */
|
||||
runStartedAt: number | null;
|
||||
/** Transient model retry state for the active turn. */
|
||||
retryStatus: RetryStatus | null;
|
||||
/** Latest sustained goal for this ``chatId`` (``goal_state`` WS events). */
|
||||
goalState: GoalStateWsPayload | undefined;
|
||||
@@ -174,8 +172,6 @@ export function useNanobotStream(
|
||||
/** Latest transport-level fault raised since the last ``dismissStreamError``.
|
||||
* ``null`` when there is nothing to show. */
|
||||
streamError: StreamError | null;
|
||||
/** Clear the current ``streamError`` (e.g. after the user dismisses the
|
||||
* notification or starts a fresh action). */
|
||||
dismissStreamError: () => void;
|
||||
} {
|
||||
const { client, getToken } = useClient();
|
||||
@@ -210,7 +206,6 @@ export function useNanobotStream(
|
||||
setHistoryState(transcriptRef.current.paging);
|
||||
}, []);
|
||||
const [messageScope, setMessageScope] = useState({ chatId, historyKey, client });
|
||||
/** If history ends in unfinished agent activity, keep the loading spinner alive. */
|
||||
const initialStreaming = useMemo(() => {
|
||||
if (completedTurnIds.length === 0) return hasPendingAgentActivity(initialMessages);
|
||||
const completedInitialTurns = new Set(completedTurnIds);
|
||||
@@ -502,7 +497,6 @@ export function useNanobotStream(
|
||||
setGoalState(chatId ? client.getGoalState(chatId) : undefined);
|
||||
setRecoveryState(null);
|
||||
clearPendingStreamWork();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [chatId, client, historyKey, clearActivitySegment, clearPendingStreamWork, setMessages]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -4,7 +4,6 @@ function pageIsVisible(): boolean {
|
||||
return typeof document === "undefined" || document.visibilityState !== "hidden";
|
||||
}
|
||||
|
||||
/** Keep background tabs quiet while resuming work immediately on return. */
|
||||
export function usePageVisibility(): boolean {
|
||||
const [visible, setVisible] = useState(pageIsVisible);
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import type {
|
||||
|
||||
const CHAT_CREATE_TIMEOUT_MS = 60_000;
|
||||
|
||||
/** Sidebar state: fetches the full session list and exposes create / delete actions. */
|
||||
export function useSessions(): {
|
||||
sessions: ChatSummary[];
|
||||
loading: boolean;
|
||||
@@ -206,7 +205,6 @@ export function useSessions(): {
|
||||
};
|
||||
}
|
||||
|
||||
/** Read-only history view backed by the conversation owner. */
|
||||
export function useSessionHistory(key: string | null) {
|
||||
const { messages, history, refreshHistory, loadOlder } = useNanobotStream(
|
||||
null, undefined, false, undefined, undefined, undefined, { key },
|
||||
|
||||
@@ -416,16 +416,12 @@ async function convertBlobToWav(blob: Blob): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an AudioBuffer as a 16-bit PCM WAV Blob.
|
||||
*/
|
||||
function audioBufferToWav(buffer: AudioBuffer): Blob {
|
||||
const numChannels = buffer.numberOfChannels;
|
||||
const sampleRate = buffer.sampleRate;
|
||||
const format = 1; // PCM
|
||||
const bitsPerSample = 16;
|
||||
|
||||
// Interleave channels
|
||||
const channels: Float32Array[] = [];
|
||||
for (let ch = 0; ch < numChannels; ch++) {
|
||||
channels.push(buffer.getChannelData(ch));
|
||||
@@ -450,12 +446,10 @@ function audioBufferToWav(buffer: AudioBuffer): Blob {
|
||||
const buffer2 = new ArrayBuffer(totalSize);
|
||||
const view = new DataView(buffer2);
|
||||
|
||||
// RIFF header
|
||||
writeString(view, 0, "RIFF");
|
||||
view.setUint32(4, totalSize - 8, true);
|
||||
writeString(view, 8, "WAVE");
|
||||
|
||||
// fmt sub-chunk
|
||||
writeString(view, 12, "fmt ");
|
||||
view.setUint32(16, 16, true); // sub-chunk size
|
||||
view.setUint16(20, format, true);
|
||||
@@ -465,7 +459,6 @@ function audioBufferToWav(buffer: AudioBuffer): Blob {
|
||||
view.setUint16(32, blockAlign, true);
|
||||
view.setUint16(34, bitsPerSample, true);
|
||||
|
||||
// data sub-chunk
|
||||
writeString(view, 36, "data");
|
||||
view.setUint32(40, dataSize, true);
|
||||
|
||||
|
||||
Reference in new issue
Block a user