openclaw/extensions/document-extract/document-extractor.worker.ts
Peter Steinberger d72a144e7b
improve: keep image and PDF processing responsive (#146094)
* fix: bound concurrent compute work and pending worker inputs

* fix: supply the host response budget in worker checkpoint tests

* fix: preserve prepared catalog ownership under admission pressure

* improve: keep image and PDF processing responsive

* fix: register PDF worker declarations in build fixtures

* test: rebalance SQLite checks into the state shard

* fix: resolve workers in standalone plugin packages

* docs: separate worker entrypoint guidance
2026-09-12 10:58:14 -07:00

35 lines
1.2 KiB
TypeScript

import type {
DocumentExtractionRequest,
DocumentExtractionResult,
} from "openclaw/plugin-sdk/document-extractor";
import { serveWorkerTasks } from "openclaw/plugin-sdk/process-runtime";
import { extractPdfContent } from "./document-extractor.runtime.js";
export type DocumentExtractorWorkerRequest = Omit<
DocumentExtractionRequest,
"signal" | "onImageExtractionError"
>;
export type DocumentExtractorWorkerReply = { imageErrors: Error[] } & (
| { status: "ok"; result: DocumentExtractionResult }
| { status: "failed"; error: Error }
);
serveWorkerTasks<DocumentExtractorWorkerReply>(async (input) => {
// SAFETY: The plugin-owned pool sends this private request shape; both sides are built together.
const request = input as DocumentExtractorWorkerRequest;
const imageErrors: Error[] = [];
try {
const result = await extractPdfContent({
...request,
onImageExtractionError: (error) =>
imageErrors.push(error instanceof Error ? error : new Error(String(error))),
});
return { status: "ok", result, imageErrors };
} catch (error) {
return {
status: "failed",
error: error instanceof Error ? error : new Error(String(error)),
imageErrors,
};
}
});