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