( prompt: string, markdownContent: string, signal: AbortSignal, isNonInteractiveSession: boolean, isPreapprovedDomain: boolean, )
| 482 | } |
| 483 | |
| 484 | export async function applyPromptToMarkdown( |
| 485 | prompt: string, |
| 486 | markdownContent: string, |
| 487 | signal: AbortSignal, |
| 488 | isNonInteractiveSession: boolean, |
| 489 | isPreapprovedDomain: boolean, |
| 490 | ): Promise<string> { |
| 491 | // Truncate content to avoid "Prompt is too long" errors from the secondary model |
| 492 | const truncatedContent = |
| 493 | markdownContent.length > MAX_MARKDOWN_LENGTH |
| 494 | ? markdownContent.slice(0, MAX_MARKDOWN_LENGTH) + |
| 495 | '\n\n[Content truncated due to length...]' |
| 496 | : markdownContent |
| 497 | |
| 498 | const modelPrompt = makeSecondaryModelPrompt( |
| 499 | truncatedContent, |
| 500 | prompt, |
| 501 | isPreapprovedDomain, |
| 502 | ) |
| 503 | const assistantMessage = await queryHaiku({ |
| 504 | systemPrompt: asSystemPrompt([]), |
| 505 | userPrompt: modelPrompt, |
| 506 | signal, |
| 507 | options: { |
| 508 | querySource: 'web_fetch_apply', |
| 509 | agents: [], |
| 510 | isNonInteractiveSession, |
| 511 | hasAppendSystemPrompt: false, |
| 512 | mcpTools: [], |
| 513 | }, |
| 514 | }) |
| 515 | |
| 516 | // We need to bubble this up, so that the tool call throws, causing us to return |
| 517 | // an is_error tool_use block to the server, and render a red dot in the UI. |
| 518 | if (signal.aborted) { |
| 519 | throw new AbortError() |
| 520 | } |
| 521 | |
| 522 | const { content } = assistantMessage.message |
| 523 | if (content.length > 0) { |
| 524 | const contentBlock = content[0] |
| 525 | if ('text' in contentBlock!) { |
| 526 | return contentBlock.text |
| 527 | } |
| 528 | } |
| 529 | return 'No response from model' |
| 530 | } |
no test coverage detected