MCPcopy Create free account
hub / github.com/Noumena-Network/code / stripAdvisorBlocks

Function stripAdvisorBlocks

src/utils/messages.ts:5566–5594  ·  view source on GitHub ↗
(
  messages: (UserMessage | AssistantMessage)[],
)

Source from the content-addressed store, hash-verified

5564 * with name "advisor" unless the advisor beta header is present.
5565 */
5566export function stripAdvisorBlocks(
5567 messages: (UserMessage | AssistantMessage)[],
5568): (UserMessage | AssistantMessage)[] {
5569 let changed = false
5570 const result = messages.map(msg => {
5571 if (msg.type !== 'assistant') return msg
5572 const content = msg.message.content
5573 const filtered = content.filter(b => !isAdvisorBlock(b))
5574 if (filtered.length === content.length) return msg
5575 changed = true
5576 if (
5577 filtered.length === 0 ||
5578 filtered.every(
5579 b =>
5580 b.type === 'thinking' ||
5581 b.type === 'redacted_thinking' ||
5582 (b.type === 'text' && (!b.text || !b.text.trim())),
5583 )
5584 ) {
5585 filtered.push({
5586 type: 'text' as const,
5587 text: '[Advisor response]',
5588 citations: [],
5589 })
5590 }
5591 return { ...msg, message: { ...msg.message, content: filtered } }
5592 })
5593 return changed ? result : messages
5594}
5595
5596export function wrapCommandText(
5597 raw: string,

Callers 1

queryModelFunction · 0.85

Calls 1

isAdvisorBlockFunction · 0.85

Tested by

no test coverage detected