ViewContext
interfaceThe context a panel declared with `view(...)` receives, through `useViewContext()`. The two members that only exist here are `viewId` and `diagnostics`: a view is a panel the host mounts, so it has an identity in the layout and it owes the host a report on whether it rendered. Its `ai` is AiViewApi, the subset that is safe across the view boundary, not the full runtime.
Import
import { ViewContext } from '@modular/sdk';Members26
- ai
AiViewApiThe AI surface a view is allowed to reach.
- auth
AuthViewApiSign in and read sessions from auth providers.
- commands
CommandsViewApiRun any registered command by id.
- completedActionTraces
ReadonlySignal<readonly HostActionTrace[]>Traces of actions that have finished, for mods that show or verify what the app did. Pair it with ContextBase.subscribeActionTraces to be told when a new one lands.
- diagnostics
ViewDiagnosticsReport that the panel rendered, or that it failed.
- editor
EditorApiRead and edit the document the user is in.
- hooks
HostHookClientRegister interceptors from code.
- logger
LoggerYour mod's log channel.
- media
MediaApiScreen, camera, and audio capture.
- modId
ModIdThe id of the mod this handler belongs to.
- permissions
PermissionClientWhat the user has granted, denied, and is being asked.
- system
SystemCapabilitiesHost event sources you can listen to, and the catalog to discover them.
- terminal
TerminalApiCreate and drive terminals.
- ui
UiCapabilityNotifications, dialogs, quick input, and progress.
- viewId
stringThe id you gave this view in `view({ id })`.
- workbench
WorkbenchApiThe window shell: theme, layout, status bar, opening things.
- workspace
WorkspaceApiFolders, files, and configuration of the open workspace.
- action()
<K extends HostActionReference>(id: K, input: HostActionInput<K>, options?: HostActionClientRunOptions) => Promise<HostActionResult<K>>Dispatch an action. This is the only way a mod changes the app. Takes a host action id, one of this mod's own `command(...)` values, or `command:` plus the id of a command another mod owns. Inside an event listener, prefer `occurrence.action(...)` so the causal link survives.
- describeAction()
(id: HostActionId) => ModularActionDescriptorDto | undefinedLook up one action's schema, or `undefined` if nothing owns that id.
- describeEvent()
(id: HostEventId) => ModularEventDescriptorDto | undefinedLook up one event's schema, or `undefined` if nothing declares that id.
- emit()
<TPayload>(descriptor: EventDeclaration<TPayload>, payload: TPayload, options?: HostActionClientRunOptions) => Promise<EventEmitResult>Publish one of your mod's own events to whoever is listening.
- listActions()
() => readonly ModularActionDescriptorDto[]Every action available right now, including those other mods contribute.
- listEvents()
() => readonly ModularEventDescriptorDto[]Every event you can subscribe to right now.
- on()
<TPayload>(descriptor: EventDeclaration<TPayload>, listener: (event: EventOccurrence<TPayload>) => void | Promise<void>) => Disposable | <K extends ModularEventId>(id: K, listener: (event: EventOccurrence<ModularEventMap[K]>) => void | Promise<void>) => Disposable | (id: HostEventId, listener: (event: EventOccurrence<unknown>) => void | Promise<void>) => DisposableSubscribe to an event, either your own declared one or a host event named by id. Dispose the result to stop listening.
- state()
<TValue>(declaration: StateDeclaration<TValue>) => OwnedState<TValue> | <TName extends BuiltInStateName>(name: TName) => State<BuiltInStateValue<TName>>Acquire a live state handle. Passing your own `state(...)` declaration gives an OwnedState you can write with `set`. Passing a built-in name gives a read-only State: host state changes only through actions.
- subscribeActionTraces()
(listener: () => void) => DisposableRuns `listener` whenever a new trace lands in `completedActionTraces`.