### Host SDK - Quick Start
Source: https://context7_llms
A basic example demonstrating how to create a component registry, register custom components, and initialize a worker controller to load and connect to a plugin.
```APIDOC
## Quick Start
```typescript
import {
createWorkerController,
createComponentRegistry,
} from "@uniview/host-sdk";
// Create a registry for custom components
const registry = createComponentRegistry();
registry.register("Button", MyButtonComponent);
// Create a controller to load the plugin
const controller = createWorkerController({
pluginUrl: "/plugins/my-plugin.js",
initialProps: { userId: "123" },
});
// Subscribe to tree updates
controller.subscribe((tree) => {
console.log("New UI tree:", tree);
// Render the tree using your framework
});
// Connect to start the plugin
await controller.connect();
```
```
--------------------------------
### Svelte Host Setup Example
Source: https://context7_llms
This Svelte component demonstrates how to set up a Uniview plugin host. It uses `@uniview/host-svelte` and `@uniview/host-sdk` to create a worker controller and render a plugin.
```svelte
```
--------------------------------
### Host SDK - Installation
Source: https://context7_llms
Install the @uniview/host-sdk package using pnpm.
```APIDOC
## Installation
```bash
pnpm add @uniview/host-sdk
```
```
--------------------------------
### Install @uniview/host-sdk
Source: https://context7_llms
Installs the @uniview/host-sdk package using pnpm. This is the first step to integrating Uniview plugins into your application.
```bash
pnpm add @uniview/host-sdk
```
--------------------------------
### Installation
Source: https://context7_llms
Install the @uniview/runtime package using pnpm.
```APIDOC
## Installation
```bash
pnpm add @uniview/runtime
```
```
--------------------------------
### Basic PluginHost Usage with Svelte 5
Source: https://context7_llms
Demonstrates a quick start example of using the PluginHost component in Svelte 5. It shows how to set up a component registry and a plugin controller to load and render a plugin's UI.
```svelte
{#snippet loading()}
Loading plugin...
{/snippet}
```
--------------------------------
### Install @uniview/runtime
Source: https://context7_llms
Install the @uniview/runtime package using pnpm. This is the first step to integrating runtime capabilities into your project.
```bash
pnpm add @uniview/runtime
```
--------------------------------
### Run Uniview Host Development Server
Source: https://context7_llms
Starts the development server for a SvelteKit application, allowing you to test the host and its integrated plugins.
```bash
pnpm dev
```
--------------------------------
### startWSServerPlugin (Deprecated)
Source: https://context7_llms
Start a WebSocket server plugin (Deprecated). Use `@uniview/runtime/ws-client` instead.
```APIDOC
## startWSServerPlugin (Deprecated)
Start a WebSocket server plugin.
**Deprecated**: Running plugins as WebSocket servers is deprecated. Use
`@uniview/runtime/ws-client` to connect to a Bridge server instead. This
approach simplifies deployment and port management.
### Method
```typescript
import { startWSServerPlugin } from "@uniview/runtime/ws-server";
startWSServerPlugin({
App,
port: 3001,
});
```
### Description
This function starts a plugin that communicates over WebSocket. It is recommended to use the WebSocket client approach for new projects.
### Parameters
#### Request Body
- **App** (React.ComponentType) - Required - Your React plugin component
- **port** (number) - Required - The port to listen on
### Request Example
```typescript
// server-plugin.ts
import { startWSServerPlugin } from "@uniview/runtime/ws-server";
import App from "./App";
startWSServerPlugin({
App,
port: 3001,
});
```
```
--------------------------------
### Install @uniview/host-svelte and Dependencies
Source: https://context7_llms
Installs the necessary @uniview/host-svelte package along with its required SDK and protocol dependencies using pnpm.
```bash
pnpm add @uniview/host-svelte @uniview/host-sdk @uniview/protocol
```
--------------------------------
### Install Uniview Host SDK and Svelte Package
Source: https://context7_llms
Installs the necessary packages for host development using Svelte and the Uniview protocol.
```bash
pnpm add @uniview/host-sdk @uniview/host-svelte @uniview/protocol
```
--------------------------------
### Quick Start: Load and Manage Uniview Plugins
Source: https://context7_llms
Demonstrates the basic usage of @uniview/host-sdk to create a component registry, register custom components, and initialize a worker controller to load and manage a plugin. It shows how to subscribe to UI tree updates and connect to the plugin.
```typescript
import {
createWorkerController,
createComponentRegistry,
} from "@uniview/host-sdk";
// Create a registry for custom components
const registry = createComponentRegistry();
registry.register("Button", MyButtonComponent);
// Create a controller to load the plugin
const controller = createWorkerController({
pluginUrl: "/plugins/my-plugin.js",
initialProps: { userId: "123" },
});
// Subscribe to tree updates
controller.subscribe((tree) => {
console.log("New UI tree:", tree);
// Render the tree using your framework
});
// Connect to start the plugin
await controller.connect();
```
--------------------------------
### TypeScript: Setup Browser Environment
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This TypeScript code snippet sets up the browser environment by importing the 'browser' object from the '$app/environment' module. It's a foundational step for applications running in a browser context.
```typescript
import { browser } from "$app/environment";
```
--------------------------------
### startWorkerPlugin
Source: https://context7_llms
Bootstrap a plugin in a Web Worker with automatic RPC setup.
```APIDOC
## startWorkerPlugin
Bootstrap a plugin in a Web Worker with automatic RPC setup.
### Method
```typescript
function startWorkerPlugin(options: { App: React.ComponentType }): void;
```
### Description
This function:
1. Creates an RPC channel using the Worker's `postMessage`
2. Exposes the `HostToPluginAPI` methods to the host
3. Sets up the React reconciler
4. Starts rendering when `initialize()` is called
### Request Example
```typescript
// worker.ts
import { startWorkerPlugin } from "@uniview/runtime";
import App from "./App";
startWorkerPlugin({ App });
```
```
--------------------------------
### Start WebSocket Server Plugin (Deprecated)
Source: https://context7_llms
Launch a plugin that acts as a WebSocket server. Note that this method is deprecated in favor of the WebSocket client approach for better deployment and port management.
```typescript
// server-plugin.ts
import { startWSServerPlugin } from "@uniview/runtime/ws-server";
import App from "./App";
startWSServerPlugin({
App,
port: 3001,
});
```
--------------------------------
### Keyed Re-rendering Example
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This Svelte code demonstrates keyed re-rendering by wrapping a component in a `{#key ...}` block. This forces the component to be destroyed and recreated when the key's value changes, which is useful for resetting component state.
```html
{#key runtimeMode}
{/key}
```
--------------------------------
### Install Uniview Plugin Development Packages with pnpm
Source: https://context7_llms
Provides the command to install essential packages for developing Uniview plugins using pnpm. This includes the core runtime, React renderer, protocol definitions, and React itself.
```bash
# For plugin development
pnpm add @uniview/runtime @uniview/react-renderer @uniview/protocol react
```
--------------------------------
### Plugin Host Structure Example
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This snippet illustrates the basic structure of a PluginHost in a configuration file. It defines key properties like runtimeMode, controller, and registry, which are essential for managing plugin behavior and registration.
```json
{
"key": "runtimeMode",
"PluginHost": {
"controller": {},
"registry": {}
}
}
```
--------------------------------
### Loading Snippet Example
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This Svelte snippet defines a custom loading UI to be displayed while a component or process is initializing. It includes a spinning animation and a status message, suitable for scenarios like worker startup or network connections.
```html
{#snippet loading()}
Connecting to plugin environment...
{/snippet}
```
--------------------------------
### Install @uniview/protocol
Source: https://context7_llms
Installs the @uniview/protocol package using pnpm. This package is essential for defining the communication contract between plugins and hosts.
```bash
pnpm add @uniview/protocol
```
--------------------------------
### Install @uniview/react-renderer - Bash
Source: https://context7_llms
Installs the @uniview/react-renderer package along with React using pnpm. This package enables rendering React components into a serializable tree structure.
```bash
pnpm add @uniview/react-renderer react
```
--------------------------------
### Framework Integration - React/Vue/Other
Source: https://context7_llms
Guides on implementing a custom renderer for React, Vue, or other frameworks using the Uniview LLMs Host SDK controller.
```APIDOC
## Framework Integration - React/Vue/Other
### Description
Implement your own UI renderer for frameworks like React or Vue by utilizing the Host SDK's controller. This involves subscribing to updates, handling events, and managing the connection lifecycle.
### Method
N/A (This is a conceptual guide for implementation)
### Parameters
None
### Request Example
```typescript
// 1. Create controller and registry
const controller = createWorkerController({ pluginUrl: "/plugin.js" });
const registry = createComponentRegistry();
// 2. Subscribe to updates
controller.subscribe((tree) => {
// Re-render your UI with the new tree
renderTree(tree, registry);
});
// 3. Handle events
function createEventHandler(handlerId: string) {
return (...args: unknown[]) => {
controller.execute(handlerId, args);
};
}
// 4. Connect on mount
await controller.connect();
// 5. Disconnect on unmount
controller.disconnect();
```
### Response
#### Success Response (200)
N/A (This is a code implementation guide)
#### Response Example
N/A
```
--------------------------------
### Bootstrap Plugin with @uniview/runtime (TypeScript)
Source: https://context7_llms
Shows the simplest way to bootstrap a plugin using the startWorkerPlugin function from @uniview/runtime. It also includes an example of how to configure initial props and error handling.
```typescript
// Simplest usage
import { startWorkerPlugin } from "@uniview/runtime";
startWorkerPlugin({ App });
// With configuration
startWorkerPlugin({
App,
initialProps: { theme: "dark" },
onError: (err) => console.error(err),
});
```
--------------------------------
### Setup Worker Plugin (TypeScript)
Source: https://context7_llms
Demonstrates setting up a plugin in Worker mode on the plugin side using `@uniview/runtime`. It initializes the plugin application within a web worker for isolation. This mode is asynchronous and communicates via `postMessage`.
```typescript
// worker.ts
import { startWorkerPlugin } from "@uniview/runtime";
import App from "./App";
startWorkerPlugin({ App });
```
--------------------------------
### Basic Usage of React Renderer - TypeScript
Source: https://context7_llms
Demonstrates the basic setup for using @uniview/react-renderer. It involves creating a HandlerRegistry, a render bridge, subscribing to tree updates, and rendering a React app.
```typescript
import {
render,
createRenderBridge,
serializeTree,
HandlerRegistry
} from "@uniview/react-renderer";
// Create handler registry
const registry = new HandlerRegistry();
// Create render bridge
const bridge = createRenderBridge();
// Subscribe to tree updates
bridge.subscribe((root) => {
if (root) {
const tree = serializeTree(root, registry);
console.log('Tree updated:', tree);
}
});
// Render your React app
render(, bridge);
```
--------------------------------
### Setup Main Thread Controller
Source: https://context7_llms
Initializes and connects the Main Thread controller for plugin development. This mode is suitable for local development and debugging due to its direct access and hot-reloading capabilities. It requires the '@uniview/host-sdk' and the plugin's App component.
```typescript
import { createMainController } from "@uniview/host-sdk";
import { SimpleDemo } from "@uniview/example-plugin";
const controller = createMainController({
App: SimpleDemo,
initialProps: { debug: true },
});
await controller.connect();
```
--------------------------------
### HTML Structure for Plugin Host Initialization
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This snippet represents an HTML structure for initializing a plugin host. It includes a 'div' element and a closing tag, indicating the start and end of a component or section. The code suggests a dynamic rendering process in a web environment.
```html
```
--------------------------------
### Svelte Framework Integration with Uniview Host
Source: https://context7_llms
Demonstrates how to integrate Uniview components into a Svelte application using the `@uniview/host-svelte` package. It shows the setup of the component registry and the worker controller, and how to render the `PluginHost` component.
```svelte
```
--------------------------------
### React Plugin Example
Source: https://context7_llms
This code snippet demonstrates a simple React plugin component that includes state management for a counter and a button to increment it. It utilizes the standard React useState hook.
```tsx
// App.tsx
import { useState } from "react";
export default function App() {
const [count, setCount] = useState(0);
return (
Count: {count}
);
}
```
--------------------------------
### Importing SimpleDemo from @uniview/example-plugin
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This JavaScript code snippet demonstrates how to import the 'SimpleDemo' component from the '@uniview/example-plugin' package. It's a standard import statement used in Svelte or similar JavaScript frameworks.
```javascript
import { SimpleDemo } from "@uniview/example-plugin";
```
--------------------------------
### Loading States UI with Plugin Initialization
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This code demonstrates how to implement a custom UI for loading states while a plugin is initializing. It's crucial for providing user feedback during delays in Worker Mode (script/worker startup) and WebSocket Mode (network latency).
```html
The {#snippet loading()} block allows you to provide a custom UI while the plugin is initializing. This is especially important for:
Worker Mode: Script loading and worker startup (approx. 50-200ms).
```
--------------------------------
### Set Up Uniview Host Controller (Svelte)
Source: https://context7_llms
Initializes a Svelte component to act as a Uniview plugin host. It sets up a component registry and a worker controller pointing to the plugin's JavaScript file.
```svelte
Uniview Host Demo
{#snippet loading()}
Loading plugin environment...
{/snippet}
```
--------------------------------
### Example React Component for a Plugin
Source: https://context7_llms
A standard React component that can be used within a @uniview/runtime plugin. It functions as expected with state management and event handling.
```tsx
// App.tsx
import { useState } from "react";
export default function App() {
const [count, setCount] = useState(0);
return (
Count: {count}
);
}
```
--------------------------------
### Bootstrap Plugin with Uniview Runtime
Source: https://context7_llms
Starts a Uniview plugin worker using the provided React component. This is the entry point for the plugin's runtime environment.
```typescript
import { startWorkerPlugin } from "@uniview/runtime";
import App from "./App";
startWorkerPlugin({ App });
```
--------------------------------
### Reactive Controller Creation with $derived.by
Source: https://context7_llms
Demonstrates how to use `$derived.by` to reactively recreate a controller when a runtime mode changes. This ensures proper cleanup of the old controller and initialization of a new one with the correct configuration, including re-instantiating the registry.
```javascript
const controller = $derived.by(() => {
// Cleanup logic for the old controller can be placed here using $effect
return new RuntimeController(runtimeMode, registry);
});
```
--------------------------------
### Deprecated WebSocket Plugin Server (TypeScript)
Source: https://context7_llms
Provides the deprecated method for starting a WebSocket server directly within the plugin using `@uniview/runtime/ws-server`. This approach is less recommended than the Bridge architecture for server-side plugins.
```typescript
import { startWSServerPlugin } from "@uniview/runtime/ws-server";
startWSServerPlugin({ App, port: 3001 });
```
--------------------------------
### JavaScript for Plugin Host Initialization
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This JavaScript snippet appears to be part of a system for managing plugin hosts and their controllers. It defines structures for plugin host objects, including properties like 'controller' and 'registry', and likely handles the initialization or registration of these components.
```javascript
PluginHost {
controller
registry
}
```
--------------------------------
### Svelte 5 Toggle Custom Component Example
Source: https://context7_llms
A Svelte 5 toggle button component. It can be pressed or unpressed, supports disabled state, and offers 'default' or 'outline' variants. It accepts an optional click handler and can render child content.
```svelte
```
--------------------------------
### Importing PluginController from @uniview/host-sdk
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This snippet demonstrates how to import the PluginController from the '@uniview/host-sdk' package. It's a common pattern for integrating external SDKs in JavaScript projects.
```javascript
import { PluginController } from "@uniview/host-sdk";
```
--------------------------------
### Create and Register Custom Components with Uniview Host SDK
Source: https://context7_llms
Demonstrates how to initialize a component registry using `createComponentRegistry` from `@uniview/host-sdk` and then register custom Svelte components like 'Button', 'Card', and 'Input' into this registry.
```typescript
import { createComponentRegistry } from "@uniview/host-sdk";
import type { Component } from "svelte";
// Create a typed registry for your framework
const registry = createComponentRegistry();
// Register components
registry.register("Button", Button);
registry.register("Card", Card);
registry.register("Input", Input);
```
--------------------------------
### connectToHostServer
Source: https://context7_llms
Connect to a Bridge server for server-side plugins.
```APIDOC
## connectToHostServer
Connect to a Bridge server for server-side plugins (Recommended).
### Method
```typescript
import { connectToHostServer } from "@uniview/runtime/ws-client";
connectToHostServer({
App,
serverUrl: "ws://localhost:3000", // Bridge server URL
pluginId: "my-plugin", // Unique plugin identifier
});
```
### Description
This function is used for server-side plugins to connect to a Bridge server. It simplifies deployment and port management by establishing a WebSocket connection.
### Parameters
#### Request Body
- **App** (React.ComponentType) - Required - Your React plugin component
- **serverUrl** (string) - Required - Bridge server WebSocket URL
- **pluginId** (string) - Required - Unique identifier for this plugin
- **initialProps** (JSONValue) - Optional - Optional initial props
### Request Example
```typescript
// server-plugin.ts
import { connectToHostServer } from "@uniview/runtime/ws-client";
import App from "./App";
connectToHostServer({
App,
serverUrl: "ws://localhost:3000", // Bridge server URL
pluginId: "my-plugin", // Unique plugin identifier
});
```
The plugin connects to `{serverUrl}/plugins/{pluginId}` and waits for a host to connect.
```
--------------------------------
### Svelte 5 Card Custom Component Example
Source: https://context7_llms
A Svelte 5 component for displaying cards. It supports optional title and description props, and renders any provided child content within the card body. Includes basic CSS for card styling.
```svelte
{#if title}
{title}
{/if}
{#if description}
{description}
{/if}
{@render children?.()}
```
--------------------------------
### Serialize React onClick to UINode Handler ID
Source: https://context7_llms
This example shows how a React `onClick` event handler is transformed into a `UINode` representation. The actual function is replaced by a handler ID (`_onClickHandlerId`), which the runtime uses to look up and execute the original function via its registry.
```tsx
// In your plugin
// Becomes UINode:
{
type: "button",
props: {
_onClickHandlerId: "handler_abc123"
},
children: ["Click"]
}
```
--------------------------------
### createPluginRuntime
Source: https://context7_llms
For advanced use cases, create a runtime with a custom transport.
```APIDOC
## createPluginRuntime
For advanced use cases, create a runtime with custom transport.
### Method
```typescript
import { createPluginRuntime } from "@uniview/runtime";
import type { PluginToHostAPI } from "@uniview/protocol";
interface PluginRuntimeOptions {
App: React.ComponentType;
hostApi: PluginToHostAPI;
onInitialize?: (props: JSONValue) => void;
onUpdateProps?: (props: JSONValue) => void;
}
interface PluginRuntime {
start(): void;
stop(): void;
executeHandler(handlerId: string, args: JSONValue[]): Promise;
}
```
### Description
This function allows for the creation of a plugin runtime with a custom transport mechanism, providing more control over communication with the host.
### Request Example
```typescript
import { createPluginRuntime } from "@uniview/runtime";
import type { PluginToHostAPI } from "@uniview/protocol";
const runtime = createPluginRuntime({
App: MyApp,
hostApi: {
updateTree: (tree) => sendToHost(tree),
log: (level, args) => console.log(level, ...args),
},
});
runtime.start();
```
```
--------------------------------
### Custom Svelte 5 Button Component for Uniview
Source: https://context7_llms
Provides an example of a custom Svelte 5 component (Button.svelte) designed to be registered with Uniview's component registry. It supports various props like variant, disabled state, click handlers, and children content.
```svelte
```
--------------------------------
### Component Registry: Map Plugin Components to Framework Implementations
Source: https://context7_llms
Demonstrates the usage of the ComponentRegistry to map string types to actual component implementations within your UI framework. It shows how to register, retrieve, check for, and list components.
```typescript
import { createComponentRegistry } from "@uniview/host-sdk";
interface ComponentRegistry {
register(type: string, component: T, metadata?: ComponentMetadata): void;
get(type: string): T | undefined;
has(type: string): boolean;
list(): string[];
clear(): void;
}
const registry = createComponentRegistry();
// Register components
registry.register("Button", Button);
registry.register("Card", Card);
registry.register("Modal", Modal);
// Check availability
if (registry.has("Button")) {
const ButtonComponent = registry.get("Button");
}
// List all registered
console.log(registry.list()); // ['Button', 'Card', 'Modal']
```
--------------------------------
### Svelte 5 Input Custom Component Example
Source: https://context7_llms
A Svelte 5 component for input fields. It supports various input types, placeholder text, labels, disabled state, and event handlers for input and change events. It's structured within a div for group styling.
```svelte
{#if label}
{/if}
```
--------------------------------
### Framework Adapter Structure (Conceptual)
Source: https://context7_llms
Describes the architectural separation between the core 'host-sdk' logic and thin framework-specific adapters. The 'host-sdk' contains all controller logic, while adapters like 'host-svelte' and 'host-vue' are minimal and focus solely on rendering.
```text
host-sdk (400 lines) ← All the logic
host-svelte (150 lines) ← Just Svelte rendering
host-vue (150 lines) ← Just Vue rendering
```
--------------------------------
### Svelte 5 Button Custom Component Example
Source: https://context7_llms
A Svelte 5 component for a customizable button. It accepts props for variant, size, disabled state, and an optional click handler. It also supports rendering child content via Svelte snippets and includes scoped CSS for styling.
```svelte
```
--------------------------------
### Protocol Helpers for Handler IDs (TypeScript)
Source: https://context7_llms
Illustrates the use of protocol helper functions for managing handler IDs, which are used to serialize functions across RPC boundaries. Functions include `handlerIdProp` to get the property name, `isHandlerIdProp` to check if a property is a handler ID, and `extractEventName` to retrieve the original event name.
```typescript
// Protocol helpers
import {
handlerIdProp,
isHandlerIdProp,
extractEventName,
} from "@uniview/protocol";
handlerIdProp("onClick"); // "_onClickHandlerId"
isHandlerIdProp("_onClickHandlerId"); // true
extractEventName("_onClickHandlerId"); // "onClick"
```
--------------------------------
### Create Main Controller in JavaScript
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This snippet shows how to create a main controller in JavaScript, intended for use in the main thread, possibly during development. It utilizes a function named createMainController. The App is then configured with SimpleDemo.
```javascript
// Main Thread (Dev only)
controller = createMainController({
App: SimpleDemo,
});
```
--------------------------------
### Handle Unknown Components in TypeScript
Source: https://context7_llms
Illustrates a strategy for handling components that are not found in the registry, including logging a warning and providing options for rendering.
```typescript
// In ComponentRenderer logic
if (!registry.has(node.type)) {
console.warn(`Unknown component: ${node.type}`);
// Option 1: Render nothing
// Option 2: Render error message
// Option 3: Render as div with warning
}
```
--------------------------------
### Lazy Component Registration with TypeScript
Source: https://context7_llms
Illustrates how to create a component registry and register components on-demand using dynamic imports in TypeScript.
```typescript
const registry = createComponentRegistry();
// Register core components immediately
registry.register("Button", Button);
registry.register("Input", Input);
// Register others when needed
async function loadAdvancedComponents() {
const { DataTable } = await import("$lib/components/DataTable.svelte");
const { Chart } = await import("$lib/components/Chart.svelte");
registry.register("DataTable", DataTable);
registry.register("Chart", Chart);
}
```
--------------------------------
### Connect to Host Server using WebSocket Client
Source: https://context7_llms
Establish a connection to a Bridge server from a server-side plugin using the WebSocket client entry point. This is the recommended approach for server-side plugins.
```typescript
// server-plugin.ts
import { connectToHostServer } from "@uniview/runtime/ws-client";
import App from "./App";
connectToHostServer({
App,
serverUrl: "ws://localhost:3000", // Bridge server URL
pluginId: "my-plugin", // Unique plugin identifier
});
```
--------------------------------
### Lifecycle Management
Source: https://context7_llms
Illustrates the lifecycle of the Uniview LLMs Host SDK controller, from creation to disconnection.
```APIDOC
## Lifecycle Management
### Description
Details the lifecycle of the Uniview LLMs Host SDK controller, outlining the sequence of operations including creation, connection, subscription, updates, execution, and disconnection.
### Method
N/A (This section describes the flow)
### Parameters
None
### Request Example
```
createController()
│
▼
connect() ──────────────┐
│ │
▼ │
subscribe(cb) ◄─────────┤
│ │
▼ │
updateProps() ◄─────────┤
│ │
▼ │
execute() ◄─────────────┤
│ │
▼ │
disconnect() ───────────┘
```
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
**Note:** Always call `disconnect()` when done to clean up resources and prevent memory leaks.
```
--------------------------------
### Registering Custom Components with Host SDK
Source: https://context7_llms
Demonstrates how to register a custom Svelte component (e.g., Button) with the component registry provided by the @uniview/host-sdk. This allows the PluginHost to render custom UI elements defined by plugins.
```typescript
import { createComponentRegistry } from "@uniview/host-sdk";
import Button from "$lib/components/Button.svelte";
const registry = createComponentRegistry();
registry.register("Button", Button);
```
--------------------------------
### TypeScript: Import Host SDK Controllers and Registry
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This TypeScript code imports various controller creation functions (createWorkerController, createWebSocketController, createMainController) and the createComponentRegistry function from the '@uniview/host-sdk' module. These are essential for managing different types of controllers and component registration within the host application.
```typescript
import {
createWorkerController,
createWebSocketController,
createMainController,
createComponentRegistry
} from "@uniview/host-sdk";
```
--------------------------------
### Register Component with Metadata in TypeScript
Source: https://context7_llms
Demonstrates how to register a component with additional metadata, including its description and prop details, using a component registry.
```typescript
registry.register("Button", Button, {
description: "Primary action button",
props: {
variant: { type: "string", default: "primary" },
size: { type: "string", default: "md" },
disabled: { type: "boolean", default: false },
},
});
```
--------------------------------
### JavaScript Error Handling and Controller Creation
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
This snippet demonstrates JavaScript code for handling errors during controller creation and returning null if an error occurs. It also includes logic for returning controller and registry objects upon successful creation.
```javascript
}
catch (err) {
console.error("Failed to create controller:", err);
return null;
}
return { controller, registry };
});
// 3. Cleanup Effect
$
effect(() => {
const config = controllerConfig;
return () =>
});
```
--------------------------------
### Svelte Host Implementation with Uniview SDK
Source: https://huakunshen.github.io/uniview/docs/guides/advanced-host
A Svelte 5 component demonstrating a Universal Host pattern using @uniview/host-svelte and @uniview/host-sdk. It dynamically creates controllers for Worker, WebSocket, or Main Thread modes based on the runtimeMode state, registering custom Svelte components for UI interaction.
```svelte