Plan: Mid-Sized Structured Asset Creator — Configurable Workflow
Build a generic mid-sized-structured-asset-creator workflow. Users upload a PDF, then engage in a multi-turn chat where Claude: (1) analyzes the document structure, (2) collects an asset name and category, (3) proposes and refines a schema through conversation, and (4) extracts all records once the schema is confirmed. Both the schema and data are persisted together in a StructuredAsset MongoDB model.
Architecture
Phase 1 — Upload
- HTTP
POST /api/documents/:id/upload (multer)
- Files API: upload PDF → store fileId in state
- AI file-chat: analyze structure, ask for name + category, propose schema
Phase 2 — Schema discussion (multi-turn chat)
- New
file-chat AI step type in workflow engine
- Each user message continues the conversation with the PDF in context
- Claude proposes/refines schema, triggers
schema-proposed response type
Phase 2b — Version check (immediately after schema-proposed)
schema-proposed handler step 2: check-asset-exists query
asset-not-found → saveIntent: 'create', show "Confirm Schema"
asset-exists → uploadStatus: 'version-check', show 3-choice conflict card:
- Replace v{N}
- Save as v{N+1}
- Change name / category (re-opens chat, loops back)
Phase 3 — Extraction
- New
file-extract AI step type
- One-shot extraction using confirmed schema
Phase 4 — Accept / Reject
accept-import → persist-structured-asset (reads saveIntent — no second conflict check needed)
reject-import → back to schema-proposed phase
New Files
libs/shared-types/src/structured-asset.types.ts
apps/api/src/app/models/structured-asset.model.ts
apps/api/src/app/services/fileExtract.service.ts
apps/api/src/app/routes/upload.routes.ts
apps/api/src/app/config/workflows/mid-sized-structured-asset-creator.json
apps/web/src/app/components/ChatUploadPanel.tsx
apps/web/src/app/components/JsonViewer.tsx
Modified Files
WorkflowEngine.ts — extend AiStepConfig with type, fileIdPath, historyPath, userMessagePath, schemaPath
AIEventManager.ts — route file-chat / file-extract to new service methods
EventProcessorWorker.ts — resolve file context and pass to AI manager
QueryExecutor.ts — add check-asset-exists and persist-structured-asset queries
document.model.ts — add mid-sized-structured-asset-creator to enum
layoutRegistry.ts — register chatUploadPanel and jsonViewer
app.ts — register upload route
Data Model: StructuredAsset
name, category, assetVersion (compound unique index)
schema (embedded JSON Schema + description)
data (array of extracted records)
recordCount, sourceFileName, sourceDocumentId, timestamps
Dependencies
multer + @types/multer (new)
@anthropic-ai/sdk already installed
Plan: Mid-Sized Structured Asset Creator — Configurable Workflow
Build a generic
mid-sized-structured-asset-creatorworkflow. Users upload a PDF, then engage in a multi-turn chat where Claude: (1) analyzes the document structure, (2) collects an asset name and category, (3) proposes and refines a schema through conversation, and (4) extracts all records once the schema is confirmed. Both the schema and data are persisted together in aStructuredAssetMongoDB model.Architecture
Phase 1 — Upload
POST /api/documents/:id/upload(multer)Phase 2 — Schema discussion (multi-turn chat)
file-chatAI step type in workflow engineschema-proposedresponse typePhase 2b — Version check (immediately after schema-proposed)
schema-proposedhandler step 2:check-asset-existsqueryasset-not-found→saveIntent: 'create', show "Confirm Schema"asset-exists→uploadStatus: 'version-check', show 3-choice conflict card:Phase 3 — Extraction
file-extractAI step typePhase 4 — Accept / Reject
accept-import→persist-structured-asset(readssaveIntent— no second conflict check needed)reject-import→ back to schema-proposed phaseNew Files
libs/shared-types/src/structured-asset.types.tsapps/api/src/app/models/structured-asset.model.tsapps/api/src/app/services/fileExtract.service.tsapps/api/src/app/routes/upload.routes.tsapps/api/src/app/config/workflows/mid-sized-structured-asset-creator.jsonapps/web/src/app/components/ChatUploadPanel.tsxapps/web/src/app/components/JsonViewer.tsxModified Files
WorkflowEngine.ts— extendAiStepConfigwithtype,fileIdPath,historyPath,userMessagePath,schemaPathAIEventManager.ts— routefile-chat/file-extractto new service methodsEventProcessorWorker.ts— resolve file context and pass to AI managerQueryExecutor.ts— addcheck-asset-existsandpersist-structured-assetqueriesdocument.model.ts— addmid-sized-structured-asset-creatorto enumlayoutRegistry.ts— registerchatUploadPanelandjsonViewerapp.ts— register upload routeData Model: StructuredAsset
name,category,assetVersion(compound unique index)schema(embedded JSON Schema + description)data(array of extracted records)recordCount,sourceFileName,sourceDocumentId, timestampsDependencies
multer+@types/multer(new)@anthropic-ai/sdkalready installed