Drafts Action Script to Format as MD Outline

I use the macOS/iOS app Drafts to capture stuff that goes into Logseq later on. I thought that I could improve the workflow by writing a Drafts Action script that calls on Claude AI to re-format my notes as markdown outlines before pasting into Logseq. This script does some extra steps as well. For instance, if the note is a large block of text, it will make a summary header element and then nest the note under that. If the note is in Chinese, it will make the summary in English.

// Get the entire draft content
const draftContent = editor.getText();

// Setup model name to use
const models = AnthropicAI.knownModels();
const model = models[0]; // Use the first available model (likely Claude)

// Build the prompt with instructions
let chatPrompt = `
Format this text into a Logseq-compatible Markdown outline:
1. Create ONE parent element with a brief title/summary (just a few words)
2. Convert each line of the original text to a separate child bullet point
3. Preserve the exact content of each line
4. Do not add categories, headers, or additional structure
5. If text is in Chinese, add an English title/summary as the parent
6. Use Logseq markdown format:
   - Parent item (with a dash)
     - Child item (indented with a dash)
     - Child item

Here's the text to format:
${draftContent}
`;

// Send to Claude
let ai = new AnthropicAI();
let formattedText = ai.quickPrompt(chatPrompt, {"model": model});

// If we got no reply, cancel
if (!formattedText || formattedText.length == 0) {
  app.displayErrorMessage("Claude did not return any formatted text");
  context.fail();
} else {
  // Replace the draft content with the formatted text
  editor.setText(formattedText);

  // Display success message
  app.displayInfoMessage("Draft successfully converted to Logseq format");
}