@@ -10,6 +10,7 @@ import {
1010 writeResponseToFile ,
1111 buildFormData ,
1212 assertOutputDiffersFromInput ,
13+ deriveOutputPath ,
1314} from '../files.js' ;
1415
1516export const convertToPdfTool : ToolDefinition = {
@@ -19,15 +20,15 @@ export const convertToPdfTool: ToolDefinition = {
1920 'Supports page ranges, password-protected files, and HTML layout options.' ,
2021 parameters : {
2122 type : 'object' ,
22- required : [ 'filePath' , 'outputPath' ] ,
23+ required : [ 'filePath' ] ,
2324 properties : {
2425 filePath : {
2526 type : 'string' ,
2627 description : 'Path to input file (DOCX, XLSX, PPTX, HTML, image, or PDF)' ,
2728 } ,
2829 outputPath : {
2930 type : 'string' ,
30- description : 'Path for output PDF' ,
31+ description : 'Path for output PDF. If omitted, derives from input filename (e.g. report.docx → report.pdf) ' ,
3132 } ,
3233 password : {
3334 type : 'string' ,
@@ -70,7 +71,8 @@ export const convertToPdfTool: ToolDefinition = {
7071
7172 async execute ( args , ctx ) : Promise < ToolResponse > {
7273 try {
73- assertOutputDiffersFromInput ( args . filePath , args . outputPath , ctx . sandboxDir ) ;
74+ const outputPath = args . outputPath || deriveOutputPath ( args . filePath , 'pdf' ) ;
75+ assertOutputDiffersFromInput ( args . filePath , outputPath , ctx . sandboxDir ) ;
7476
7577 const fileRef = readFileReference ( args . filePath , ctx . sandboxDir ) ;
7678 const fileRefs = new Map < string , FileReference > ( [ [ fileRef . key , fileRef ] ] ) ;
@@ -91,9 +93,9 @@ export const convertToPdfTool: ToolDefinition = {
9193 const body = buildFormData ( instructions , fileRefs ) ;
9294 const response = await ctx . client . post ( 'build' , body ) ;
9395
94- const outputPath = writeResponseToFile (
96+ const writtenPath = writeResponseToFile (
9597 response . data as ArrayBuffer ,
96- args . outputPath ,
98+ outputPath ,
9799 ctx . sandboxDir ,
98100 ) ;
99101
@@ -105,7 +107,7 @@ export const convertToPdfTool: ToolDefinition = {
105107
106108 return {
107109 success : true ,
108- output : `PDF created at ${ outputPath } ` ,
110+ output : `PDF created at ${ writtenPath } ` ,
109111 credits_used : response . creditsUsed ?? undefined ,
110112 } ;
111113 } catch ( e ) {
0 commit comments