@uploadista/flow-documents-nodes 0.0.16 → 0.0.17-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -12
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +12 -78
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +47 -113
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/convert-to-markdown-node.ts +2 -0
- package/src/extract-text-node.ts +3 -3
- package/src/merge-pdf-node.ts +9 -5
- package/src/ocr-node.ts +12 -21
- package/src/split-pdf-node.ts +9 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @uploadista/flow-documents-nodes@0.0.
|
|
3
|
+
> @uploadista/flow-documents-nodes@0.0.17-beta.1 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/documents/nodes
|
|
4
4
|
> tsdown
|
|
5
5
|
|
|
6
6
|
[34mℹ[39m tsdown [2mv0.16.5[22m powered by rolldown [2mv1.0.0-beta.50[22m
|
|
@@ -9,25 +9,25 @@
|
|
|
9
9
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
10
10
|
[34mℹ[39m Build start
|
|
11
11
|
[34mℹ[39m Cleaning 19 files
|
|
12
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m10.
|
|
12
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mindex.cjs[22m [2m10.34 kB[22m [2m│ gzip: 2.49 kB[22m
|
|
13
13
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[1mtypes/index.cjs[22m [2m 0.25 kB[22m [2m│ gzip: 0.15 kB[22m
|
|
14
14
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mtypes-CdmvDfq8.cjs [2m 1.09 kB[22m [2m│ gzip: 0.36 kB[22m
|
|
15
|
-
[34mℹ[39m [33m[CJS][39m 3 files, total: 11.
|
|
16
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 9.
|
|
15
|
+
[34mℹ[39m [33m[CJS][39m 3 files, total: 11.69 kB
|
|
16
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mindex.mjs[22m [2m 9.12 kB[22m [2m│ gzip: 2.57 kB[22m
|
|
17
17
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[1mtypes/index.mjs[22m [2m 0.25 kB[22m [2m│ gzip: 0.17 kB[22m
|
|
18
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [2m33.
|
|
19
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.d.mts.map [2m 6.
|
|
18
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.mjs.map [2m33.43 kB[22m [2m│ gzip: 5.78 kB[22m
|
|
19
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex.d.mts.map [2m 6.65 kB[22m [2m│ gzip: 0.98 kB[22m
|
|
20
20
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mtypes-rDFmPO7S.mjs.map [2m 2.57 kB[22m [2m│ gzip: 0.77 kB[22m
|
|
21
21
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mindex-aD9vy0kH.d.mts.map [2m 1.02 kB[22m [2m│ gzip: 0.46 kB[22m
|
|
22
22
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22mtypes-rDFmPO7S.mjs [2m 0.70 kB[22m [2m│ gzip: 0.35 kB[22m
|
|
23
|
-
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [
|
|
23
|
+
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m31.74 kB[22m [2m│ gzip: 1.74 kB[22m
|
|
24
24
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32m[1mtypes/index.d.mts[22m[39m [2m 0.63 kB[22m [2m│ gzip: 0.24 kB[22m
|
|
25
25
|
[34mℹ[39m [34m[ESM][39m [2mdist/[22m[32mindex-aD9vy0kH.d.mts[39m [2m 2.33 kB[22m [2m│ gzip: 0.64 kB[22m
|
|
26
|
-
[34mℹ[39m [34m[ESM][39m 10 files, total:
|
|
27
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.d.cts.map [2m 6.
|
|
26
|
+
[34mℹ[39m [34m[ESM][39m 10 files, total: 88.45 kB
|
|
27
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex.d.cts.map [2m 6.65 kB[22m [2m│ gzip: 0.98 kB[22m
|
|
28
28
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22mindex-DN0piYEv.d.cts.map [2m 1.02 kB[22m [2m│ gzip: 0.46 kB[22m
|
|
29
|
-
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [
|
|
29
|
+
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m31.74 kB[22m [2m│ gzip: 1.73 kB[22m
|
|
30
30
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32m[1mtypes/index.d.cts[22m[39m [2m 0.63 kB[22m [2m│ gzip: 0.23 kB[22m
|
|
31
31
|
[34mℹ[39m [33m[CJS][39m [2mdist/[22m[32mindex-DN0piYEv.d.cts[39m [2m 2.33 kB[22m [2m│ gzip: 0.64 kB[22m
|
|
32
|
-
[34mℹ[39m [33m[CJS][39m 5 files, total:
|
|
33
|
-
[32m✔[39m Build complete in [
|
|
32
|
+
[34mℹ[39m [33m[CJS][39m 5 files, total: 42.37 kB
|
|
33
|
+
[32m✔[39m Build complete in [32m8101ms[39m
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const e=require(`./types-CdmvDfq8.cjs`);let t=require(`@uploadista/core/errors`),n=require(`@uploadista/core/flow`),r=require(`@uploadista/core/types`),i=require(`@uploadista/core/upload`),a=require(`effect`),o=require(`zod`);function s(e,o={}){return a.Effect.gen(function*(){let s=yield*n.DocumentPlugin,c=yield*n.DocumentAiPlugin,l=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Convert to Markdown`,description:`Convert documents to Markdown format (intelligently uses OCR if needed)`,type:n.NodeType.process,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:u,clientId:d})=>a.Effect.gen(function*(){let f={flowId:i,nodeId:e,jobId:u};yield*a.Effect.logInfo(`Converting file ${r.id} to Markdown`);let p=yield*l.read(r.id,d),m=yield*s.extractText(p).pipe(a.Effect.either),h,g;if(a.Either.isRight(m)&&m.right.trim().length>0){let e=m.right;yield*a.Effect.logInfo(`Successfully extracted ${e.length} characters from searchable PDF`),h=e.split(`
|
|
1
|
+
const e=require(`./types-CdmvDfq8.cjs`);let t=require(`@uploadista/core/errors`),n=require(`@uploadista/core/flow`),r=require(`@uploadista/core/types`),i=require(`@uploadista/core/upload`),a=require(`effect`),o=require(`zod`);function s(e,o={}){return a.Effect.gen(function*(){let s=yield*n.DocumentPlugin,c=yield*n.DocumentAiPlugin,l=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Convert to Markdown`,description:`Convert documents to Markdown format (intelligently uses OCR if needed)`,type:n.NodeType.process,nodeTypeId:n.STORAGE_OUTPUT_TYPE_ID,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:u,clientId:d})=>a.Effect.gen(function*(){let f={flowId:i,nodeId:e,jobId:u};yield*a.Effect.logInfo(`Converting file ${r.id} to Markdown`);let p=yield*l.read(r.id,d),m=yield*s.extractText(p).pipe(a.Effect.either),h,g;if(a.Either.isRight(m)&&m.right.trim().length>0){let e=m.right;yield*a.Effect.logInfo(`Successfully extracted ${e.length} characters from searchable PDF`),h=e.split(`
|
|
2
2
|
|
|
3
3
|
`).map(e=>e.trim()).filter(e=>e.length>0).join(`
|
|
4
4
|
|
|
5
|
-
`),g=`text`,yield*a.Effect.logInfo(`Converted text to Markdown (${h.length} characters)`)}else{yield*a.Effect.logInfo(`Text extraction failed or returned empty, falling back to OCR`);let e=r.url;if(!e)return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for OCR-based markdown conversion`}).toEffect();let n={clientId:d,credentialId:o.credentialId};h=(yield*c.performOCR(e,{taskType:`convertToMarkdown`,resolution:o.resolution||`gundam`},n).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to perform OCR`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to perform OCR for markdown conversion`}).toEffect()})))).extractedText,g=`ocr`,yield*a.Effect.logInfo(`Successfully converted scanned document to Markdown using OCR (${h.length} characters)`)}let{metadata:_}=(0,n.resolveUploadMetadata)(r.metadata),v={...r.metadata,..._,markdown:h,markdownSource:g};return yield*a.Effect.logInfo(`Successfully converted file ${r.id} to Markdown via ${g}`),(0,n.completeNodeExecution)({...r,metadata:v,flow:f})})})})}function c(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Describe Document`,description:`Extract metadata from PDF documents`,type:n.NodeType.process,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};yield*a.Effect.logInfo(`Extracting metadata from PDF file ${r.id}`);let d=yield*s.read(r.id,l),f=yield*o.getMetadata(d).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to extract metadata`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract metadata`}).toEffect()}))),{metadata:p}=(0,n.resolveUploadMetadata)(r.metadata),m={...r.metadata,...p,pageCount:f.pageCount,format:f.format,...f.author&&{author:f.author},...f.title&&{title:f.title},...f.subject&&{subject:f.subject},...f.creator&&{creator:f.creator},...f.creationDate&&{creationDate:f.creationDate},...f.modifiedDate&&{modifiedDate:f.modifiedDate},fileSize:f.fileSize};return yield*a.Effect.logInfo(`Successfully extracted metadata from file ${r.id}: ${f.pageCount} pages`),(0,n.completeNodeExecution)({...r,metadata:m,flow:u})})})})}function l(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Extract Text`,description:`Extract text from searchable PDF documents`,type:n.NodeType.process,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};yield*a.Effect.logInfo(`Extracting text from PDF file ${r.id}`);let d=yield*s.read(r.id,l),f=yield*o.extractText(d).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to extract text`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract text`}).toEffect()}))),{metadata:p}=(0,n.resolveUploadMetadata)(r.metadata),m={...r.metadata,...p,extractedText:f};return!f||f.trim().length===0?yield*a.Effect.logWarning(`No text extracted from file ${r.id}. This might be a scanned document. Consider using the OCR node instead.`):yield*a.Effect.logInfo(`Successfully extracted ${f.length} characters from file ${r.id}`),(0,n.completeNodeExecution)({...r,metadata:m,flow:u})})})})}const u=o.z.array(r.uploadFileSchema);function d(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Merge PDFs`,description:`Merge multiple PDF documents into one`,type:n.NodeType.process,inputSchema:u,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};if(!Array.isArray(r))return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`Merge PDF node requires an array of files from a Merge utility node`}).toEffect();if(r.length===0)return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`At least one PDF file is required for merging`}).toEffect();let d=[],f=0;for(let e of r){let t=yield*s.read(e.id,l);d.push(t);let r=(0,n.resolveUploadMetadata)(e.metadata).metadata;r?.pageCount&&typeof r.pageCount==`number`&&(f+=r.pageCount)}yield*a.Effect.logInfo(`Merging ${r.length} PDF files`);let p=yield*o.mergePdfs({pdfs:d}).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to merge PDFs`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to merge PDFs`}).toEffect()}))),m=r[0],{metadata:h}=(0,n.resolveUploadMetadata)(m.metadata),g=new ReadableStream({start(e){e.enqueue(p),e.close()}}),_=yield*s.upload({storageId:m.storage.id,size:p.byteLength,type:`application/pdf`,fileName:`merged-${r.length}-documents.pdf`,lastModified:0,metadata:JSON.stringify({...h,pageCount:f,mergedFrom:r.length}),flow:u},l,g),v={...h,pageCount:f,mergedFrom:r.length,fileName:`merged-${r.length}-documents.pdf`};return yield*a.Effect.logInfo(`Successfully merged ${r.length} PDFs into one document with ${f} pages`),(0,n.completeNodeExecution)({..._,metadata:v})})})})}function f(e,i){return a.Effect.gen(function*(){let o=yield*n.DocumentAiPlugin;return yield*(0,n.createFlowNode)({id:e,name:`OCR`,description:`Extract text from scanned documents using AI`,type:n.NodeType.process,inputSchema:r.uploadFileSchema,outputSchema:
|
|
5
|
+
`),g=`text`,yield*a.Effect.logInfo(`Converted text to Markdown (${h.length} characters)`)}else{yield*a.Effect.logInfo(`Text extraction failed or returned empty, falling back to OCR`);let e=r.url;if(!e)return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for OCR-based markdown conversion`}).toEffect();let n={clientId:d,credentialId:o.credentialId};h=(yield*c.performOCR(e,{taskType:`convertToMarkdown`,resolution:o.resolution||`gundam`},n).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to perform OCR`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to perform OCR for markdown conversion`}).toEffect()})))).extractedText,g=`ocr`,yield*a.Effect.logInfo(`Successfully converted scanned document to Markdown using OCR (${h.length} characters)`)}let{metadata:_}=(0,n.resolveUploadMetadata)(r.metadata),v={...r.metadata,..._,markdown:h,markdownSource:g};return yield*a.Effect.logInfo(`Successfully converted file ${r.id} to Markdown via ${g}`),(0,n.completeNodeExecution)({...r,metadata:v,flow:f})})})})}function c(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Describe Document`,description:`Extract metadata from PDF documents`,type:n.NodeType.process,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};yield*a.Effect.logInfo(`Extracting metadata from PDF file ${r.id}`);let d=yield*s.read(r.id,l),f=yield*o.getMetadata(d).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to extract metadata`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract metadata`}).toEffect()}))),{metadata:p}=(0,n.resolveUploadMetadata)(r.metadata),m={...r.metadata,...p,pageCount:f.pageCount,format:f.format,...f.author&&{author:f.author},...f.title&&{title:f.title},...f.subject&&{subject:f.subject},...f.creator&&{creator:f.creator},...f.creationDate&&{creationDate:f.creationDate},...f.modifiedDate&&{modifiedDate:f.modifiedDate},fileSize:f.fileSize};return yield*a.Effect.logInfo(`Successfully extracted metadata from file ${r.id}: ${f.pageCount} pages`),(0,n.completeNodeExecution)({...r,metadata:m,flow:u})})})})}function l(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Extract Text`,description:`Extract text from searchable PDF documents`,type:n.NodeType.process,nodeTypeId:n.STORAGE_OUTPUT_TYPE_ID,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};yield*a.Effect.logInfo(`Extracting text from PDF file ${r.id}`);let d=yield*s.read(r.id,l),f=yield*o.extractText(d).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to extract text`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract text`}).toEffect()}))),{metadata:p}=(0,n.resolveUploadMetadata)(r.metadata),m={...r.metadata,...p,extractedText:f};return!f||f.trim().length===0?yield*a.Effect.logWarning(`No text extracted from file ${r.id}. This might be a scanned document. Consider using the OCR node instead.`):yield*a.Effect.logInfo(`Successfully extracted ${f.length} characters from file ${r.id}`),(0,n.completeNodeExecution)({...r,metadata:m,flow:u})})})})}const u=o.z.array(r.uploadFileSchema);function d(e,o={}){return a.Effect.gen(function*(){let o=yield*n.DocumentPlugin,s=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Merge PDFs`,description:`Merge multiple PDF documents into one`,type:n.NodeType.process,nodeTypeId:n.STORAGE_OUTPUT_TYPE_ID,inputSchema:u,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:i,nodeId:e,jobId:c};if(!Array.isArray(r))return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`Merge PDF node requires an array of files from a Merge utility node`}).toEffect();if(r.length===0)return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`At least one PDF file is required for merging`}).toEffect();let d=[],f=0;for(let e of r){let t=yield*s.read(e.id,l);d.push(t);let r=(0,n.resolveUploadMetadata)(e.metadata).metadata;r?.pageCount&&typeof r.pageCount==`number`&&(f+=r.pageCount)}yield*a.Effect.logInfo(`Merging ${r.length} PDF files`);let p=yield*o.mergePdfs({pdfs:d}).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to merge PDFs`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to merge PDFs`}).toEffect()}))),m=r[0],{metadata:h}=(0,n.resolveUploadMetadata)(m.metadata),g=new ReadableStream({start(e){e.enqueue(p),e.close()}}),_=yield*s.upload({storageId:m.storage.id,size:p.byteLength,type:`application/pdf`,fileName:`merged-${r.length}-documents.pdf`,lastModified:0,metadata:JSON.stringify({...h,pageCount:f,mergedFrom:r.length}),flow:u},l,g),v={...h,pageCount:f,mergedFrom:r.length,fileName:`merged-${r.length}-documents.pdf`};return yield*a.Effect.logInfo(`Successfully merged ${r.length} PDFs into one document with ${f} pages`),(0,n.completeNodeExecution)({..._,metadata:v})})})})}function f(e,i){return a.Effect.gen(function*(){let o=yield*n.DocumentAiPlugin;return yield*(0,n.createFlowNode)({id:e,name:`OCR`,description:`Extract text from scanned documents using AI`,type:n.NodeType.process,nodeTypeId:n.OCR_OUTPUT_TYPE_ID,inputSchema:r.uploadFileSchema,outputSchema:n.ocrOutputSchema,run:({data:r,flowId:s,jobId:c,clientId:l})=>a.Effect.gen(function*(){let u={flowId:s,nodeId:e,jobId:c},d=r.url;if(!d)return yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for OCR operation`}).toEffect();yield*a.Effect.logInfo(`Starting OCR for file ${r.id} with task type: ${i.taskType}`);let f={clientId:l,credentialId:i.credentialId},p=yield*o.performOCR(d,{taskType:i.taskType,resolution:i.resolution,referenceText:i.referenceText},f).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to perform OCR`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to perform OCR`}).toEffect()})));return yield*a.Effect.logInfo(`Successfully completed OCR for file ${r.id}, extracted ${p.extractedText.length} characters`),(0,n.completeNodeExecution)({extractedText:p.extractedText,format:p.format,taskType:i.taskType,confidence:p.confidence,flow:u})})})})}function p(e,o){return a.Effect.gen(function*(){let s=yield*n.DocumentPlugin,c=yield*i.UploadServer;return yield*(0,n.createFlowNode)({id:e,name:`Split PDF`,description:`Split PDF into pages or page ranges`,type:n.NodeType.process,nodeTypeId:n.STORAGE_OUTPUT_TYPE_ID,inputSchema:r.uploadFileSchema,outputSchema:r.uploadFileSchema,run:({data:r,flowId:i,jobId:l,clientId:u})=>a.Effect.gen(function*(){let d={flowId:i,nodeId:e,jobId:l};yield*a.Effect.logInfo(`Splitting PDF file ${r.id} in ${o.mode} mode`);let f=yield*c.read(r.id,u),p=yield*s.splitPdf(f,o).pipe(a.Effect.catchAll(e=>a.Effect.gen(function*(){return yield*a.Effect.logError(`Failed to split PDF`,e),yield*t.UploadistaError.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to split PDF`}).toEffect()}))),{metadata:m}=(0,n.resolveUploadMetadata)(r.metadata);if(p.mode===`individual`){yield*a.Effect.logInfo(`Successfully split PDF into ${p.pdfs.length} individual pages`),yield*a.Effect.logWarning(`Individual page mode returns multiple files - flow engine support required`);let e=p.pdfs[0],t=new ReadableStream({start(t){t.enqueue(e),t.close()}}),i=yield*c.upload({storageId:r.storage.id,size:e.byteLength,type:`application/pdf`,fileName:`${m?.fileName||`document`}-page-1.pdf`,lastModified:0,metadata:JSON.stringify({...m,pageCount:1,splitMode:`individual`}),flow:d},u,t),o={...m,pageCount:1,splitMode:`individual`};return(0,n.completeNodeExecution)({...i,metadata:o})}let h=o.endPage&&o.startPage?o.endPage-o.startPage+1:1,g=p.pdf,_=new ReadableStream({start(e){e.enqueue(g),e.close()}}),v=yield*c.upload({storageId:r.storage.id,size:g.byteLength,type:`application/pdf`,fileName:`${m?.fileName||`document`}-pages-${o.startPage}-${o.endPage}.pdf`,lastModified:0,metadata:JSON.stringify({...m,pageCount:h,splitMode:`range`,splitRange:`${o.startPage}-${o.endPage}`}),flow:d},u,_),y={...m,pageCount:h,splitMode:`range`,splitRange:`${o.startPage}-${o.endPage}`};return yield*a.Effect.logInfo(`Successfully split PDF to pages ${o.startPage}-${o.endPage}`),(0,n.completeNodeExecution)({...v,metadata:y})})})})}exports.convertToMarkdownParamsSchema=e.o,exports.createConvertToMarkdownNode=s,exports.createDescribeDocumentNode=c,exports.createExtractTextNode=l,exports.createMergePdfNode=d,exports.createOcrNode=f,exports.createSplitPdfNode=p,exports.describeDocumentParamsSchema=e.a,exports.extractTextParamsSchema=e.i,exports.mergePdfParamsSchema=e.r,exports.ocrParamsSchema=e.n,exports.splitPdfParamsSchema=e.t;
|
package/dist/index.d.cts
CHANGED
|
@@ -845,59 +845,15 @@ declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect
|
|
|
845
845
|
} | undefined;
|
|
846
846
|
}, unknown>>;
|
|
847
847
|
outputSchema: zod1.ZodType<{
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
type: string;
|
|
853
|
-
path?: string | undefined;
|
|
854
|
-
uploadId?: string | undefined;
|
|
855
|
-
bucket?: string | undefined;
|
|
856
|
-
parts?: {
|
|
857
|
-
partNumber: number;
|
|
858
|
-
etag: string;
|
|
859
|
-
size: number;
|
|
860
|
-
}[] | undefined;
|
|
861
|
-
};
|
|
862
|
-
size?: number | undefined;
|
|
863
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
864
|
-
creationDate?: string | undefined;
|
|
865
|
-
url?: string | undefined;
|
|
866
|
-
sizeIsDeferred?: boolean | undefined;
|
|
867
|
-
checksum?: string | undefined;
|
|
868
|
-
checksumAlgorithm?: string | undefined;
|
|
869
|
-
flow?: {
|
|
870
|
-
flowId: string;
|
|
871
|
-
nodeId: string;
|
|
872
|
-
jobId: string;
|
|
873
|
-
} | undefined;
|
|
848
|
+
extractedText: string;
|
|
849
|
+
format: "markdown" | "plain" | "structured";
|
|
850
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
851
|
+
confidence?: number | undefined;
|
|
874
852
|
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
type: string;
|
|
880
|
-
path?: string | undefined;
|
|
881
|
-
uploadId?: string | undefined;
|
|
882
|
-
bucket?: string | undefined;
|
|
883
|
-
parts?: {
|
|
884
|
-
partNumber: number;
|
|
885
|
-
etag: string;
|
|
886
|
-
size: number;
|
|
887
|
-
}[] | undefined;
|
|
888
|
-
};
|
|
889
|
-
size?: number | undefined;
|
|
890
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
891
|
-
creationDate?: string | undefined;
|
|
892
|
-
url?: string | undefined;
|
|
893
|
-
sizeIsDeferred?: boolean | undefined;
|
|
894
|
-
checksum?: string | undefined;
|
|
895
|
-
checksumAlgorithm?: string | undefined;
|
|
896
|
-
flow?: {
|
|
897
|
-
flowId: string;
|
|
898
|
-
nodeId: string;
|
|
899
|
-
jobId: string;
|
|
900
|
-
} | undefined;
|
|
853
|
+
extractedText: string;
|
|
854
|
+
format: "markdown" | "plain" | "structured";
|
|
855
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
856
|
+
confidence?: number | undefined;
|
|
901
857
|
}, unknown>>;
|
|
902
858
|
run: (args: {
|
|
903
859
|
data: {
|
|
@@ -934,32 +890,10 @@ declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect
|
|
|
934
890
|
inputs?: Record<string, unknown>;
|
|
935
891
|
clientId: string | null;
|
|
936
892
|
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
type: string;
|
|
942
|
-
path?: string | undefined;
|
|
943
|
-
uploadId?: string | undefined;
|
|
944
|
-
bucket?: string | undefined;
|
|
945
|
-
parts?: {
|
|
946
|
-
partNumber: number;
|
|
947
|
-
etag: string;
|
|
948
|
-
size: number;
|
|
949
|
-
}[] | undefined;
|
|
950
|
-
};
|
|
951
|
-
size?: number | undefined;
|
|
952
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
953
|
-
creationDate?: string | undefined;
|
|
954
|
-
url?: string | undefined;
|
|
955
|
-
sizeIsDeferred?: boolean | undefined;
|
|
956
|
-
checksum?: string | undefined;
|
|
957
|
-
checksumAlgorithm?: string | undefined;
|
|
958
|
-
flow?: {
|
|
959
|
-
flowId: string;
|
|
960
|
-
nodeId: string;
|
|
961
|
-
jobId: string;
|
|
962
|
-
} | undefined;
|
|
893
|
+
extractedText: string;
|
|
894
|
+
format: "markdown" | "plain" | "structured";
|
|
895
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
896
|
+
confidence?: number | undefined;
|
|
963
897
|
}>, UploadistaError, never>;
|
|
964
898
|
condition?: {
|
|
965
899
|
field: string;
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../src/ocr-node.ts","../src/split-pdf-node.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../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,EAAA;MAAkC,EAAA,EAAA,MAAA;MAAa,MAAA,EAAA,MAAA;;;;;;;;;;;;;;;MAAA,YAAA,CAAA,EAAA,MAAA,GAAA,SAAA;MAAA,GAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;MCRnD,IAAA,CAAA,EAAA;QAMI,MAAA,EAAA,MAAkB;QAAqB,MAAA,EAAA,MAAA;QAAkB,KAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;QAAA,IAAA,EAAA,MAAA;QAAA,IAAA,EAAA,MAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { a as MergePdfParams, c as extractTextParamsSchema, d as ConvertToMarkdownParams, f as convertToMarkdownParamsSchema, i as ocrParamsSchema, l as DescribeDocumentParams, n as splitPdfParamsSchema, o as mergePdfParamsSchema, r as OcrParams, s as ExtractTextParams, t as SplitPdfParams, u as describeDocumentParamsSchema } from "./index-aD9vy0kH.mjs";
|
|
2
2
|
import { UploadistaError } from "@uploadista/core/errors";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _uploadista_core_flow1 from "@uploadista/core/flow";
|
|
4
4
|
import { DocumentAiPlugin, DocumentPlugin, NodeType, OcrResolution, OcrTaskType } from "@uploadista/core/flow";
|
|
5
5
|
import { UploadServer } from "@uploadista/core/upload";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
|
-
import * as
|
|
7
|
+
import * as zod1 from "zod";
|
|
8
8
|
import { z } from "zod";
|
|
9
|
-
import * as
|
|
9
|
+
import * as zod_v4_core1 from "zod/v4/core";
|
|
10
10
|
|
|
11
11
|
//#region src/convert-to-markdown-node.d.ts
|
|
12
12
|
type ConvertToMarkdownNodeParams = {
|
|
13
13
|
credentialId?: string;
|
|
14
14
|
resolution?: "tiny" | "small" | "base" | "gundam" | "large";
|
|
15
15
|
};
|
|
16
|
-
declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkdownNodeParams): Effect.Effect<
|
|
17
|
-
inputSchema:
|
|
16
|
+
declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkdownNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
17
|
+
inputSchema: zod1.ZodType<{
|
|
18
18
|
id: string;
|
|
19
19
|
offset: number;
|
|
20
20
|
storage: {
|
|
@@ -41,7 +41,7 @@ declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkd
|
|
|
41
41
|
nodeId: string;
|
|
42
42
|
jobId: string;
|
|
43
43
|
} | undefined;
|
|
44
|
-
}, unknown,
|
|
44
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
45
45
|
id: string;
|
|
46
46
|
offset: number;
|
|
47
47
|
storage: {
|
|
@@ -69,7 +69,7 @@ declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkd
|
|
|
69
69
|
jobId: string;
|
|
70
70
|
} | undefined;
|
|
71
71
|
}, unknown>>;
|
|
72
|
-
outputSchema:
|
|
72
|
+
outputSchema: zod1.ZodType<{
|
|
73
73
|
id: string;
|
|
74
74
|
offset: number;
|
|
75
75
|
storage: {
|
|
@@ -96,7 +96,7 @@ declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkd
|
|
|
96
96
|
nodeId: string;
|
|
97
97
|
jobId: string;
|
|
98
98
|
} | undefined;
|
|
99
|
-
}, unknown,
|
|
99
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
100
100
|
id: string;
|
|
101
101
|
offset: number;
|
|
102
102
|
storage: {
|
|
@@ -158,7 +158,7 @@ declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkd
|
|
|
158
158
|
flowId: string;
|
|
159
159
|
inputs?: Record<string, unknown>;
|
|
160
160
|
clientId: string | null;
|
|
161
|
-
}) => Effect.Effect<
|
|
161
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
162
162
|
id: string;
|
|
163
163
|
offset: number;
|
|
164
164
|
storage: {
|
|
@@ -205,8 +205,8 @@ declare function createConvertToMarkdownNode(id: string, params?: ConvertToMarkd
|
|
|
205
205
|
//#endregion
|
|
206
206
|
//#region src/describe-document-node.d.ts
|
|
207
207
|
type DescribeDocumentNodeParams = Record<string, never>;
|
|
208
|
-
declare function createDescribeDocumentNode(id: string, _params?: DescribeDocumentNodeParams): Effect.Effect<
|
|
209
|
-
inputSchema:
|
|
208
|
+
declare function createDescribeDocumentNode(id: string, _params?: DescribeDocumentNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
209
|
+
inputSchema: zod1.ZodType<{
|
|
210
210
|
id: string;
|
|
211
211
|
offset: number;
|
|
212
212
|
storage: {
|
|
@@ -233,7 +233,7 @@ declare function createDescribeDocumentNode(id: string, _params?: DescribeDocume
|
|
|
233
233
|
nodeId: string;
|
|
234
234
|
jobId: string;
|
|
235
235
|
} | undefined;
|
|
236
|
-
}, unknown,
|
|
236
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
237
237
|
id: string;
|
|
238
238
|
offset: number;
|
|
239
239
|
storage: {
|
|
@@ -261,7 +261,7 @@ declare function createDescribeDocumentNode(id: string, _params?: DescribeDocume
|
|
|
261
261
|
jobId: string;
|
|
262
262
|
} | undefined;
|
|
263
263
|
}, unknown>>;
|
|
264
|
-
outputSchema:
|
|
264
|
+
outputSchema: zod1.ZodType<{
|
|
265
265
|
id: string;
|
|
266
266
|
offset: number;
|
|
267
267
|
storage: {
|
|
@@ -288,7 +288,7 @@ declare function createDescribeDocumentNode(id: string, _params?: DescribeDocume
|
|
|
288
288
|
nodeId: string;
|
|
289
289
|
jobId: string;
|
|
290
290
|
} | undefined;
|
|
291
|
-
}, unknown,
|
|
291
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
292
292
|
id: string;
|
|
293
293
|
offset: number;
|
|
294
294
|
storage: {
|
|
@@ -350,7 +350,7 @@ declare function createDescribeDocumentNode(id: string, _params?: DescribeDocume
|
|
|
350
350
|
flowId: string;
|
|
351
351
|
inputs?: Record<string, unknown>;
|
|
352
352
|
clientId: string | null;
|
|
353
|
-
}) => Effect.Effect<
|
|
353
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
354
354
|
id: string;
|
|
355
355
|
offset: number;
|
|
356
356
|
storage: {
|
|
@@ -397,8 +397,8 @@ declare function createDescribeDocumentNode(id: string, _params?: DescribeDocume
|
|
|
397
397
|
//#endregion
|
|
398
398
|
//#region src/extract-text-node.d.ts
|
|
399
399
|
type ExtractTextNodeParams = Record<string, never>;
|
|
400
|
-
declare function createExtractTextNode(id: string, _params?: ExtractTextNodeParams): Effect.Effect<
|
|
401
|
-
inputSchema:
|
|
400
|
+
declare function createExtractTextNode(id: string, _params?: ExtractTextNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
401
|
+
inputSchema: zod1.ZodType<{
|
|
402
402
|
id: string;
|
|
403
403
|
offset: number;
|
|
404
404
|
storage: {
|
|
@@ -425,7 +425,7 @@ declare function createExtractTextNode(id: string, _params?: ExtractTextNodePara
|
|
|
425
425
|
nodeId: string;
|
|
426
426
|
jobId: string;
|
|
427
427
|
} | undefined;
|
|
428
|
-
}, unknown,
|
|
428
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
429
429
|
id: string;
|
|
430
430
|
offset: number;
|
|
431
431
|
storage: {
|
|
@@ -453,7 +453,7 @@ declare function createExtractTextNode(id: string, _params?: ExtractTextNodePara
|
|
|
453
453
|
jobId: string;
|
|
454
454
|
} | undefined;
|
|
455
455
|
}, unknown>>;
|
|
456
|
-
outputSchema:
|
|
456
|
+
outputSchema: zod1.ZodType<{
|
|
457
457
|
id: string;
|
|
458
458
|
offset: number;
|
|
459
459
|
storage: {
|
|
@@ -480,7 +480,7 @@ declare function createExtractTextNode(id: string, _params?: ExtractTextNodePara
|
|
|
480
480
|
nodeId: string;
|
|
481
481
|
jobId: string;
|
|
482
482
|
} | undefined;
|
|
483
|
-
}, unknown,
|
|
483
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
484
484
|
id: string;
|
|
485
485
|
offset: number;
|
|
486
486
|
storage: {
|
|
@@ -542,7 +542,7 @@ declare function createExtractTextNode(id: string, _params?: ExtractTextNodePara
|
|
|
542
542
|
flowId: string;
|
|
543
543
|
inputs?: Record<string, unknown>;
|
|
544
544
|
clientId: string | null;
|
|
545
|
-
}) => Effect.Effect<
|
|
545
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
546
546
|
id: string;
|
|
547
547
|
offset: number;
|
|
548
548
|
storage: {
|
|
@@ -591,7 +591,7 @@ declare function createExtractTextNode(id: string, _params?: ExtractTextNodePara
|
|
|
591
591
|
type MergePdfNodeParams = {
|
|
592
592
|
inputCount?: number;
|
|
593
593
|
};
|
|
594
|
-
declare function createMergePdfNode(id: string, _params?: MergePdfNodeParams): Effect.Effect<
|
|
594
|
+
declare function createMergePdfNode(id: string, _params?: MergePdfNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
595
595
|
inputSchema: z.ZodType<{
|
|
596
596
|
id: string;
|
|
597
597
|
offset: number;
|
|
@@ -736,7 +736,7 @@ declare function createMergePdfNode(id: string, _params?: MergePdfNodeParams): E
|
|
|
736
736
|
flowId: string;
|
|
737
737
|
inputs?: Record<string, unknown>;
|
|
738
738
|
clientId: string | null;
|
|
739
|
-
}) => Effect.Effect<
|
|
739
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
740
740
|
id: string;
|
|
741
741
|
offset: number;
|
|
742
742
|
storage: {
|
|
@@ -788,8 +788,8 @@ type OcrNodeParams = {
|
|
|
788
788
|
credentialId?: string;
|
|
789
789
|
referenceText?: string;
|
|
790
790
|
};
|
|
791
|
-
declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect<
|
|
792
|
-
inputSchema:
|
|
791
|
+
declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
792
|
+
inputSchema: zod1.ZodType<{
|
|
793
793
|
id: string;
|
|
794
794
|
offset: number;
|
|
795
795
|
storage: {
|
|
@@ -816,7 +816,7 @@ declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect
|
|
|
816
816
|
nodeId: string;
|
|
817
817
|
jobId: string;
|
|
818
818
|
} | undefined;
|
|
819
|
-
}, unknown,
|
|
819
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
820
820
|
id: string;
|
|
821
821
|
offset: number;
|
|
822
822
|
storage: {
|
|
@@ -844,60 +844,16 @@ declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect
|
|
|
844
844
|
jobId: string;
|
|
845
845
|
} | undefined;
|
|
846
846
|
}, unknown>>;
|
|
847
|
-
outputSchema:
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
partNumber: number;
|
|
858
|
-
etag: string;
|
|
859
|
-
size: number;
|
|
860
|
-
}[] | undefined;
|
|
861
|
-
};
|
|
862
|
-
size?: number | undefined;
|
|
863
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
864
|
-
creationDate?: string | undefined;
|
|
865
|
-
url?: string | undefined;
|
|
866
|
-
sizeIsDeferred?: boolean | undefined;
|
|
867
|
-
checksum?: string | undefined;
|
|
868
|
-
checksumAlgorithm?: string | undefined;
|
|
869
|
-
flow?: {
|
|
870
|
-
flowId: string;
|
|
871
|
-
nodeId: string;
|
|
872
|
-
jobId: string;
|
|
873
|
-
} | undefined;
|
|
874
|
-
}, unknown, zod_v4_core0.$ZodTypeInternals<{
|
|
875
|
-
id: string;
|
|
876
|
-
offset: number;
|
|
877
|
-
storage: {
|
|
878
|
-
id: string;
|
|
879
|
-
type: string;
|
|
880
|
-
path?: string | undefined;
|
|
881
|
-
uploadId?: string | undefined;
|
|
882
|
-
bucket?: string | undefined;
|
|
883
|
-
parts?: {
|
|
884
|
-
partNumber: number;
|
|
885
|
-
etag: string;
|
|
886
|
-
size: number;
|
|
887
|
-
}[] | undefined;
|
|
888
|
-
};
|
|
889
|
-
size?: number | undefined;
|
|
890
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
891
|
-
creationDate?: string | undefined;
|
|
892
|
-
url?: string | undefined;
|
|
893
|
-
sizeIsDeferred?: boolean | undefined;
|
|
894
|
-
checksum?: string | undefined;
|
|
895
|
-
checksumAlgorithm?: string | undefined;
|
|
896
|
-
flow?: {
|
|
897
|
-
flowId: string;
|
|
898
|
-
nodeId: string;
|
|
899
|
-
jobId: string;
|
|
900
|
-
} | undefined;
|
|
847
|
+
outputSchema: zod1.ZodType<{
|
|
848
|
+
extractedText: string;
|
|
849
|
+
format: "markdown" | "plain" | "structured";
|
|
850
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
851
|
+
confidence?: number | undefined;
|
|
852
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
853
|
+
extractedText: string;
|
|
854
|
+
format: "markdown" | "plain" | "structured";
|
|
855
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
856
|
+
confidence?: number | undefined;
|
|
901
857
|
}, unknown>>;
|
|
902
858
|
run: (args: {
|
|
903
859
|
data: {
|
|
@@ -933,33 +889,11 @@ declare function createOcrNode(id: string, params: OcrNodeParams): Effect.Effect
|
|
|
933
889
|
flowId: string;
|
|
934
890
|
inputs?: Record<string, unknown>;
|
|
935
891
|
clientId: string | null;
|
|
936
|
-
}) => Effect.Effect<
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
type: string;
|
|
942
|
-
path?: string | undefined;
|
|
943
|
-
uploadId?: string | undefined;
|
|
944
|
-
bucket?: string | undefined;
|
|
945
|
-
parts?: {
|
|
946
|
-
partNumber: number;
|
|
947
|
-
etag: string;
|
|
948
|
-
size: number;
|
|
949
|
-
}[] | undefined;
|
|
950
|
-
};
|
|
951
|
-
size?: number | undefined;
|
|
952
|
-
metadata?: Record<string, string | number | boolean> | undefined;
|
|
953
|
-
creationDate?: string | undefined;
|
|
954
|
-
url?: string | undefined;
|
|
955
|
-
sizeIsDeferred?: boolean | undefined;
|
|
956
|
-
checksum?: string | undefined;
|
|
957
|
-
checksumAlgorithm?: string | undefined;
|
|
958
|
-
flow?: {
|
|
959
|
-
flowId: string;
|
|
960
|
-
nodeId: string;
|
|
961
|
-
jobId: string;
|
|
962
|
-
} | undefined;
|
|
892
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
893
|
+
extractedText: string;
|
|
894
|
+
format: "markdown" | "plain" | "structured";
|
|
895
|
+
taskType: "convertToMarkdown" | "freeOcr" | "parseFigure" | "locateObject";
|
|
896
|
+
confidence?: number | undefined;
|
|
963
897
|
}>, UploadistaError, never>;
|
|
964
898
|
condition?: {
|
|
965
899
|
field: string;
|
|
@@ -984,8 +918,8 @@ type SplitPdfNodeParams = {
|
|
|
984
918
|
startPage?: number;
|
|
985
919
|
endPage?: number;
|
|
986
920
|
};
|
|
987
|
-
declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Effect.Effect<
|
|
988
|
-
inputSchema:
|
|
921
|
+
declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Effect.Effect<_uploadista_core_flow1.FlowNodeData & {
|
|
922
|
+
inputSchema: zod1.ZodType<{
|
|
989
923
|
id: string;
|
|
990
924
|
offset: number;
|
|
991
925
|
storage: {
|
|
@@ -1012,7 +946,7 @@ declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Eff
|
|
|
1012
946
|
nodeId: string;
|
|
1013
947
|
jobId: string;
|
|
1014
948
|
} | undefined;
|
|
1015
|
-
}, unknown,
|
|
949
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
1016
950
|
id: string;
|
|
1017
951
|
offset: number;
|
|
1018
952
|
storage: {
|
|
@@ -1040,7 +974,7 @@ declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Eff
|
|
|
1040
974
|
jobId: string;
|
|
1041
975
|
} | undefined;
|
|
1042
976
|
}, unknown>>;
|
|
1043
|
-
outputSchema:
|
|
977
|
+
outputSchema: zod1.ZodType<{
|
|
1044
978
|
id: string;
|
|
1045
979
|
offset: number;
|
|
1046
980
|
storage: {
|
|
@@ -1067,7 +1001,7 @@ declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Eff
|
|
|
1067
1001
|
nodeId: string;
|
|
1068
1002
|
jobId: string;
|
|
1069
1003
|
} | undefined;
|
|
1070
|
-
}, unknown,
|
|
1004
|
+
}, unknown, zod_v4_core1.$ZodTypeInternals<{
|
|
1071
1005
|
id: string;
|
|
1072
1006
|
offset: number;
|
|
1073
1007
|
storage: {
|
|
@@ -1129,7 +1063,7 @@ declare function createSplitPdfNode(id: string, params: SplitPdfNodeParams): Eff
|
|
|
1129
1063
|
flowId: string;
|
|
1130
1064
|
inputs?: Record<string, unknown>;
|
|
1131
1065
|
clientId: string | null;
|
|
1132
|
-
}) => Effect.Effect<
|
|
1066
|
+
}) => Effect.Effect<_uploadista_core_flow1.NodeExecutionResult<{
|
|
1133
1067
|
id: string;
|
|
1134
1068
|
offset: number;
|
|
1135
1069
|
storage: {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../src/ocr-node.ts","../src/split-pdf-node.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../src/ocr-node.ts","../src/split-pdf-node.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;KAcY,2BAAA;;;;iB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AA,CAAA,EAAA,MAAA,GAAA,SAAA;MAAA,GAAA,CAAA,EAAA,MAAA,GAAA,SAAA;;;;MCRnD,IAAA,CAAA,EAAA;QAMI,MAAA,EAAA,MAAkB;QAAqB,MAAA,EAAA,MAAA;QAAkB,KAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;QAAA,IAAA,EAAA,MAAA;QAAA,IAAA,EAAA,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{a as e,i as t,n,o as r,r as i,t as a}from"./types-rDFmPO7S.mjs";import{UploadistaError as o}from"@uploadista/core/errors";import{DocumentAiPlugin as s,DocumentPlugin as c,NodeType as l,
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,t as a}from"./types-rDFmPO7S.mjs";import{UploadistaError as o}from"@uploadista/core/errors";import{DocumentAiPlugin as s,DocumentPlugin as c,NodeType as l,OCR_OUTPUT_TYPE_ID as u,STORAGE_OUTPUT_TYPE_ID as d,completeNodeExecution as f,createFlowNode as p,ocrOutputSchema as m,resolveUploadMetadata as h}from"@uploadista/core/flow";import{uploadFileSchema as g}from"@uploadista/core/types";import{UploadServer as _}from"@uploadista/core/upload";import{Effect as v,Either as y}from"effect";import{z as b}from"zod";function x(e,t={}){return v.gen(function*(){let n=yield*c,r=yield*s,i=yield*_;return yield*p({id:e,name:`Convert to Markdown`,description:`Convert documents to Markdown format (intelligently uses OCR if needed)`,type:l.process,nodeTypeId:d,inputSchema:g,outputSchema:g,run:({data:a,flowId:s,jobId:c,clientId:l})=>v.gen(function*(){let u={flowId:s,nodeId:e,jobId:c};yield*v.logInfo(`Converting file ${a.id} to Markdown`);let d=yield*i.read(a.id,l),p=yield*n.extractText(d).pipe(v.either),m,g;if(y.isRight(p)&&p.right.trim().length>0){let e=p.right;yield*v.logInfo(`Successfully extracted ${e.length} characters from searchable PDF`),m=e.split(`
|
|
2
2
|
|
|
3
3
|
`).map(e=>e.trim()).filter(e=>e.length>0).join(`
|
|
4
4
|
|
|
5
|
-
`),
|
|
5
|
+
`),g=`text`,yield*v.logInfo(`Converted text to Markdown (${m.length} characters)`)}else{yield*v.logInfo(`Text extraction failed or returned empty, falling back to OCR`);let e=a.url;if(!e)return yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for OCR-based markdown conversion`}).toEffect();let n={clientId:l,credentialId:t.credentialId};m=(yield*r.performOCR(e,{taskType:`convertToMarkdown`,resolution:t.resolution||`gundam`},n).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to perform OCR`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to perform OCR for markdown conversion`}).toEffect()})))).extractedText,g=`ocr`,yield*v.logInfo(`Successfully converted scanned document to Markdown using OCR (${m.length} characters)`)}let{metadata:_}=h(a.metadata),b={...a.metadata,..._,markdown:m,markdownSource:g};return yield*v.logInfo(`Successfully converted file ${a.id} to Markdown via ${g}`),f({...a,metadata:b,flow:u})})})})}function S(e,t={}){return v.gen(function*(){let t=yield*c,n=yield*_;return yield*p({id:e,name:`Describe Document`,description:`Extract metadata from PDF documents`,type:l.process,inputSchema:g,outputSchema:g,run:({data:r,flowId:i,jobId:a,clientId:s})=>v.gen(function*(){let c={flowId:i,nodeId:e,jobId:a};yield*v.logInfo(`Extracting metadata from PDF file ${r.id}`);let l=yield*n.read(r.id,s),u=yield*t.getMetadata(l).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to extract metadata`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract metadata`}).toEffect()}))),{metadata:d}=h(r.metadata),p={...r.metadata,...d,pageCount:u.pageCount,format:u.format,...u.author&&{author:u.author},...u.title&&{title:u.title},...u.subject&&{subject:u.subject},...u.creator&&{creator:u.creator},...u.creationDate&&{creationDate:u.creationDate},...u.modifiedDate&&{modifiedDate:u.modifiedDate},fileSize:u.fileSize};return yield*v.logInfo(`Successfully extracted metadata from file ${r.id}: ${u.pageCount} pages`),f({...r,metadata:p,flow:c})})})})}function C(e,t={}){return v.gen(function*(){let t=yield*c,n=yield*_;return yield*p({id:e,name:`Extract Text`,description:`Extract text from searchable PDF documents`,type:l.process,nodeTypeId:d,inputSchema:g,outputSchema:g,run:({data:r,flowId:i,jobId:a,clientId:s})=>v.gen(function*(){let c={flowId:i,nodeId:e,jobId:a};yield*v.logInfo(`Extracting text from PDF file ${r.id}`);let l=yield*n.read(r.id,s),u=yield*t.extractText(l).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to extract text`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to extract text`}).toEffect()}))),{metadata:d}=h(r.metadata),p={...r.metadata,...d,extractedText:u};return!u||u.trim().length===0?yield*v.logWarning(`No text extracted from file ${r.id}. This might be a scanned document. Consider using the OCR node instead.`):yield*v.logInfo(`Successfully extracted ${u.length} characters from file ${r.id}`),f({...r,metadata:p,flow:c})})})})}const w=b.array(g);function T(e,t={}){return v.gen(function*(){let t=yield*c,n=yield*_;return yield*p({id:e,name:`Merge PDFs`,description:`Merge multiple PDF documents into one`,type:l.process,nodeTypeId:d,inputSchema:w,outputSchema:g,run:({data:r,flowId:i,jobId:a,clientId:s})=>v.gen(function*(){let c={flowId:i,nodeId:e,jobId:a};if(!Array.isArray(r))return yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:`Merge PDF node requires an array of files from a Merge utility node`}).toEffect();if(r.length===0)return yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:`At least one PDF file is required for merging`}).toEffect();let l=[],u=0;for(let e of r){let t=yield*n.read(e.id,s);l.push(t);let r=h(e.metadata).metadata;r?.pageCount&&typeof r.pageCount==`number`&&(u+=r.pageCount)}yield*v.logInfo(`Merging ${r.length} PDF files`);let d=yield*t.mergePdfs({pdfs:l}).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to merge PDFs`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to merge PDFs`}).toEffect()}))),p=r[0],{metadata:m}=h(p.metadata),g=new ReadableStream({start(e){e.enqueue(d),e.close()}}),_=yield*n.upload({storageId:p.storage.id,size:d.byteLength,type:`application/pdf`,fileName:`merged-${r.length}-documents.pdf`,lastModified:0,metadata:JSON.stringify({...m,pageCount:u,mergedFrom:r.length}),flow:c},s,g),y={...m,pageCount:u,mergedFrom:r.length,fileName:`merged-${r.length}-documents.pdf`};return yield*v.logInfo(`Successfully merged ${r.length} PDFs into one document with ${u} pages`),f({..._,metadata:y})})})})}function E(e,t){return v.gen(function*(){let n=yield*s;return yield*p({id:e,name:`OCR`,description:`Extract text from scanned documents using AI`,type:l.process,nodeTypeId:u,inputSchema:g,outputSchema:m,run:({data:r,flowId:i,jobId:a,clientId:s})=>v.gen(function*(){let c={flowId:i,nodeId:e,jobId:a},l=r.url;if(!l)return yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:`URL is required for OCR operation`}).toEffect();yield*v.logInfo(`Starting OCR for file ${r.id} with task type: ${t.taskType}`);let u={clientId:s,credentialId:t.credentialId},d=yield*n.performOCR(l,{taskType:t.taskType,resolution:t.resolution,referenceText:t.referenceText},u).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to perform OCR`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to perform OCR`}).toEffect()})));return yield*v.logInfo(`Successfully completed OCR for file ${r.id}, extracted ${d.extractedText.length} characters`),f({extractedText:d.extractedText,format:d.format,taskType:t.taskType,confidence:d.confidence,flow:c})})})})}function D(e,t){return v.gen(function*(){let n=yield*c,r=yield*_;return yield*p({id:e,name:`Split PDF`,description:`Split PDF into pages or page ranges`,type:l.process,nodeTypeId:d,inputSchema:g,outputSchema:g,run:({data:i,flowId:a,jobId:s,clientId:c})=>v.gen(function*(){let l={flowId:a,nodeId:e,jobId:s};yield*v.logInfo(`Splitting PDF file ${i.id} in ${t.mode} mode`);let u=yield*r.read(i.id,c),d=yield*n.splitPdf(u,t).pipe(v.catchAll(e=>v.gen(function*(){return yield*v.logError(`Failed to split PDF`,e),yield*o.fromCode(`FLOW_NODE_ERROR`,{cause:e instanceof Error?e.message:`Failed to split PDF`}).toEffect()}))),{metadata:p}=h(i.metadata);if(d.mode===`individual`){yield*v.logInfo(`Successfully split PDF into ${d.pdfs.length} individual pages`),yield*v.logWarning(`Individual page mode returns multiple files - flow engine support required`);let e=d.pdfs[0],t=new ReadableStream({start(t){t.enqueue(e),t.close()}}),n=yield*r.upload({storageId:i.storage.id,size:e.byteLength,type:`application/pdf`,fileName:`${p?.fileName||`document`}-page-1.pdf`,lastModified:0,metadata:JSON.stringify({...p,pageCount:1,splitMode:`individual`}),flow:l},c,t),a={...p,pageCount:1,splitMode:`individual`};return f({...n,metadata:a})}let m=t.endPage&&t.startPage?t.endPage-t.startPage+1:1,g=d.pdf,_=new ReadableStream({start(e){e.enqueue(g),e.close()}}),y=yield*r.upload({storageId:i.storage.id,size:g.byteLength,type:`application/pdf`,fileName:`${p?.fileName||`document`}-pages-${t.startPage}-${t.endPage}.pdf`,lastModified:0,metadata:JSON.stringify({...p,pageCount:m,splitMode:`range`,splitRange:`${t.startPage}-${t.endPage}`}),flow:l},c,_),b={...p,pageCount:m,splitMode:`range`,splitRange:`${t.startPage}-${t.endPage}`};return yield*v.logInfo(`Successfully split PDF to pages ${t.startPage}-${t.endPage}`),f({...y,metadata:b})})})})}export{r as convertToMarkdownParamsSchema,x as createConvertToMarkdownNode,S as createDescribeDocumentNode,C as createExtractTextNode,T as createMergePdfNode,E as createOcrNode,D as createSplitPdfNode,e as describeDocumentParamsSchema,t as extractTextParamsSchema,i as mergePdfParamsSchema,n as ocrParamsSchema,a as splitPdfParamsSchema};
|
|
6
6
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["markdown: string","markdownSource: \"text\" | \"ocr\"","pdfBuffers: Uint8Array[]","pdfBytes","stream","uploadResult","newMetadata"],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../src/ocr-node.ts","../src/split-pdf-node.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentAiPlugin,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect, Either } from \"effect\";\n\nexport type ConvertToMarkdownNodeParams = {\n credentialId?: string;\n resolution?: \"tiny\" | \"small\" | \"base\" | \"gundam\" | \"large\";\n};\n\nexport function createConvertToMarkdownNode(\n id: string,\n params: ConvertToMarkdownNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const documentAiService = yield* DocumentAiPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Convert to Markdown\",\n description:\n \"Convert documents to Markdown format (intelligently uses OCR if needed)\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(`Converting file ${file.id} to Markdown`);\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Try to extract text first (for searchable PDFs)\n const extractResult = yield* documentService\n .extractText(fileBytes)\n .pipe(Effect.either);\n\n let markdown: string;\n let markdownSource: \"text\" | \"ocr\";\n\n if (\n Either.isRight(extractResult) &&\n extractResult.right.trim().length > 0\n ) {\n // Successfully extracted text from searchable PDF\n const text = extractResult.right;\n\n yield* Effect.logInfo(\n `Successfully extracted ${text.length} characters from searchable PDF`,\n );\n\n // Simple text-to-markdown conversion\n // In a real implementation, this could be more sophisticated\n markdown = text\n .split(\"\\n\\n\")\n .map((para: string) => para.trim())\n .filter((para: string) => para.length > 0)\n .join(\"\\n\\n\");\n\n markdownSource = \"text\";\n\n yield* Effect.logInfo(\n `Converted text to Markdown (${markdown.length} characters)`,\n );\n } else {\n // Text extraction failed or returned empty - use OCR\n yield* Effect.logInfo(\n \"Text extraction failed or returned empty, falling back to OCR\",\n );\n\n const fileUrl = file.url;\n\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for OCR-based markdown conversion\",\n }).toEffect();\n }\n\n // Build context for DocumentAI plugin\n const context = {\n clientId,\n credentialId: params.credentialId,\n };\n\n // Perform OCR with markdown conversion\n const ocrResult = yield* documentAiService\n .performOCR(\n fileUrl,\n {\n taskType: \"convertToMarkdown\",\n resolution: params.resolution || \"gundam\",\n },\n context,\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to perform OCR\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to perform OCR for markdown conversion\",\n }).toEffect();\n }),\n ),\n );\n\n markdown = ocrResult.extractedText;\n markdownSource = \"ocr\";\n\n yield* Effect.logInfo(\n `Successfully converted scanned document to Markdown using OCR (${markdown.length} characters)`,\n );\n }\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add markdown to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n markdown,\n markdownSource,\n };\n\n yield* Effect.logInfo(\n `Successfully converted file ${file.id} to Markdown via ${markdownSource}`,\n );\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type DescribeDocumentNodeParams = Record<string, never>; // No parameters needed\n\nexport function createDescribeDocumentNode(\n id: string,\n _params: DescribeDocumentNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Describe Document\",\n description: \"Extract metadata from PDF documents\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(\n `Extracting metadata from PDF file ${file.id}`,\n );\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Get metadata with error handling\n const documentMetadata = yield* documentService\n .getMetadata(fileBytes)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to extract metadata\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to extract metadata\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add document metadata to file metadata (filter out null values)\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n pageCount: documentMetadata.pageCount,\n format: documentMetadata.format,\n ...(documentMetadata.author && { author: documentMetadata.author }),\n ...(documentMetadata.title && { title: documentMetadata.title }),\n ...(documentMetadata.subject && { subject: documentMetadata.subject }),\n ...(documentMetadata.creator && { creator: documentMetadata.creator }),\n ...(documentMetadata.creationDate && { creationDate: documentMetadata.creationDate }),\n ...(documentMetadata.modifiedDate && { modifiedDate: documentMetadata.modifiedDate }),\n fileSize: documentMetadata.fileSize,\n };\n\n yield* Effect.logInfo(\n `Successfully extracted metadata from file ${file.id}: ${documentMetadata.pageCount} pages`,\n );\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type ExtractTextNodeParams = Record<string, never>; // No parameters needed\n\nexport function createExtractTextNode(\n id: string,\n _params: ExtractTextNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Extract Text\",\n description: \"Extract text from searchable PDF documents\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(\n `Extracting text from PDF file ${file.id}`,\n );\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Extract text with error handling\n const extractedText = yield* documentService\n .extractText(fileBytes)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to extract text\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to extract text\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add extracted text to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n extractedText,\n };\n\n if (!extractedText || extractedText.trim().length === 0) {\n yield* Effect.logWarning(\n `No text extracted from file ${file.id}. This might be a scanned document. Consider using the OCR node instead.`,\n );\n } else {\n yield* Effect.logInfo(\n `Successfully extracted ${extractedText.length} characters from file ${file.id}`,\n );\n }\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { z } from \"zod\";\n\nexport type MergePdfNodeParams = {\n inputCount?: number;\n};\n\n// Schema for multiple file inputs\nconst multipleFilesSchema = z.array(uploadFileSchema);\n\nexport function createMergePdfNode(\n id: string,\n _params: MergePdfNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Merge PDFs\",\n description: \"Merge multiple PDF documents into one\",\n type: NodeType.process,\n inputSchema: multipleFilesSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: files, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n // Validate that we have an array of files\n if (!Array.isArray(files)) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"Merge PDF node requires an array of files from a Merge utility node\",\n }).toEffect();\n }\n\n if (files.length === 0) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"At least one PDF file is required for merging\",\n }).toEffect();\n }\n\n // Read buffers from all files\n const pdfBuffers: Uint8Array[] = [];\n let totalPages = 0;\n\n for (const file of files) {\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n pdfBuffers.push(fileBytes);\n\n // Sum up page counts if available\n const fileMetadata = resolveUploadMetadata(file.metadata).metadata;\n if (fileMetadata?.pageCount && typeof fileMetadata.pageCount === 'number') {\n totalPages += fileMetadata.pageCount;\n }\n }\n\n yield* Effect.logInfo(\n `Merging ${files.length} PDF files`,\n );\n\n // Merge PDFs with error handling\n const mergedPdf = yield* documentService\n .mergePdfs({ pdfs: pdfBuffers })\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to merge PDFs\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to merge PDFs\",\n }).toEffect();\n }),\n ),\n );\n\n // Use metadata from first file as base\n const firstFile = files[0];\n const { metadata } = resolveUploadMetadata(firstFile.metadata);\n\n // Create a stream from the merged PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(mergedPdf);\n controller.close();\n },\n });\n\n // Upload the merged PDF back to the upload server\n const result = yield* uploadServer.upload(\n {\n storageId: firstFile.storage.id,\n size: mergedPdf.byteLength,\n type: \"application/pdf\",\n fileName: `merged-${files.length}-documents.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount: totalPages,\n mergedFrom: files.length,\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount: totalPages,\n mergedFrom: files.length,\n fileName: `merged-${files.length}-documents.pdf`,\n };\n\n yield* Effect.logInfo(\n `Successfully merged ${files.length} PDFs into one document with ${totalPages} pages`,\n );\n\n return completeNodeExecution({\n ...result,\n metadata: newMetadata,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentAiPlugin,\n NodeType,\n type OcrTaskType,\n type OcrResolution,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { Effect } from \"effect\";\n\nexport type OcrNodeParams = {\n taskType: OcrTaskType;\n resolution?: OcrResolution;\n credentialId?: string;\n referenceText?: string;\n};\n\nexport function createOcrNode(\n id: string,\n params: OcrNodeParams,\n) {\n return Effect.gen(function* () {\n const documentAiService = yield* DocumentAiPlugin;\n\n return yield* createFlowNode({\n id,\n name: \"OCR\",\n description: \"Extract text from scanned documents using AI\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for OCR operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Starting OCR for file ${file.id} with task type: ${params.taskType}`,\n );\n\n // Build context for DocumentAI plugin\n const context = {\n clientId,\n credentialId: params.credentialId,\n };\n\n // Perform OCR with error handling\n const ocrResult = yield* documentAiService\n .performOCR(\n fileUrl,\n {\n taskType: params.taskType,\n resolution: params.resolution,\n referenceText: params.referenceText,\n },\n context\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to perform OCR\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to perform OCR\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add OCR results to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n ocrText: ocrResult.extractedText,\n ocrFormat: ocrResult.format,\n ocrTaskType: params.taskType,\n };\n\n yield* Effect.logInfo(\n `Successfully completed OCR for file ${file.id}, extracted ${ocrResult.extractedText.length} characters`,\n );\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type SplitPdfNodeParams = {\n mode: \"range\" | \"individual\";\n startPage?: number;\n endPage?: number;\n};\n\nexport function createSplitPdfNode(\n id: string,\n params: SplitPdfNodeParams,\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Split PDF\",\n description: \"Split PDF into pages or page ranges\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(\n `Splitting PDF file ${file.id} in ${params.mode} mode`,\n );\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Split PDF with error handling\n const result = yield* documentService\n .splitPdf(fileBytes, params)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to split PDF\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to split PDF\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n if (result.mode === \"individual\") {\n // Return array of files (one per page)\n yield* Effect.logInfo(\n `Successfully split PDF into ${result.pdfs.length} individual pages`,\n );\n\n // For individual mode, we'd need to return multiple files\n // This requires special handling in the flow engine\n // For now, we'll return the first page and log a warning\n yield* Effect.logWarning(\n \"Individual page mode returns multiple files - flow engine support required\",\n );\n\n const pdfBytes = result.pdfs[0];\n\n // Create a stream from the PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(pdfBytes);\n controller.close();\n },\n });\n\n // Upload the split PDF back to the upload server\n const uploadResult = yield* uploadServer.upload(\n {\n storageId: file.storage.id,\n size: pdfBytes.byteLength,\n type: \"application/pdf\",\n fileName: `${metadata?.fileName || 'document'}-page-1.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount: 1,\n splitMode: \"individual\",\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount: 1,\n splitMode: \"individual\",\n };\n\n return completeNodeExecution({\n ...uploadResult,\n metadata: newMetadata,\n });\n }\n\n // Range mode - return single PDF with selected pages\n const pageCount = params.endPage && params.startPage\n ? params.endPage - params.startPage + 1\n : 1;\n\n const pdfBytes = result.pdf;\n\n // Create a stream from the PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(pdfBytes);\n controller.close();\n },\n });\n\n // Upload the split PDF back to the upload server\n const uploadResult = yield* uploadServer.upload(\n {\n storageId: file.storage.id,\n size: pdfBytes.byteLength,\n type: \"application/pdf\",\n fileName: `${metadata?.fileName || 'document'}-pages-${params.startPage}-${params.endPage}.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount,\n splitMode: \"range\",\n splitRange: `${params.startPage}-${params.endPage}`,\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount,\n splitMode: \"range\",\n splitRange: `${params.startPage}-${params.endPage}`,\n };\n\n yield* Effect.logInfo(\n `Successfully split PDF to pages ${params.startPage}-${params.endPage}`,\n );\n\n return completeNodeExecution({\n ...uploadResult,\n metadata: newMetadata,\n });\n });\n },\n });\n });\n}\n"],"mappings":"2dAkBA,SAAgB,EACd,EACA,EAAsC,EAAE,CACxC,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAkB,MAAO,EACzB,EAAoB,MAAO,EAC3B,EAAe,MAAO,EAE5B,OAAO,MAAO,EAAe,CAC3B,KACA,KAAM,sBACN,YACE,0EACF,KAAM,EAAS,QACf,YAAa,EACb,aAAc,EACd,KAAM,CAAE,KAAM,EAAM,SAAQ,QAAO,cAC1B,EAAO,IAAI,WAAa,CAC7B,IA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AAS,CAC5B,EAAW,OAAO,EAErB,CAAC,CAGIE,EAAe,MAAO,EAAa,OACvC,CACE,UAAW,EAAK,QAAQ,GACxB,KAAMF,EAAS,WACf,KAAM,kBACN,SAAU,GAAG,GAAU,UAAY,WAAW,aAC9C,aAAc,EACd,SAAU,KAAK,UAAU,CACvB,GAAG,EACH,UAAW,EACX,UAAW,aACZ,CAAC,CACF,OACD,CACD,EACAC,EACD,CAEKE,EAAc,CAClB,GAAG,EACH,UAAW,EACX,UAAW,aACZ,CAED,OAAO,EAAsB,CAC3B,GAAGD,EACH,SAAUC,EACX,CAAC,CAIJ,IAAM,EAAY,EAAO,SAAW,EAAO,UACvC,EAAO,QAAU,EAAO,UAAY,EACpC,EAEE,EAAW,EAAO,IAGlB,EAAS,IAAI,eAAe,CAChC,MAAM,EAAY,CAChB,EAAW,QAAQ,EAAS,CAC5B,EAAW,OAAO,EAErB,CAAC,CAGI,EAAe,MAAO,EAAa,OACvC,CACE,UAAW,EAAK,QAAQ,GACxB,KAAM,EAAS,WACf,KAAM,kBACN,SAAU,GAAG,GAAU,UAAY,WAAW,SAAS,EAAO,UAAU,GAAG,EAAO,QAAQ,MAC1F,aAAc,EACd,SAAU,KAAK,UAAU,CACvB,GAAG,EACH,YACA,UAAW,QACX,WAAY,GAAG,EAAO,UAAU,GAAG,EAAO,UAC3C,CAAC,CACF,OACD,CACD,EACA,EACD,CAEK,EAAc,CAClB,GAAG,EACH,YACA,UAAW,QACX,WAAY,GAAG,EAAO,UAAU,GAAG,EAAO,UAC3C,CAMD,OAJA,MAAO,EAAO,QACZ,mCAAmC,EAAO,UAAU,GAAG,EAAO,UAC/D,CAEM,EAAsB,CAC3B,GAAG,EACH,SAAU,EACX,CAAC,EACF,CAEL,CAAC,EACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["markdown: string","markdownSource: \"text\" | \"ocr\"","pdfBuffers: Uint8Array[]","pdfBytes","stream","uploadResult","newMetadata"],"sources":["../src/convert-to-markdown-node.ts","../src/describe-document-node.ts","../src/extract-text-node.ts","../src/merge-pdf-node.ts","../src/ocr-node.ts","../src/split-pdf-node.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentAiPlugin,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect, Either } from \"effect\";\n\nexport type ConvertToMarkdownNodeParams = {\n credentialId?: string;\n resolution?: \"tiny\" | \"small\" | \"base\" | \"gundam\" | \"large\";\n};\n\nexport function createConvertToMarkdownNode(\n id: string,\n params: ConvertToMarkdownNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const documentAiService = yield* DocumentAiPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Convert to Markdown\",\n description:\n \"Convert documents to Markdown format (intelligently uses OCR if needed)\",\n type: NodeType.process,\n nodeTypeId: STORAGE_OUTPUT_TYPE_ID,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(`Converting file ${file.id} to Markdown`);\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Try to extract text first (for searchable PDFs)\n const extractResult = yield* documentService\n .extractText(fileBytes)\n .pipe(Effect.either);\n\n let markdown: string;\n let markdownSource: \"text\" | \"ocr\";\n\n if (\n Either.isRight(extractResult) &&\n extractResult.right.trim().length > 0\n ) {\n // Successfully extracted text from searchable PDF\n const text = extractResult.right;\n\n yield* Effect.logInfo(\n `Successfully extracted ${text.length} characters from searchable PDF`,\n );\n\n // Simple text-to-markdown conversion\n // In a real implementation, this could be more sophisticated\n markdown = text\n .split(\"\\n\\n\")\n .map((para: string) => para.trim())\n .filter((para: string) => para.length > 0)\n .join(\"\\n\\n\");\n\n markdownSource = \"text\";\n\n yield* Effect.logInfo(\n `Converted text to Markdown (${markdown.length} characters)`,\n );\n } else {\n // Text extraction failed or returned empty - use OCR\n yield* Effect.logInfo(\n \"Text extraction failed or returned empty, falling back to OCR\",\n );\n\n const fileUrl = file.url;\n\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for OCR-based markdown conversion\",\n }).toEffect();\n }\n\n // Build context for DocumentAI plugin\n const context = {\n clientId,\n credentialId: params.credentialId,\n };\n\n // Perform OCR with markdown conversion\n const ocrResult = yield* documentAiService\n .performOCR(\n fileUrl,\n {\n taskType: \"convertToMarkdown\",\n resolution: params.resolution || \"gundam\",\n },\n context,\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to perform OCR\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to perform OCR for markdown conversion\",\n }).toEffect();\n }),\n ),\n );\n\n markdown = ocrResult.extractedText;\n markdownSource = \"ocr\";\n\n yield* Effect.logInfo(\n `Successfully converted scanned document to Markdown using OCR (${markdown.length} characters)`,\n );\n }\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add markdown to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n markdown,\n markdownSource,\n };\n\n yield* Effect.logInfo(\n `Successfully converted file ${file.id} to Markdown via ${markdownSource}`,\n );\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type DescribeDocumentNodeParams = Record<string, never>; // No parameters needed\n\nexport function createDescribeDocumentNode(\n id: string,\n _params: DescribeDocumentNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Describe Document\",\n description: \"Extract metadata from PDF documents\",\n type: NodeType.process,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(\n `Extracting metadata from PDF file ${file.id}`,\n );\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Get metadata with error handling\n const documentMetadata = yield* documentService\n .getMetadata(fileBytes)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to extract metadata\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to extract metadata\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add document metadata to file metadata (filter out null values)\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n pageCount: documentMetadata.pageCount,\n format: documentMetadata.format,\n ...(documentMetadata.author && { author: documentMetadata.author }),\n ...(documentMetadata.title && { title: documentMetadata.title }),\n ...(documentMetadata.subject && { subject: documentMetadata.subject }),\n ...(documentMetadata.creator && { creator: documentMetadata.creator }),\n ...(documentMetadata.creationDate && { creationDate: documentMetadata.creationDate }),\n ...(documentMetadata.modifiedDate && { modifiedDate: documentMetadata.modifiedDate }),\n fileSize: documentMetadata.fileSize,\n };\n\n yield* Effect.logInfo(\n `Successfully extracted metadata from file ${file.id}: ${documentMetadata.pageCount} pages`,\n );\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type ExtractTextNodeParams = Record<string, never>; // No parameters needed\n\nexport function createExtractTextNode(\n id: string,\n _params: ExtractTextNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Extract Text\",\n description: \"Extract text from searchable PDF documents\",\n type: NodeType.process,\n nodeTypeId: STORAGE_OUTPUT_TYPE_ID,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(`Extracting text from PDF file ${file.id}`);\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Extract text with error handling\n const extractedText = yield* documentService\n .extractText(fileBytes)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to extract text\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to extract text\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n // Add extracted text to metadata\n const newMetadata = {\n ...file.metadata,\n ...metadata,\n extractedText,\n };\n\n if (!extractedText || extractedText.trim().length === 0) {\n yield* Effect.logWarning(\n `No text extracted from file ${file.id}. This might be a scanned document. Consider using the OCR node instead.`,\n );\n } else {\n yield* Effect.logInfo(\n `Successfully extracted ${extractedText.length} characters from file ${file.id}`,\n );\n }\n\n return completeNodeExecution({\n ...file,\n metadata: newMetadata,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\nimport { z } from \"zod\";\n\nexport type MergePdfNodeParams = {\n inputCount?: number;\n};\n\n// Schema for multiple file inputs\nconst multipleFilesSchema = z.array(uploadFileSchema);\n\nexport function createMergePdfNode(\n id: string,\n _params: MergePdfNodeParams = {},\n) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Merge PDFs\",\n description: \"Merge multiple PDF documents into one\",\n type: NodeType.process,\n nodeTypeId: STORAGE_OUTPUT_TYPE_ID,\n inputSchema: multipleFilesSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: files, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n // Validate that we have an array of files\n if (!Array.isArray(files)) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n \"Merge PDF node requires an array of files from a Merge utility node\",\n }).toEffect();\n }\n\n if (files.length === 0) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"At least one PDF file is required for merging\",\n }).toEffect();\n }\n\n // Read buffers from all files\n const pdfBuffers: Uint8Array[] = [];\n let totalPages = 0;\n\n for (const file of files) {\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n pdfBuffers.push(fileBytes);\n\n // Sum up page counts if available\n const fileMetadata = resolveUploadMetadata(file.metadata).metadata;\n if (\n fileMetadata?.pageCount &&\n typeof fileMetadata.pageCount === \"number\"\n ) {\n totalPages += fileMetadata.pageCount;\n }\n }\n\n yield* Effect.logInfo(`Merging ${files.length} PDF files`);\n\n // Merge PDFs with error handling\n const mergedPdf = yield* documentService\n .mergePdfs({ pdfs: pdfBuffers })\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to merge PDFs\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to merge PDFs\",\n }).toEffect();\n }),\n ),\n );\n\n // Use metadata from first file as base\n const firstFile = files[0];\n const { metadata } = resolveUploadMetadata(firstFile.metadata);\n\n // Create a stream from the merged PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(mergedPdf);\n controller.close();\n },\n });\n\n // Upload the merged PDF back to the upload server\n const result = yield* uploadServer.upload(\n {\n storageId: firstFile.storage.id,\n size: mergedPdf.byteLength,\n type: \"application/pdf\",\n fileName: `merged-${files.length}-documents.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount: totalPages,\n mergedFrom: files.length,\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount: totalPages,\n mergedFrom: files.length,\n fileName: `merged-${files.length}-documents.pdf`,\n };\n\n yield* Effect.logInfo(\n `Successfully merged ${files.length} PDFs into one document with ${totalPages} pages`,\n );\n\n return completeNodeExecution({\n ...result,\n metadata: newMetadata,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentAiPlugin,\n NodeType,\n OCR_OUTPUT_TYPE_ID,\n type OcrResolution,\n type OcrTaskType,\n ocrOutputSchema,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { Effect } from \"effect\";\n\nexport type OcrNodeParams = {\n taskType: OcrTaskType;\n resolution?: OcrResolution;\n credentialId?: string;\n referenceText?: string;\n};\n\nexport function createOcrNode(id: string, params: OcrNodeParams) {\n return Effect.gen(function* () {\n const documentAiService = yield* DocumentAiPlugin;\n\n return yield* createFlowNode({\n id,\n name: \"OCR\",\n description: \"Extract text from scanned documents using AI\",\n type: NodeType.process,\n nodeTypeId: OCR_OUTPUT_TYPE_ID,\n inputSchema: uploadFileSchema,\n outputSchema: ocrOutputSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n const fileUrl = file.url;\n\n // Validate input\n if (!fileUrl) {\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause: \"URL is required for OCR operation\",\n }).toEffect();\n }\n\n yield* Effect.logInfo(\n `Starting OCR for file ${file.id} with task type: ${params.taskType}`,\n );\n\n // Build context for DocumentAI plugin\n const context = {\n clientId,\n credentialId: params.credentialId,\n };\n\n // Perform OCR with error handling\n const ocrResult = yield* documentAiService\n .performOCR(\n fileUrl,\n {\n taskType: params.taskType,\n resolution: params.resolution,\n referenceText: params.referenceText,\n },\n context,\n )\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to perform OCR\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to perform OCR\",\n }).toEffect();\n }),\n ),\n );\n\n yield* Effect.logInfo(\n `Successfully completed OCR for file ${file.id}, extracted ${ocrResult.extractedText.length} characters`,\n );\n\n // Return structured OCR output (not UploadFile)\n return completeNodeExecution({\n extractedText: ocrResult.extractedText,\n format: ocrResult.format,\n taskType: params.taskType,\n confidence: ocrResult.confidence,\n flow,\n });\n });\n },\n });\n });\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n completeNodeExecution,\n createFlowNode,\n DocumentPlugin,\n NodeType,\n resolveUploadMetadata,\n STORAGE_OUTPUT_TYPE_ID,\n} from \"@uploadista/core/flow\";\nimport { uploadFileSchema } from \"@uploadista/core/types\";\nimport { UploadServer } from \"@uploadista/core/upload\";\nimport { Effect } from \"effect\";\n\nexport type SplitPdfNodeParams = {\n mode: \"range\" | \"individual\";\n startPage?: number;\n endPage?: number;\n};\n\nexport function createSplitPdfNode(id: string, params: SplitPdfNodeParams) {\n return Effect.gen(function* () {\n const documentService = yield* DocumentPlugin;\n const uploadServer = yield* UploadServer;\n\n return yield* createFlowNode({\n id,\n name: \"Split PDF\",\n description: \"Split PDF into pages or page ranges\",\n type: NodeType.process,\n nodeTypeId: STORAGE_OUTPUT_TYPE_ID,\n inputSchema: uploadFileSchema,\n outputSchema: uploadFileSchema,\n run: ({ data: file, flowId, jobId, clientId }) => {\n return Effect.gen(function* () {\n const flow = {\n flowId,\n nodeId: id,\n jobId,\n };\n\n yield* Effect.logInfo(\n `Splitting PDF file ${file.id} in ${params.mode} mode`,\n );\n\n // Read file bytes from upload server\n const fileBytes = yield* uploadServer.read(file.id, clientId);\n\n // Split PDF with error handling\n const result = yield* documentService\n .splitPdf(fileBytes, params)\n .pipe(\n Effect.catchAll((error) =>\n Effect.gen(function* () {\n yield* Effect.logError(\"Failed to split PDF\", error);\n return yield* UploadistaError.fromCode(\"FLOW_NODE_ERROR\", {\n cause:\n error instanceof Error\n ? error.message\n : \"Failed to split PDF\",\n }).toEffect();\n }),\n ),\n );\n\n const { metadata } = resolveUploadMetadata(file.metadata);\n\n if (result.mode === \"individual\") {\n // Return array of files (one per page)\n yield* Effect.logInfo(\n `Successfully split PDF into ${result.pdfs.length} individual pages`,\n );\n\n // For individual mode, we'd need to return multiple files\n // This requires special handling in the flow engine\n // For now, we'll return the first page and log a warning\n yield* Effect.logWarning(\n \"Individual page mode returns multiple files - flow engine support required\",\n );\n\n const pdfBytes = result.pdfs[0];\n\n // Create a stream from the PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(pdfBytes);\n controller.close();\n },\n });\n\n // Upload the split PDF back to the upload server\n const uploadResult = yield* uploadServer.upload(\n {\n storageId: file.storage.id,\n size: pdfBytes.byteLength,\n type: \"application/pdf\",\n fileName: `${metadata?.fileName || \"document\"}-page-1.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount: 1,\n splitMode: \"individual\",\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount: 1,\n splitMode: \"individual\",\n };\n\n return completeNodeExecution({\n ...uploadResult,\n metadata: newMetadata,\n });\n }\n\n // Range mode - return single PDF with selected pages\n const pageCount =\n params.endPage && params.startPage\n ? params.endPage - params.startPage + 1\n : 1;\n\n const pdfBytes = result.pdf;\n\n // Create a stream from the PDF bytes\n const stream = new ReadableStream({\n start(controller) {\n controller.enqueue(pdfBytes);\n controller.close();\n },\n });\n\n // Upload the split PDF back to the upload server\n const uploadResult = yield* uploadServer.upload(\n {\n storageId: file.storage.id,\n size: pdfBytes.byteLength,\n type: \"application/pdf\",\n fileName: `${metadata?.fileName || \"document\"}-pages-${params.startPage}-${params.endPage}.pdf`,\n lastModified: 0,\n metadata: JSON.stringify({\n ...metadata,\n pageCount,\n splitMode: \"range\",\n splitRange: `${params.startPage}-${params.endPage}`,\n }),\n flow,\n },\n clientId,\n stream,\n );\n\n const newMetadata = {\n ...metadata,\n pageCount,\n splitMode: \"range\",\n splitRange: `${params.startPage}-${params.endPage}`,\n };\n\n yield* Effect.logInfo(\n `Successfully split PDF to pages ${params.startPage}-${params.endPage}`,\n );\n\n return completeNodeExecution({\n ...uploadResult,\n metadata: newMetadata,\n });\n });\n },\n });\n });\n}\n"],"mappings":"oiBAmBA,SAAgB,EACd,EACA,EAAsC,EAAE,CACxC,CACA,OAAO,EAAO,IAAI,WAAa,CAC7B,IAAM,EAAkB,MAAO,EACzB,EAAoB,MAAO,EAC3B,EAAe,MAAO,EAE5B,OAAO,MAAO,EAAe,CAC3B,KACA,KA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@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/flow-documents-nodes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17-beta.2",
|
|
5
5
|
"description": "Document processing nodes for Uploadista Flow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"effect": "3.19.4",
|
|
24
24
|
"zod": "4.1.12",
|
|
25
|
-
"@uploadista/core": "0.0.
|
|
25
|
+
"@uploadista/core": "0.0.17-beta.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@effect/vitest": "0.27.0",
|
|
29
29
|
"@types/node": "24.10.1",
|
|
30
30
|
"tsdown": "0.16.5",
|
|
31
|
-
"vitest": "4.0.
|
|
32
|
-
"@uploadista/typescript-config": "0.0.
|
|
31
|
+
"vitest": "4.0.10",
|
|
32
|
+
"@uploadista/typescript-config": "0.0.17-beta.2"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "tsdown",
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
DocumentPlugin,
|
|
7
7
|
NodeType,
|
|
8
8
|
resolveUploadMetadata,
|
|
9
|
+
STORAGE_OUTPUT_TYPE_ID,
|
|
9
10
|
} from "@uploadista/core/flow";
|
|
10
11
|
import { uploadFileSchema } from "@uploadista/core/types";
|
|
11
12
|
import { UploadServer } from "@uploadista/core/upload";
|
|
@@ -31,6 +32,7 @@ export function createConvertToMarkdownNode(
|
|
|
31
32
|
description:
|
|
32
33
|
"Convert documents to Markdown format (intelligently uses OCR if needed)",
|
|
33
34
|
type: NodeType.process,
|
|
35
|
+
nodeTypeId: STORAGE_OUTPUT_TYPE_ID,
|
|
34
36
|
inputSchema: uploadFileSchema,
|
|
35
37
|
outputSchema: uploadFileSchema,
|
|
36
38
|
run: ({ data: file, flowId, jobId, clientId }) => {
|
package/src/extract-text-node.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
DocumentPlugin,
|
|
6
6
|
NodeType,
|
|
7
7
|
resolveUploadMetadata,
|
|
8
|
+
STORAGE_OUTPUT_TYPE_ID,
|
|
8
9
|
} from "@uploadista/core/flow";
|
|
9
10
|
import { uploadFileSchema } from "@uploadista/core/types";
|
|
10
11
|
import { UploadServer } from "@uploadista/core/upload";
|
|
@@ -25,6 +26,7 @@ export function createExtractTextNode(
|
|
|
25
26
|
name: "Extract Text",
|
|
26
27
|
description: "Extract text from searchable PDF documents",
|
|
27
28
|
type: NodeType.process,
|
|
29
|
+
nodeTypeId: STORAGE_OUTPUT_TYPE_ID,
|
|
28
30
|
inputSchema: uploadFileSchema,
|
|
29
31
|
outputSchema: uploadFileSchema,
|
|
30
32
|
run: ({ data: file, flowId, jobId, clientId }) => {
|
|
@@ -35,9 +37,7 @@ export function createExtractTextNode(
|
|
|
35
37
|
jobId,
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
yield* Effect.logInfo(
|
|
39
|
-
`Extracting text from PDF file ${file.id}`,
|
|
40
|
-
);
|
|
40
|
+
yield* Effect.logInfo(`Extracting text from PDF file ${file.id}`);
|
|
41
41
|
|
|
42
42
|
// Read file bytes from upload server
|
|
43
43
|
const fileBytes = yield* uploadServer.read(file.id, clientId);
|
package/src/merge-pdf-node.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
DocumentPlugin,
|
|
6
6
|
NodeType,
|
|
7
7
|
resolveUploadMetadata,
|
|
8
|
+
STORAGE_OUTPUT_TYPE_ID,
|
|
8
9
|
} from "@uploadista/core/flow";
|
|
9
10
|
import { uploadFileSchema } from "@uploadista/core/types";
|
|
10
11
|
import { UploadServer } from "@uploadista/core/upload";
|
|
@@ -31,6 +32,7 @@ export function createMergePdfNode(
|
|
|
31
32
|
name: "Merge PDFs",
|
|
32
33
|
description: "Merge multiple PDF documents into one",
|
|
33
34
|
type: NodeType.process,
|
|
35
|
+
nodeTypeId: STORAGE_OUTPUT_TYPE_ID,
|
|
34
36
|
inputSchema: multipleFilesSchema,
|
|
35
37
|
outputSchema: uploadFileSchema,
|
|
36
38
|
run: ({ data: files, flowId, jobId, clientId }) => {
|
|
@@ -44,7 +46,8 @@ export function createMergePdfNode(
|
|
|
44
46
|
// Validate that we have an array of files
|
|
45
47
|
if (!Array.isArray(files)) {
|
|
46
48
|
return yield* UploadistaError.fromCode("FLOW_NODE_ERROR", {
|
|
47
|
-
cause:
|
|
49
|
+
cause:
|
|
50
|
+
"Merge PDF node requires an array of files from a Merge utility node",
|
|
48
51
|
}).toEffect();
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -65,14 +68,15 @@ export function createMergePdfNode(
|
|
|
65
68
|
|
|
66
69
|
// Sum up page counts if available
|
|
67
70
|
const fileMetadata = resolveUploadMetadata(file.metadata).metadata;
|
|
68
|
-
if (
|
|
71
|
+
if (
|
|
72
|
+
fileMetadata?.pageCount &&
|
|
73
|
+
typeof fileMetadata.pageCount === "number"
|
|
74
|
+
) {
|
|
69
75
|
totalPages += fileMetadata.pageCount;
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
yield* Effect.logInfo(
|
|
74
|
-
`Merging ${files.length} PDF files`,
|
|
75
|
-
);
|
|
79
|
+
yield* Effect.logInfo(`Merging ${files.length} PDF files`);
|
|
76
80
|
|
|
77
81
|
// Merge PDFs with error handling
|
|
78
82
|
const mergedPdf = yield* documentService
|
package/src/ocr-node.ts
CHANGED
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
createFlowNode,
|
|
5
5
|
DocumentAiPlugin,
|
|
6
6
|
NodeType,
|
|
7
|
-
|
|
7
|
+
OCR_OUTPUT_TYPE_ID,
|
|
8
8
|
type OcrResolution,
|
|
9
|
-
|
|
9
|
+
type OcrTaskType,
|
|
10
|
+
ocrOutputSchema,
|
|
10
11
|
} from "@uploadista/core/flow";
|
|
11
12
|
import { uploadFileSchema } from "@uploadista/core/types";
|
|
12
13
|
import { Effect } from "effect";
|
|
@@ -18,10 +19,7 @@ export type OcrNodeParams = {
|
|
|
18
19
|
referenceText?: string;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
export function createOcrNode(
|
|
22
|
-
id: string,
|
|
23
|
-
params: OcrNodeParams,
|
|
24
|
-
) {
|
|
22
|
+
export function createOcrNode(id: string, params: OcrNodeParams) {
|
|
25
23
|
return Effect.gen(function* () {
|
|
26
24
|
const documentAiService = yield* DocumentAiPlugin;
|
|
27
25
|
|
|
@@ -30,8 +28,9 @@ export function createOcrNode(
|
|
|
30
28
|
name: "OCR",
|
|
31
29
|
description: "Extract text from scanned documents using AI",
|
|
32
30
|
type: NodeType.process,
|
|
31
|
+
nodeTypeId: OCR_OUTPUT_TYPE_ID,
|
|
33
32
|
inputSchema: uploadFileSchema,
|
|
34
|
-
outputSchema:
|
|
33
|
+
outputSchema: ocrOutputSchema,
|
|
35
34
|
run: ({ data: file, flowId, jobId, clientId }) => {
|
|
36
35
|
return Effect.gen(function* () {
|
|
37
36
|
const flow = {
|
|
@@ -68,7 +67,7 @@ export function createOcrNode(
|
|
|
68
67
|
resolution: params.resolution,
|
|
69
68
|
referenceText: params.referenceText,
|
|
70
69
|
},
|
|
71
|
-
context
|
|
70
|
+
context,
|
|
72
71
|
)
|
|
73
72
|
.pipe(
|
|
74
73
|
Effect.catchAll((error) =>
|
|
@@ -84,24 +83,16 @@ export function createOcrNode(
|
|
|
84
83
|
),
|
|
85
84
|
);
|
|
86
85
|
|
|
87
|
-
const { metadata } = resolveUploadMetadata(file.metadata);
|
|
88
|
-
|
|
89
|
-
// Add OCR results to metadata
|
|
90
|
-
const newMetadata = {
|
|
91
|
-
...file.metadata,
|
|
92
|
-
...metadata,
|
|
93
|
-
ocrText: ocrResult.extractedText,
|
|
94
|
-
ocrFormat: ocrResult.format,
|
|
95
|
-
ocrTaskType: params.taskType,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
86
|
yield* Effect.logInfo(
|
|
99
87
|
`Successfully completed OCR for file ${file.id}, extracted ${ocrResult.extractedText.length} characters`,
|
|
100
88
|
);
|
|
101
89
|
|
|
90
|
+
// Return structured OCR output (not UploadFile)
|
|
102
91
|
return completeNodeExecution({
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
extractedText: ocrResult.extractedText,
|
|
93
|
+
format: ocrResult.format,
|
|
94
|
+
taskType: params.taskType,
|
|
95
|
+
confidence: ocrResult.confidence,
|
|
105
96
|
flow,
|
|
106
97
|
});
|
|
107
98
|
});
|
package/src/split-pdf-node.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
DocumentPlugin,
|
|
6
6
|
NodeType,
|
|
7
7
|
resolveUploadMetadata,
|
|
8
|
+
STORAGE_OUTPUT_TYPE_ID,
|
|
8
9
|
} from "@uploadista/core/flow";
|
|
9
10
|
import { uploadFileSchema } from "@uploadista/core/types";
|
|
10
11
|
import { UploadServer } from "@uploadista/core/upload";
|
|
@@ -16,10 +17,7 @@ export type SplitPdfNodeParams = {
|
|
|
16
17
|
endPage?: number;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export function createSplitPdfNode(
|
|
20
|
-
id: string,
|
|
21
|
-
params: SplitPdfNodeParams,
|
|
22
|
-
) {
|
|
20
|
+
export function createSplitPdfNode(id: string, params: SplitPdfNodeParams) {
|
|
23
21
|
return Effect.gen(function* () {
|
|
24
22
|
const documentService = yield* DocumentPlugin;
|
|
25
23
|
const uploadServer = yield* UploadServer;
|
|
@@ -29,6 +27,7 @@ export function createSplitPdfNode(
|
|
|
29
27
|
name: "Split PDF",
|
|
30
28
|
description: "Split PDF into pages or page ranges",
|
|
31
29
|
type: NodeType.process,
|
|
30
|
+
nodeTypeId: STORAGE_OUTPUT_TYPE_ID,
|
|
32
31
|
inputSchema: uploadFileSchema,
|
|
33
32
|
outputSchema: uploadFileSchema,
|
|
34
33
|
run: ({ data: file, flowId, jobId, clientId }) => {
|
|
@@ -94,7 +93,7 @@ export function createSplitPdfNode(
|
|
|
94
93
|
storageId: file.storage.id,
|
|
95
94
|
size: pdfBytes.byteLength,
|
|
96
95
|
type: "application/pdf",
|
|
97
|
-
fileName: `${metadata?.fileName ||
|
|
96
|
+
fileName: `${metadata?.fileName || "document"}-page-1.pdf`,
|
|
98
97
|
lastModified: 0,
|
|
99
98
|
metadata: JSON.stringify({
|
|
100
99
|
...metadata,
|
|
@@ -120,9 +119,10 @@ export function createSplitPdfNode(
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
// Range mode - return single PDF with selected pages
|
|
123
|
-
const pageCount =
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
const pageCount =
|
|
123
|
+
params.endPage && params.startPage
|
|
124
|
+
? params.endPage - params.startPage + 1
|
|
125
|
+
: 1;
|
|
126
126
|
|
|
127
127
|
const pdfBytes = result.pdf;
|
|
128
128
|
|
|
@@ -140,7 +140,7 @@ export function createSplitPdfNode(
|
|
|
140
140
|
storageId: file.storage.id,
|
|
141
141
|
size: pdfBytes.byteLength,
|
|
142
142
|
type: "application/pdf",
|
|
143
|
-
fileName: `${metadata?.fileName ||
|
|
143
|
+
fileName: `${metadata?.fileName || "document"}-pages-${params.startPage}-${params.endPage}.pdf`,
|
|
144
144
|
lastModified: 0,
|
|
145
145
|
metadata: JSON.stringify({
|
|
146
146
|
...metadata,
|