MCPcopy
hub / github.com/codeaashu/claude-code / applyPromptToMarkdown

Function applyPromptToMarkdown

src/tools/WebFetchTool/utils.ts:521–567  ·  view source on GitHub ↗
(
  prompt: string,
  markdownContent: string,
  signal: AbortSignal,
  isNonInteractiveSession: boolean,
  isPreapprovedDomain: boolean,
)

Source from the content-addressed store, hash-verified

519}
520
521export async function applyPromptToMarkdown(
522 prompt: string,
523 markdownContent: string,
524 signal: AbortSignal,
525 isNonInteractiveSession: boolean,
526 isPreapprovedDomain: boolean,
527): Promise<string> {
528 // Truncate content to avoid "Prompt is too long" errors from the secondary model
529 const truncatedContent =
530 markdownContent.length > MAX_MARKDOWN_LENGTH
531 ? markdownContent.slice(0, MAX_MARKDOWN_LENGTH) +
532 '\n\n[Content truncated due to length...]'
533 : markdownContent
534
535 const modelPrompt = makeSecondaryModelPrompt(
536 truncatedContent,
537 prompt,
538 isPreapprovedDomain,
539 )
540 const assistantMessage = await queryHaiku({
541 systemPrompt: asSystemPrompt([]),
542 userPrompt: modelPrompt,
543 signal,
544 options: {
545 querySource: 'web_fetch_apply',
546 agents: [],
547 isNonInteractiveSession,
548 hasAppendSystemPrompt: false,
549 mcpTools: [],
550 },
551 })
552
553 // We need to bubble this up, so that the tool call throws, causing us to return
554 // an is_error tool_use block to the server, and render a red dot in the UI.
555 if (signal.aborted) {
556 throw new AbortError()
557 }
558
559 const { content } = assistantMessage.message
560 if (content.length > 0) {
561 const contentBlock = content[0]
562 if ('text' in contentBlock!) {
563 return contentBlock.text
564 }
565 }
566 return 'No response from model'
567}
568

Callers 1

callFunction · 0.85

Calls 3

makeSecondaryModelPromptFunction · 0.85
queryHaikuFunction · 0.85
asSystemPromptFunction · 0.85

Tested by

no test coverage detected