MCPcopy Index your code
hub / github.com/coder/mux / extractModelSection

Function extractModelSection

src/node/utils/main/markdown.ts:132–166  ·  view source on GitHub ↗
(markdown: string, modelId: string)

Source from the content-addressed store, hash-verified

130 * would be misleading.
131 */
132export function extractModelSection(markdown: string, modelId: string): string | null {
133 if (!markdown || !modelId) return null;
134
135 const headingPattern = /^model:\s*(.+)$/i;
136
137 const compileRegex = (pattern: string): RegExp | null => {
138 const trimmed = pattern.trim();
139 if (!trimmed) return null;
140
141 if (trimmed.startsWith("/") && trimmed.lastIndexOf("/") > 0) {
142 const lastSlash = trimmed.lastIndexOf("/");
143 const source = trimmed.slice(1, lastSlash);
144 const flags = trimmed.slice(lastSlash + 1);
145 try {
146 return new RegExp(source, flags || undefined);
147 } catch {
148 return null;
149 }
150 }
151
152 try {
153 return new RegExp(trimmed, "i");
154 } catch {
155 return null;
156 }
157 };
158
159 const matches = extractSectionsByHeading(markdown, (headingText) => {
160 const match = headingPattern.exec(headingText);
161 if (!match) return false;
162 const regex = compileRegex(match[1] ?? "");
163 return Boolean(regex?.test(modelId));
164 });
165 return joinMatchedSections(matches);
166}
167
168/**
169 * Extract the content under every heading titled "Tool: <tool_name>" (case-insensitive),

Callers 2

markdown.test.tsFile · 0.90
buildSystemMessageFunction · 0.90

Calls 5

extractSectionsByHeadingFunction · 0.85
compileRegexFunction · 0.85
joinMatchedSectionsFunction · 0.85
testMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected