fix(knowledge): serialize chunk date tags on the internal chunk read

Merged
WA
14d ago
+137-4

Summary

  • GET /api/knowledge/[id]/documents/[documentId]/chunks/[chunkId] returned 500 for any chunk whose date1/date2 tag was set: the chunk context loads the full embedding row (date slots are Date), but toInternalKnowledgeChunk only serialized createdAt/updatedAt before parsing with chunkDataSchema, whose date slots are strings
  • toInternalKnowledgeChunk now serializes date1/date2 with the same helper the document mapper uses, only when the row carries them, so the projected list/create/update responses keep their exact keys
  • Dropped the chunk as ChunkData cast in resolveActiveKnowledgeChunkContext and typed the context chunk as the real row, which is what hid the Date slots from the compiler
  • v2 chunk read is unchanged: toV2KnowledgeChunk projects explicit fields and never included date slots

Type of Change

  • Bug fix

Testing

  • New chunk-read-tags.integration.ts runs the real read/list use cases against Postgres with a date-tagged chunk: the internal read failed with the exact expected string, received Date error before the fix and passes after; the listing keeps its key set and the v2 projection is byte-identical
  • Existing knowledge context/chunk/internal-route/v2 unit tests pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)