/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { IExecuteContext, TaskConfig, TaskEntitlements } from "@workglow/task-graph"; import { CreateWorkflow, Task } from "@workglow/task-graph"; import type { DataPortSchema, FromSchema } from "@workglow/util/schema"; import type { FetchUrlResponseType, FetchUrlTaskOutput } from "./FetchUrlTask"; declare const inputSchema: { readonly type: "object"; readonly properties: { readonly url: { readonly type: "string"; readonly title: "URL"; readonly description: "URL to load document from (http://, https://)"; readonly format: "uri"; }; readonly format: { readonly type: "string"; readonly enum: readonly ["text", "markdown", "json", "csv", "pdf", "image", "html", "auto"]; readonly title: "Format"; readonly description: "File format (auto-detected from URL if 'auto')"; readonly default: "auto"; }; }; readonly required: readonly ["url"]; readonly additionalProperties: false; }; declare const outputSchema: { readonly type: "object"; readonly properties: { readonly text: { readonly type: "string"; readonly title: "Text"; readonly description: "Text content (for text, markdown, html formats)"; }; readonly json: { readonly title: "JSON"; readonly description: "Parsed JSON object or array"; }; readonly csv: { readonly type: "array"; readonly title: "CSV"; readonly description: "Parsed CSV data as array of objects"; }; readonly image: { readonly type: "string"; readonly title: "Image"; readonly description: "Base64 data URL for image files"; readonly format: "image:data-uri"; }; readonly pdf: { readonly type: "string"; readonly title: "PDF"; readonly description: "Base64 data URL for PDF files"; }; readonly frontmatter: { readonly type: "object"; readonly title: "Frontmatter"; readonly description: "Parsed YAML frontmatter from markdown/MDX files"; }; readonly metadata: { readonly type: "object"; readonly properties: { readonly url: { readonly type: "string"; }; readonly format: { readonly type: "string"; }; readonly size: { readonly type: "number"; }; readonly title: { readonly type: "string"; }; readonly mimeType: { readonly type: "string"; }; }; readonly additionalProperties: false; readonly title: "Metadata"; readonly description: "File metadata"; }; }; readonly required: readonly ["metadata"]; readonly additionalProperties: false; }; export type FileLoaderTaskInput = FromSchema; export type FileLoaderTaskOutput = FromSchema; /** * Task for loading documents from URLs (including file:// URLs). * Works in all environments (browser, Node.js, Bun) by using fetch API. * For server-only filesystem path access, see FileLoaderServerTask. */ export declare class FileLoaderTask extends Task { static type: string; static category: string; static title: string; static description: string; static cacheable: boolean; static hasDynamicEntitlements: boolean; /** * The owned `FetchUrlTask` does the network access, but an owned child is * created inside `execute()` and so is absent from the graph-start snapshot * `computeGraphEntitlements` takes over `graph.getTasks()`. Declaring the * fetch's entitlements here is what puts them in front of the enforcer. */ static entitlements(): TaskEntitlements; entitlements(): TaskEntitlements; static inputSchema(): DataPortSchema; static outputSchema(): DataPortSchema; execute(input: FileLoaderTaskInput, context: IExecuteContext): Promise; protected parseJsonContent(content: string): unknown; protected parseCsvContent(content: string): Promise>>; /** * Parse YAML frontmatter from markdown/MDX content. * Supports common frontmatter patterns: strings, numbers, booleans, arrays, and nested objects. */ protected parseFrontmatter(content: string): { readonly frontmatter: Record | undefined; readonly body: string; }; private parseSimpleYaml; private parseYamlLine; private parseYamlValue; protected parseResponse(response: FetchUrlTaskOutput, url: string, detectedFormat: "text" | "markdown" | "json" | "csv" | "pdf" | "image" | "html"): Promise<{ readonly text: string | undefined; readonly json: unknown; readonly csv: Array> | undefined; readonly image: string | undefined; readonly pdf: string | undefined; readonly frontmatter: Record | undefined; readonly size: number; readonly mimeType: string; }>; protected detectResponseType(detectedFormat: string): FetchUrlResponseType; protected detectFormat(url: string, format: "text" | "markdown" | "json" | "csv" | "pdf" | "image" | "html" | "auto"): "text" | "markdown" | "json" | "csv" | "pdf" | "image" | "html"; protected getImageMimeType(url: string): string; protected blobToBase64DataURL(blob: Blob, mimeType: string): Promise; } /** * Config for both builds. `roots` is declared here rather than beside the * server subclass because a `declare module` augmentation must state one type * across every file that contributes it, and both files augment `Workflow` * with `fileLoader`. */ export interface FileLoaderTaskConfig extends TaskConfig { /** * Directories a local path must resolve inside, checked after symlinks are * resolved. Omitted means `[process.cwd()]`, NOT unrestricted — the * `filesystem:read` entitlement is only consulted when the embedder runs * with `enforceEntitlements` and a registered enforcer, so it cannot stand * in as the default fence. State {@link allowAnyRoot} to opt out. * * Honored only by the server build — the cross-platform class reaches * http(s) through `FetchUrlTask` and touches no filesystem. */ readonly roots?: readonly string[] | undefined; /** * Read any path the process can open, skipping containment entirely. Only * the literal `true` does so, and it is never implied by leaving `roots` * unset. */ readonly allowAnyRoot?: boolean | undefined; } export declare const fileLoader: (input: FileLoaderTaskInput, config?: FileLoaderTaskConfig) => Promise<{ csv?: unknown[] | undefined; frontmatter?: { [x: string]: unknown; } | undefined; image?: string | undefined; json?: unknown; metadata: { format?: string | undefined; mimeType?: string | undefined; size?: number | undefined; title?: string | undefined; url?: string | undefined; }; pdf?: string | undefined; text?: string | undefined; }>; declare module "@workglow/task-graph" { interface Workflow { fileLoader: CreateWorkflow; } } export {};