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

Function prependPathRefs

src/bridge/inboundAttachments.ts:143–162  ·  view source on GitHub ↗
(
  content: string | Array<ContentBlockParam>,
  prefix: string,
)

Source from the content-addressed store, hash-verified

141 * block[0] means they're silently ignored for [text, image] content.
142 */
143export function prependPathRefs(
144 content: string | Array<ContentBlockParam>,
145 prefix: string,
146): string | Array<ContentBlockParam> {
147 if (!prefix) return content
148 if (typeof content === 'string') return prefix + content
149 const i = content.findLastIndex(b => b.type === 'text')
150 if (i !== -1) {
151 const b = content[i]!
152 if (b.type === 'text') {
153 return [
154 ...content.slice(0, i),
155 { ...b, text: prefix + b.text },
156 ...content.slice(i + 1),
157 ]
158 }
159 }
160 // No text block — append one at the end so it's last.
161 return [...content, { type: 'text', text: prefix.trimEnd() }]
162}
163
164/**
165 * Convenience: extract + resolve + prepend. No-op when the message has no

Callers 2

resolveAndPrependFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected