Skip to content

feat: mid-sized structured asset creator workflow #117

Description

@droarty

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-foundsaveIntent: 'create', show "Confirm Schema"
  • asset-existsuploadStatus: '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-importpersist-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions