Web API

Import browser-only helpers from @theaiplatform/miniapp-sdk/web. Use this entry point only in a webview target because editor and theme helpers depend on browser APIs.

Platform Compatibility

app is a browser-oriented alias for the public sdk export. getPlatform returns that same lazy proxy as MiniAppPlatform, which is an alias of MiniAppPlatformApi.

import {
  getPlatform,
  platformSatisfiesApp,
} from '@theaiplatform/miniapp-sdk/web';

const platform = getPlatform();
const canOpenEditor = platformSatisfiesApp(platform, ['editorView']);

platformSatisfiesApp recognizes the public editorView and hostHttpRequest feature names. Unknown requirements fail closed. Prefer importing sdk from /sdk in shared target code; the web names are useful when all code in a module is browser-only.

Open a Project in the Editor

openEditorProject accepts OpenEditorProjectOptions. It sends an authenticated request from the exact miniapp frame to its parent host and resolves after the host accepts the action.

import { openEditorProject } from '@theaiplatform/miniapp-sdk/web';

await openEditorProject({
  conversationId,
  projectId,
  mode: 'embedded',
  files: [{ path: 'README.md', selection: { line: 1, column: 1 } }],
});

The call rejects when the frame identity, document identity, host origin, host authority, input, or response is unavailable. Handle the error in the surface without retrying indefinitely.

Specialist Events

SpecialistEvent is the union of SpecialistTurnCompletedEvent and SpecialistTurnErrorEvent. Use its type discriminator before reading outcome-specific fields.

function handleSpecialistEvent(event: SpecialistEvent) {
  if (event.type === 'turnCompleted') {
    renderParts(event.parts ?? []);
  } else {
    renderError(event.error ?? 'The specialist turn failed.');
  }
}

These are event payload types, not subscriptions. Receive them through the event source provided by your surface or contribution contract.

Appearance Synchronization

MiniAppTheme is either light or dark. getMiniAppThemeFromSearch reads the initial theme from a query string or URLSearchParams, while applyMiniAppTheme writes it to the current document.

installMiniAppThemeSync accepts InstallMiniAppThemeSyncOptions, applies the initial theme, listens for supported host theme events, and returns a cleanup function.

import { installMiniAppThemeSync } from '@theaiplatform/miniapp-sdk/web';

const stopThemeSync = installMiniAppThemeSync();

export function unmount() {
  stopThemeSync();
}

Live theme messages are accepted only from the exact parent window and concrete host origin selected for the frame. If no exact origin is available, the initial query-string theme is still applied but no listener is installed. Theme data is cosmetic: it never conveys host authority, identity, permission, or trusted application state.

Call the returned cleanup function during every unmount. An unsupported theme value is ignored; browser-less calls return a no-op cleanup function.

UI component consumers should use installMiniAppAppearanceSync. It preserves the theme behavior and also applies the host's bounded appUiScale as --app-font-size on the document root. Valid UI scales are integers from MINIAPP_UI_SCALE_MIN through MINIAPP_UI_SCALE_MAX; missing or invalid input uses MINIAPP_UI_SCALE_DEFAULT.

import { installMiniAppAppearanceSync } from '@theaiplatform/miniapp-sdk/web';

const stopAppearanceSync = installMiniAppAppearanceSync();

installMiniAppThemeSync remains available for miniapps that need only theme synchronization.

Public Export Contract

ExportPurposeInputs and resultLifecycle and errorsWorking example
MiniAppPlatformApiRe-exports the complete public host API type for browser modules.Describes the API proxy returned by getPlatform and exposed as app.Type only; property use still requires an installed host session.Platform compatibility
appProvides the browser-oriented alias of the public SDK proxy.Exposes MiniAppPlatformApi and its documented operation results.Import is safe; property reads outside a supported host throw.Platform compatibility
MiniAppPlatformNames the browser view of MiniAppPlatformApi.Used as the input type for browser capability checks.Type only; it does not widen the public API or grant authority.Platform compatibility
getPlatformReturns the same lazy public proxy exported as app.Takes no arguments and returns MiniAppPlatform.The call is import-safe; later property reads can throw without a host.Platform compatibility
platformSatisfiesAppChecks documented optional browser feature flags.Accepts a platform and feature names; returns a boolean.Unknown names and values other than true fail closed without throwing.Platform compatibility
SpecialistTurnCompletedEventDescribes a completed specialist notification.Contains channel, specialist, parts, and optional terminal metadata.Type only; validate IDs and the event source before applying it.Specialist events
SpecialistTurnErrorEventDescribes a failed specialist notification.Contains channel, specialist, and optional error or turn metadata.Type only; error text is display data and not an authority signal.Specialist events
SpecialistEventDiscriminates completed and failed specialist notifications.Narrows through the type field to one event shape.Type only; unknown external events must be rejected before this boundary.Specialist events
OpenEditorProjectOptionsSelects a project, conversation, mode, and optional file positions.openEditorProject consumes the options and resolves with no value.Type only; malformed paths, identities, or unsupported modes reject.Open a project in the editor
openEditorProjectRequests the host-owned embedded editor for the current frame.Accepts OpenEditorProjectOptions and returns a promise of void.It binds to exact frame, document, and origin data; denial or timeout rejects.Open a project in the editor
MiniAppThemeRestricts supported themes to light and dark.Supplies or receives one theme string.Type only; unsupported message values are ignored at runtime.Appearance synchronization
InstallMiniAppThemeSyncOptionsConfigures initial theme input and an application callback.Accepts optional search data and apply function; installation returns cleanup.Type only; an absent host origin disables live message listening.Appearance synchronization
getMiniAppThemeFromSearchReads the initial theme from search parameters.Accepts a query string or URLSearchParams; returns MiniAppTheme.It defaults to light for missing or unsupported values and does not throw.Appearance synchronization
applyMiniAppThemeApplies theme attributes, classes, and color scheme to the document root.Accepts MiniAppTheme and returns void.It is a no-op without a document and changes only cosmetic state.Appearance synchronization
installMiniAppThemeSyncApplies the initial theme and listens for exact-parent updates.Accepts InstallMiniAppThemeSyncOptions and returns an idempotent cleanup function.Wrong source, origin, event, or theme is ignored; always clean up on unmount.Appearance synchronization
MiniAppUiScaleNames the bounded root font size used by portable UI.An integer from the exported minimum through maximum.Type only; runtime helpers reject values outside the supported range.Appearance synchronization
MINIAPP_UI_SCALE_MINExposes the minimum accepted UI scale.Takes no input and evaluates to the numeric value 12.Stable for the installed SDK version.Appearance synchronization
MINIAPP_UI_SCALE_MAXExposes the maximum accepted UI scale.Takes no input and evaluates to the numeric value 20.Stable for the installed SDK version.Appearance synchronization
MINIAPP_UI_SCALE_DEFAULTExposes the fallback UI scale.Takes no input and evaluates to the numeric value 16.Used for absent, fractional, or out-of-range input.Appearance synchronization
getMiniAppUiScaleFromSearchReads and validates the initial scale query parameter.Accepts a query string or URLSearchParams; returns MiniAppUiScale.Invalid input returns the default without throwing.Appearance synchronization
applyMiniAppUiScaleApplies the validated scale to the document root.Accepts MiniAppUiScale and returns void.It is a no-op without a document or for an invalid runtime value.Appearance synchronization
InstallMiniAppAppearanceSyncOptionsConfigures theme and UI-scale callbacks and initial search input.Extends the theme options with an optional scale callback.Type only; an absent exact host disables live updates.Appearance synchronization
installMiniAppAppearanceSyncApplies and synchronizes both theme and UI scale.Accepts appearance options and returns an idempotent cleanup function.Wrong source, origin, event, theme, or scale is ignored.Appearance synchronization