/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import type { QueryOverrides } from './types.js'; import type { LogOptions, RequestOptions, TaskLogChunk } from '@elaraai/e3-api-client'; /** How often a task's log is polled while it changes: every second. */ export declare const LOG_POLL_MS = 1000; /** The longest a task's log waits between polls: 5 s, which it backs off to * while nothing changes. */ export declare const LOG_POLL_BACKOFF_MS = 5000; /** How often a task's log is polled once its execution has ended and the log * is read: every half minute, for another execution of the task. */ export declare const LOG_POLL_ENDED_MS = 30000; /** How a task's log is polled: how often while it changes, and the longest * it waits while nothing does. */ export interface LogPollOptions { /** How often the log is polled while it changes, in milliseconds * (default {@link LOG_POLL_MS}) */ pollMs?: number; /** The longest the log waits between polls while nothing changes, in * milliseconds (default {@link LOG_POLL_BACKOFF_MS}) */ backoffMs?: number; /** How often the log is polled once its execution has ended and the log * is read, in milliseconds (default {@link LOG_POLL_ENDED_MS}) */ endedMs?: number; } /** * A task's log as far as it has been read: one execution's, from its first * byte, at most 10 MB of it. */ export interface TaskLogRead { /** The log's text, as far as it has been read */ data: string; /** The inputs hash of the execution it is the log of */ inputsHash: string; /** The id of the execution it is the log of */ executionId: string; /** The byte the next read starts at */ offset: number; /** The log's size when it was last read */ totalSize: number; /** Whether the last read reached the log's end */ complete: boolean; /** Whether the execution has ended: its log grows no more */ ended: boolean; } /** * Reads a task's log on from where the last read stopped: only what is new, * a 64 KB chunk at a time, up to 10 MB in all. Each poll's first read names no * execution, so it finds the task's current one: when that is another * execution than the one read so far, the log starts over from its first * byte, every read after naming it. Past 10 MB, a poll reads no bytes, and * only finds whether the execution has changed or ended. * * @param read - Reads a chunk of the task's log (the client's `taskLogs`, * bound to the task) * @param stream - The stream * @param held - The log as far as the last poll read it; none for the first * @returns The log as far as it is read now, and whether the poll found * anything new: bytes, another execution, or the execution's end */ export declare function readTaskLogOn(read: (options: LogOptions) => Promise, stream: 'stdout' | 'stderr', held: TaskLogRead | undefined): Promise<{ log: TaskLogRead; changed: boolean; }>; /** * How long a task's log waits before its next poll: `pollMs` after a poll * that found something new, doubling toward `backoffMs` after each that found * nothing, and `endedMs` once the execution has ended and its log is read — * the log grows no more, and a poll looks only for another execution of the * task, as a read made for another reason does, a view shown again. A poll * that finds one starts the polls again. * * @param previous - How long the last poll waited * @param log - The log as the poll left it * @param changed - Whether the poll found anything new * @param pollMs - How often the log is polled while it changes * @param backoffMs - The longest it waits while nothing changes * @param endedMs - How often it is polled once the execution has ended and * the log is read * @returns How long the next waits, in milliseconds */ export declare function nextLogPollMs(previous: number, log: TaskLogRead, changed: boolean, pollMs?: number, backoffMs?: number, endedMs?: number): number; /** What the hook answers: the log's text as far as it is read. */ export interface TaskLogsData { data: string; offset: bigint; size: bigint; totalSize: bigint; complete: boolean; } /** * Polls a task's log: only what is new each time, starting over when the * task's current execution changes, backing off while nothing does, and every * half minute once the execution has ended and its log is read, for another * execution ({@link readTaskLogOn}, {@link nextLogPollMs}). Each poll makes * one request attempt: its next poll is its retry. A log the view left — the * other stream, another task — is kept as far as it was read, so a view that * comes back to it reads on from there, as react-query shows what it read. * * @param apiUrl - Base URL of the e3 API server * @param repo - Repository name * @param workspace - Workspace name; nothing is read while `null` * @param taskName - The task; nothing is read while `null` * @param stream - The stream * @param requestOptions - The requests' token and fetch * @param queryOptions - react-query overrides * @param poll - How often the log is polled while it changes, the longest it * waits while nothing does, and how often it is polled once its execution * has ended * @returns The query of the log's text as far as it is read */ export declare function useTaskLogs(apiUrl: string, repo: string, workspace: string | null, taskName: string | null, stream?: 'stdout' | 'stderr', requestOptions?: RequestOptions, queryOptions?: QueryOverrides, poll?: LogPollOptions): import("@tanstack/react-query").UseQueryResult; //# sourceMappingURL=useTaskLogsHook.d.ts.map