← All @molecule/* packages · App templates
@molecule/app-ai-copilot-defaultProvider bond · ai-copilot · App (browser) · v1.0.1 · Apache-2.0
Default HTTP/SSE copilot provider for inline AI suggestions
npm install @molecule/app-ai-copilot-defaultnpm · Source on GitHub · Implements @molecule/app-ai-copilot
@molecule/app-ai-copilot-default is a provider bond on the app (browser) side: it implements the ai-copilot core interface (@molecule/app-ai-copilot) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setProvider } from '@molecule/app-ai-copilot'
import { provider } from '@molecule/app-ai-copilot-default'
setProvider(provider) // at startup — lazy; same-origin base URL, no config needed
// setProvider(createProvider({ baseUrl, headers })) to customizeWorks with: @molecule/app-ai-copilot, @molecule/app-i18n
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Default ai-copilot provider for molecule.dev — HTTP/SSE inline AI suggestions from YOUR backend.
import { setProvider } from '@molecule/app-ai-copilot'
import { provider } from '@molecule/app-ai-copilot-default'
setProvider(provider) // at startup — lazy; same-origin base URL, no config needed
// setProvider(createProvider({ baseUrl, headers })) to customize
provider
npm install @molecule/app-ai-copilot-default @molecule/app-ai-copilot @molecule/app-i18n
DefaultCopilotConfigConfiguration for the default HTTP-based copilot provider.
interface DefaultCopilotConfig {
/** Base URL for API requests. Defaults to `''` (same origin). */
baseUrl?: string
/** Custom headers to include in every request. */
headers?: Record<string, string>
}
DefaultCopilotProviderHTTP/SSE-based copilot provider. Sends document context via POST and reads SSE streams for real-time inline suggestions.
createProvider(config)Creates a DefaultCopilotProvider instance.
function createProvider(config?: DefaultCopilotConfig): DefaultCopilotProvider
config — Optional provider-level configuration (base URL, headers).Returns: A new DefaultCopilotProvider.
providerThe provider implementation — the fleet-standard typed provider const.
Wire it once at startup: setProvider(provider) from @molecule/app-ai-copilot.
It is a lazy proxy: construction is deferred to the first property access, so
importing this module never throws and needs no config up front. Use
createProvider(config) instead when you need to pass a base URL or headers.
const provider: AICopilotProvider
Implements @molecule/app-ai-copilot interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/app-ai-copilot'
import { provider } from '@molecule/app-ai-copilot-default'
export function setupAiCopilotDefault(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/app-ai-copilot ^1.0.1@molecule/app-i18n ^1.0.1@molecule/app-ai-copilot@molecule/app-i18nServer contract: getSuggestions POSTs { prefix, suffix, language, filePath?, cursorLine?, cursorColumn?, model?, maxSuggestions?, projectId? } to config.endpoint and reads an SSE stream of
data: <CopilotEvent JSON> lines. acceptSuggestion /
rejectSuggestion POST { suggestionId, action: 'accept' | 'reject', text?, metadata } to ${config.endpoint}/feedback — best-effort, errors
are swallowed, so implement the route (or expect silent no-ops).
getSuggestions auto-aborts the previous in-flight request; still call
abort() on keystrokes you debounce away (see @molecule/app-ai-copilot).
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
getSuggestions(context, config, onEvent)
and the returned CopilotSuggestion.text renders as ghost/inline text
anchored to the suggestion's range (CopilotRange) — or the caret when
range is omitted — never at a stale or wrong offset.suggestion.text
at that range/caret and nothing stale, and fires
acceptSuggestion(suggestion, config); the buffer holds only the accepted
text with no leftover ghost preview.abort() so the in-flight request is cancelled before the next
getSuggestions — a late-arriving stale suggestion never lands at the
moved cursor, and rejectSuggestion(suggestion, config) reports the miss.CopilotContext (prefix/suffix/language around the cursor), so
editing the surrounding code visibly changes what gets proposed.onEvent { type: 'error' }) fails quietly — no
ghost text, no thrown exception in the editor, the buffer is untouched, and
the user can keep typing.CopilotRange (it never overwrites unrelated lines), and suggestion.text
is treated as plain model output — inserted as text, never eval'd or run as
trusted code by the copilot itself.