|
68 | 68 | public class AiWorkflowService { |
69 | 69 |
|
70 | 70 | private static final String DOCUMENTS_ENDPOINT = "/api/v1/documents"; |
71 | | - private static final String PDF_TO_MARKDOWN_ENDPOINT = "/api/v1/convert/pdf/markdown"; |
72 | 71 |
|
73 | 72 | private final CustomPDFDocumentFactory pdfDocumentFactory; |
74 | 73 | private final AiEngineClient aiEngineClient; |
@@ -196,7 +195,6 @@ private WorkflowState advance( |
196 | 195 | return switch (response.getOutcome()) { |
197 | 196 | case NEED_CONTENT -> onNeedContent(response, filesById, request, listener); |
198 | 197 | case NEED_INGEST -> onNeedIngest(response, filesById, request, listener); |
199 | | - case CONVERT_MARKDOWN -> onConvertMarkdown(response, filesById, listener); |
200 | 198 | case TOOL_CALL -> onToolCall(response, filesById, listener); |
201 | 199 | case PLAN -> onPlan(response, filesById, request, listener); |
202 | 200 | case ANSWER -> onAnswer(response, filesById, request, listener); |
@@ -333,72 +331,6 @@ private WorkflowState onNeedIngest( |
333 | 331 | return new WorkflowState.Pending(nextRequest); |
334 | 332 | } |
335 | 333 |
|
336 | | - /** |
337 | | - * Deterministically convert each requested PDF to Markdown via the {@code |
338 | | - * /convert/pdf/markdown} endpoint (backed by {@code PdfMarkdownConverter}) and return the |
339 | | - * {@code .md} file(s) as a completed result. No AI resume — the conversion output is the final |
340 | | - * answer. |
341 | | - */ |
342 | | - private WorkflowState onConvertMarkdown( |
343 | | - AiWorkflowResponse response, |
344 | | - Map<String, MultipartFile> filesById, |
345 | | - ProgressListener listener) { |
346 | | - List<AiFile> filesToConvert = response.getFilesToIngest(); |
347 | | - if (filesToConvert == null || filesToConvert.isEmpty()) { |
348 | | - return new WorkflowState.Terminal( |
349 | | - cannotContinue( |
350 | | - "AI engine requested markdown conversion without listing any files.")); |
351 | | - } |
352 | | - |
353 | | - try { |
354 | | - List<Resource> resultFiles = new ArrayList<>(); |
355 | | - List<String> inputNames = new ArrayList<>(); |
356 | | - for (int i = 0; i < filesToConvert.size(); i++) { |
357 | | - AiFile file = filesToConvert.get(i); |
358 | | - MultipartFile multipartFile = filesById.get(file.getId()); |
359 | | - if (multipartFile == null) { |
360 | | - return new WorkflowState.Terminal( |
361 | | - cannotContinue( |
362 | | - "AI engine requested markdown conversion for unknown file: " |
363 | | - + file.getName())); |
364 | | - } |
365 | | - listener.onProgress( |
366 | | - AiWorkflowProgressEvent.executingTool( |
367 | | - PDF_TO_MARKDOWN_ENDPOINT, i + 1, filesToConvert.size())); |
368 | | - Resource input = toResource(multipartFile); |
369 | | - PipelineDefinition definition = |
370 | | - new PipelineDefinition( |
371 | | - "convert-markdown", |
372 | | - List.of(new PipelineStep(PDF_TO_MARKDOWN_ENDPOINT, Map.of())), |
373 | | - null); |
374 | | - PolicyExecutionResult result = |
375 | | - policyExecutor.execute( |
376 | | - definition, |
377 | | - PolicyInputs.of(List.of(input)), |
378 | | - PolicyProgressListener.NOOP); |
379 | | - resultFiles.addAll(result.files()); |
380 | | - inputNames.add(multipartFile.getOriginalFilename()); |
381 | | - } |
382 | | - return new WorkflowState.Terminal( |
383 | | - buildCompletedResponse(null, resultFiles, inputNames, null)); |
384 | | - } catch (InternalApiTimeoutException e) { |
385 | | - log.error("PDF to Markdown conversion timed out: {}", e.getMessage()); |
386 | | - return new WorkflowState.Terminal( |
387 | | - cannotContinue(toolTimeoutMessage(PDF_TO_MARKDOWN_ENDPOINT, e))); |
388 | | - } catch (Exception e) { |
389 | | - AiWorkflowResponse limit = paygLimitResponseOrNull(e); |
390 | | - if (limit != null) { |
391 | | - log.info( |
392 | | - "AI markdown conversion blocked by downstream entitlement gate ({})", |
393 | | - limit.getErrorCode()); |
394 | | - return new WorkflowState.Terminal(limit); |
395 | | - } |
396 | | - log.error("Failed to convert PDF to Markdown: {}", e.getMessage(), e); |
397 | | - return new WorkflowState.Terminal( |
398 | | - cannotContinue(toolFailureMessage(PDF_TO_MARKDOWN_ENDPOINT, e))); |
399 | | - } |
400 | | - } |
401 | | - |
402 | 334 | private Resource toResource(MultipartFile file) throws IOException { |
403 | 335 | TempFile tempFile = tempFileManager.createManagedTempFile("ai-workflow"); |
404 | 336 | file.transferTo(tempFile.getPath()); |
|
0 commit comments