File tree Expand file tree Collapse file tree
soulfield-v2-mvp/src/middleware Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // middleware: lensEnforcer.ts
2+ export function lensEnforcer ( req , res , next ) {
3+ res . on ( 'finish' , ( ) => { } ) ; // no-op
4+ res . _send = res . send ;
5+ res . send = ( body ) => {
6+ const out = typeof body === 'string' ? JSON . parse ( body ) : body ;
7+ const lens = out ?. meta ?. lens ;
8+ const tags = out ?. sentences ?. flatMap ( s => s . tags || [ ] ) || out ?. tags || [ ] ;
9+ const hasFacts = tags . some ( t => t . type === 'fact' ) ;
10+ const unlabeledIntuition = out ?. text && hasFacts && ! tags . some ( t => t . type !== 'fact' ) ;
11+
12+ if ( ! lens || ! Array . isArray ( lens . passed ) || lens . error || unlabeledIntuition ) {
13+ out . prefix = '[WARN]' ;
14+ out . meta = out . meta || { } ;
15+ out . meta . lens = lens || { error : 'lens-missing-or-unlabeled' } ;
16+ out . policy = { route : 'AureaReview' } ;
17+ return res . _send ( JSON . stringify ( out ) ) ;
18+ }
19+ return res . _send ( JSON . stringify ( out ) ) ;
20+ } ;
21+ next ( ) ;
22+ }
You can’t perform that action at this time.
0 commit comments