#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Merge remote-tracking branch 'origin/main' into SaaS-update
James Bruntond995471a55ef
diff --cc app/common/src/main/java/stirling/software/common/service/InternalApiClient.javaindex c4663c7698,37c110c271..8df2d5e410--- a/app/common/src/main/java/stirling/software/common/service/InternalApiClient.java+++ b/app/common/src/main/java/stirling/software/common/service/InternalApiClient.java@@@ -106,12 -96,18 +106,23 @@@ public class InternalApiClientif (apiKey != null && !apiKey.isEmpty()) {headers.add("X-API-KEY", apiKey);}+ // Tag the sub-step as automation so PAYG bills it under AUTOMATION regardless of which+ // tool-level @RequiresFeature annotation the dispatched controller carries (e.g. an AI-OCR+ // step inside a policy run must bill as AUTOMATION, not AI). Set unconditionally because+ // every caller of this dispatcher is an automation surface by design.+ headers.add(AUTOMATION_HEADER, "true");+ // A no-file ai/tools call (e.g. create-pdf-from-html-agent) sends only string params, so+ // without this RestTemplate would use urlencoded instead of the multipart the controller+ // expects. File-bearing calls get the right multipart content-type from RestTemplate.+ boolean isAiTool = endpointPath.startsWith("/api/v1/ai/tools/");+ boolean hasFilePart =+ body.values().stream()+ .flatMap(java.util.List::stream)+ .anyMatch(v -> v instanceof Resource);+ if (isAiTool && !hasFilePart) {+ headers.setContentType(MediaType.MULTIPART_FORM_DATA);+ }HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);RequestCallback requestCallback = restTemplate.httpEntityCallback(entity, Resource.class);diff --cc engine/pyproject.tomlindex 7bd2fa7bea,2e26756c78..fa972c8495--- a/engine/pyproject.toml+++ b/engine/pyproject.toml@@@ -5,8 -5,9 +5,9 @@@ description = "AI Document Enginerequires-python = ">=3.13"dependencies = ["fastapi>=0.116.0",+ "jinja2>=3.1.0","pgvector>=0.3.6",- "psycopg[binary]>=3.2",+ "psycopg[binary,pool]>=3.2","pydantic>=2.0.0","pydantic-ai>=1.67.0","pydantic-ai-slim[voyageai]>=1.67.0",diff --cc engine/src/stirling/services/runtime.pyindex 06629347ca,bfaa895b20..011eb8aaf2--- a/engine/src/stirling/services/runtime.py+++ b/engine/src/stirling/services/runtime.py@@@ -43,40 -37,12 +43,43 @@@ def _build_anthropic_http_client() -> hhave died in the pool. See ``STIRLING_HTTP_DEBUG`` traces of slice 6on 2026-05-06 for the concrete failure mode this addresses."""- return httpx.AsyncClient(limits=httpx.Limits(max_keepalive_connections=0))+ return httpx.AsyncClient(+ limits=httpx.Limits(max_keepalive_connections=0),+ timeout=httpx.Timeout(connect=30.0, read=300.0, write=30.0, pool=5.0),+ )+class ConcurrencyLimitedModel(WrapperModel):+ """Caps in-flight model API calls with a semaphore shared across the process."""++ def __init__(self, wrapped: Model, semaphore: asyncio.Semaphore) -> None:+ super().__init__(wrapped)+ self._semaphore = semaphore++ async def request(+ self,+ messages: list[ModelMessage],+ model_settings: ModelSettings | None,+ model_request_parameters: ModelRequestParameters,+ ) -> ModelResponse:+ async with self._semaphore:+ return await super().request(messages, model_settings, model_request_parameters)++ @asynccontextmanager+ async def request_stream(+ self,+ messages: list[ModelMessage],+ model_settings: ModelSettings | None,+ model_request_parameters: ModelRequestParameters,+ run_context: RunContext[Any] | None = None,+ ) -> AsyncIterator[StreamedResponse]:+ async with self._semaphore:+ async with super().request_stream(+ messages, model_settings, model_request_parameters, run_context+ ) as response_stream:+ yield response_stream++@dataclass(frozen=True)class AppRuntime:settings: AppSettingsdiff --cc frontend/editor/src/core/components/chat/ChatContext.tsxindex e944bd5c29,ce47df1904..cd8f080722--- a/frontend/editor/src/core/components/chat/ChatContext.tsx+++ b/frontend/editor/src/core/components/chat/ChatContext.tsx@@@ -10,7 -10,11 +10,8 @@@ export function useChat()isLoading: false,progress: null,progressLog: [] as never[],- toggleOpen: () => {},- setOpen: (_open: boolean) => {},sendMessage: async (_content: string) => {},+ cancelMessage: () => {},clearChat: () => {},};}diff --cc frontend/editor/src/proprietary/components/chat/ChatContext.tsxindex c60abe5133,f35ff79fd1..ac3aad9724--- a/frontend/editor/src/proprietary/components/chat/ChatContext.tsx+++ b/frontend/editor/src/proprietary/components/chat/ChatContext.tsx@@@ -360,7 -367,10 +360,8 @@@ interface ChatContextValueprogress: AiWorkflowProgress | null;/** Ordered log of every progress event for the current in-flight request. */progressLog: AiWorkflowProgress[];- toggleOpen: () => void;- setOpen: (open: boolean) => void;sendMessage: (content: string) => Promise<void>;+ cancelMessage: () => void;/** Abort any in-flight request and reset the chat to an empty conversation. */clearChat: () => void;}@@@ -454,6 -465,15 +455,10 @@@ export function ChatProvider({ childre[fileActions, downloadFile],);- const toggleOpen = useCallback(() => dispatch({ type: "TOGGLE_OPEN" }), []);- const setOpen = useCallback(- (open: boolean) => dispatch({ type: "SET_OPEN", open }),- [],- );+ const cancelMessage = useCallback(() => {+ abortRef.current?.abort();+ }, []);+const clearChat = useCallback(() => {abortRef.current?.abort();abortRef.current = null;@@@ -494,17 -514,13 +499,16 @@@formData.append(`conversationHistory[${i}].role`, message.role);formData.append(`conversationHistory[${i}].content`, message.content);});-- const response = await fetch("/api/v1/ai/orchestrate/stream", {- method: "POST",- body: formData,- headers: getAuthHeaders(),- credentials: "include",- signal: controller.signal,- });+ const response = await fetch(+ `${getApiBaseUrl()}/api/v1/ai/orchestrate/stream`,+ {+ method: "POST",+ body: formData,+ headers: await getAuthHeaders(),+ credentials: "include",+ signal: controller.signal,+ },+ );if (!response.ok) {let detail: string | undefined;@@@ -636,7 -652,11 +640,8 @@@isLoading: state.isLoading,progress: state.progress,progressLog: state.progressLog,- toggleOpen,- setOpen,sendMessage,+ cancelMessage,clearChat,}}>