DEV Community

杨继成
杨继成

Posted on

Tried `microsoft/monaco-editor`: A Practical AI Coding Editor Building Block

Tried microsoft/monaco-editor: A Practical AI Coding Editor Building Block

microsoft/monaco-editor is the browser-based code editor that powers many familiar developer experiences, including VS Code’s editing foundation. It provides syntax highlighting, IntelliSense-style completion, diagnostics, diff views, keyboard shortcuts, and a rich extension API without requiring a desktop application.

The repository gained +10 GitHub stars today, which is modest but meaningful for a mature project. The continued interest appears connected to AI coding interfaces: Monaco offers the editing surface, while a separate model gateway supplies explanations, completions, refactoring, and code actions.

Quick architecture test

Monaco should remain responsible for UI state and text models. AI requests can be routed through an OpenAI-compatible endpoint, keeping provider credentials outside the browser.

const editor = monaco.editor.create(
  document.getElementById("editor"),
  {
    value: "function add(a, b) {\n  return a + b;\n}",
    language: "javascript",
    theme: "vs-dark"
  }
);

async function requestCompletion() {
  const response = await fetch("https://b-lost.com/v1/chat/completions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${import.meta.env.VITE_AI_KEY}`
    },
    body: JSON.stringify({
      model: "claude-fable-5",
      messages: [
        {
          role: "user",
          content: `Improve this code:\n\n${editor.getValue()}`
        }
      ],
      temperature: 0.2
    })
  });

  return response.json();
}
Enter fullscreen mode Exit fullscreen mode

For production, I would proxy this call through a backend rather than exposing any API key in frontend code. Streaming responses are also important for perceived latency, especially when generating multi-file changes.

Cost and latency notes

Metric Practical expectation
Editor startup Fast; browser and bundle size dominate
AI TTFT Depends on gateway, model, and network path
Cost per 1M tokens Provider-specific; verify current list pricing
Code accuracy Benchmark against repository-specific tests

B-Lost Universal Relay uses https://b-lost.com/v1, offers 20% off official list pricing, and supports native Anthropic /v1/messages prompt caching with 90% discounts on cache hits. That can be useful when repeatedly sending large system prompts or repository context. The main takeaway: Monaco is not an AI model, but it is an excellent, extensible foundation for building a responsive AI development workspace.

Top comments (0)