Files
hub/readme.md
T
2026-05-05 19:53:54 +00:00

120 lines
5.3 KiB
Markdown

# @smarthome.exchange/hub
🧠 Local smarthome.exchange runtime for device tools, scoped agents, automations, approvals, audit receipts, integrations, and typed hub handlers.
The hub is the composition root. It wires together registries, approval queues, audit logs, automation execution, MCP descriptors, integration discovery, and TypedRequest handlers around the shared contracts from `@smarthome.exchange/interfaces`.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Install
```bash
pnpm add @smarthome.exchange/hub
```
## Basic Usage
```ts
import { ShxHub } from '@smarthome.exchange/hub';
const hub = new ShxHub({
home: {
id: 'home:studio',
name: 'Studio',
timezone: 'Europe/Berlin',
},
});
await hub.start();
const snapshot = hub.getSnapshot();
console.log(snapshot.devices.map((deviceArg) => deviceArg.id));
await hub.stop();
```
`ShxHub` registers typed handlers on `hub.typedrouter`. Host applications can bind that router to the transport they want to expose. The current package runtime builds the hub primitives and web bundle; it does not itself bootstrap a standalone HTTP server from `pnpm start`.
## Runtime Pieces
| Export | Responsibility |
| --- | --- |
| `ShxHub` | Composition root for the local runtime. |
| `DeviceRegistry` | Lists, looks up, upserts, and updates normalized devices. |
| `AgentRegistry` | Holds reference agents and runtime statuses. |
| `ToolRegistry` | Lists tools and executes plans according to tool/agent modes. |
| `ApprovalQueue` | Creates, lists, approves, and rejects approval requests. |
| `AuditLog` | Stores append-only audit receipts. |
| `AutomationRunner` | Owns an SDK automation context wired to the tool registry. |
| `McpDescriptor` | Exposes registered tools as MCP-style descriptors. |
## Typed Operations
`registerTypedHandlers()` installs handlers for:
| Operation | Purpose |
| --- | --- |
| `listDevices` | Return normalized devices from the device registry. |
| `listAgents` | Return reference agents and runtime statuses. |
| `listTools` | Return registered device and agent tools. |
| `getHomeSnapshot` | Return home, devices, agents, approvals, dashboards, receipts, and timestamp. |
| `executeToolPlan` | Execute a plan, queue approval, suggest, or fail per tool mode. |
| `listApprovals` | Return approval requests filtered by status. |
| `submitApproval` | Approve or reject a pending request and write an audit receipt. |
## Integration Flow
```ts
const candidates = await hub.discoverIntegrationCandidates();
const runtime = await hub.setupIntegration('hue', {
bridgeId: 'bridge:office',
baseUrl: 'https://192.168.1.20',
username: 'local-hue-token',
});
console.log(await runtime.devices());
```
Integrations come from `@smarthome.exchange/integrations`. Successful setup returns a runtime and upserts the integration's normalized devices into the hub device registry.
## Seeded Demo State
By default, `ShxHub` seeds a Birch Lane demo home with rooms, members, reference agents, and devices such as climate, lock, solar/energy, and lighting examples. Override `home` in the constructor when embedding the hub in a real host.
## Console Bundle
The web entry imports `@smarthome.exchange/catalog` and renders `<shx-console-shell>`. It is useful for bundle/catalog development, while actual live data should come through the typed API boundary.
## Scripts
```bash
pnpm test
pnpm build
pnpm watch
pnpm buildDocs
```
## License and Legal Information
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./license) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH\
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.