@fugood/bricks-project 2.23.0-beta.9 → 2.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/instance.ts +37 -5
- package/compile/action-name-map.ts +107 -0
- package/compile/index.ts +172 -66
- package/compile/util.ts +13 -4
- package/package.json +9 -5
- package/skills/bricks-project/SKILL.md +32 -0
- package/skills/bricks-project/rules/animation.md +159 -0
- package/skills/bricks-project/rules/architecture-patterns.md +62 -0
- package/skills/bricks-project/rules/automations.md +221 -0
- package/skills/bricks-project/rules/buttress.md +153 -0
- package/skills/bricks-project/rules/data-calculation.md +208 -0
- package/skills/bricks-project/rules/local-sync.md +129 -0
- package/skills/bricks-project/rules/media-flow.md +158 -0
- package/skills/bricks-project/rules/remote-data-bank.md +196 -0
- package/skills/bricks-project/rules/standby-transition.md +124 -0
- package/skills/rive-marketplace/SKILL.md +99 -0
- package/tools/deploy.ts +74 -12
- package/tools/icons/.gitattributes +1 -0
- package/tools/icons/fa6pro-glyphmap.json +4686 -0
- package/tools/icons/fa6pro-meta.json +26127 -0
- package/tools/mcp-server.ts +818 -9
- package/tools/postinstall.ts +75 -13
- package/tools/preview-main.mjs +54 -4
- package/tools/preview.ts +54 -7
- package/tools/pull.ts +37 -16
- package/types/automation.ts +232 -0
- package/types/brick-base.ts +1 -0
- package/types/bricks/Camera.ts +26 -10
- package/types/bricks/Chart.ts +1 -0
- package/types/bricks/GenerativeMedia.ts +21 -3
- package/types/bricks/Icon.ts +1 -0
- package/types/bricks/Image.ts +6 -0
- package/types/bricks/Items.ts +1 -0
- package/types/bricks/Lottie.ts +1 -0
- package/types/bricks/Maps.ts +254 -0
- package/types/bricks/QrCode.ts +1 -0
- package/types/bricks/Rect.ts +1 -0
- package/types/bricks/RichText.ts +1 -0
- package/types/bricks/Rive.ts +1 -0
- package/types/bricks/Slideshow.ts +1 -0
- package/types/bricks/Svg.ts +1 -0
- package/types/bricks/Text.ts +1 -0
- package/types/bricks/TextInput.ts +1 -0
- package/types/bricks/Video.ts +1 -0
- package/types/bricks/VideoStreaming.ts +1 -0
- package/types/bricks/WebRtcStream.ts +1 -0
- package/types/bricks/WebView.ts +8 -1
- package/types/bricks/index.ts +2 -0
- package/types/canvas.ts +1 -0
- package/types/common.ts +2 -0
- package/types/data-calc-command.ts +7003 -0
- package/types/data-calc-script.ts +21 -0
- package/types/data-calc.ts +3 -6977
- package/types/data.ts +3 -0
- package/types/generators/AlarmClock.ts +2 -0
- package/types/generators/Assistant.ts +30 -6
- package/types/generators/BleCentral.ts +2 -0
- package/types/generators/BlePeripheral.ts +2 -0
- package/types/generators/CanvasMap.ts +2 -0
- package/types/generators/CastlesPay.ts +2 -0
- package/types/generators/DataBank.ts +2 -0
- package/types/generators/File.ts +2 -0
- package/types/generators/GraphQl.ts +2 -0
- package/types/generators/Http.ts +84 -2
- package/types/generators/HttpServer.ts +5 -1
- package/types/generators/Information.ts +2 -0
- package/types/generators/Intent.ts +51 -0
- package/types/generators/Iterator.ts +11 -2
- package/types/generators/Keyboard.ts +2 -0
- package/types/generators/LlmAnthropicCompat.ts +2 -0
- package/types/generators/LlmAppleBuiltin.ts +144 -0
- package/types/generators/LlmGgml.ts +28 -4
- package/types/generators/LlmOnnx.ts +2 -0
- package/types/generators/LlmOpenAiCompat.ts +2 -0
- package/types/generators/LlmQualcommAiEngine.ts +2 -0
- package/types/generators/Mcp.ts +6 -4
- package/types/generators/McpServer.ts +8 -6
- package/types/generators/MediaFlow.ts +2 -0
- package/types/generators/MqttBroker.ts +2 -0
- package/types/generators/MqttClient.ts +2 -0
- package/types/generators/Question.ts +9 -0
- package/types/generators/RealtimeTranscription.ts +18 -8
- package/types/generators/RerankerGgml.ts +23 -16
- package/types/generators/SerialPort.ts +2 -0
- package/types/generators/SoundPlayer.ts +2 -0
- package/types/generators/SoundRecorder.ts +2 -0
- package/types/generators/SpeechToTextGgml.ts +19 -4
- package/types/generators/SpeechToTextOnnx.ts +2 -0
- package/types/generators/SpeechToTextPlatform.ts +2 -0
- package/types/generators/SqLite.ts +32 -1
- package/types/generators/Step.ts +2 -0
- package/types/generators/SttAppleBuiltin.ts +117 -0
- package/types/generators/Tcp.ts +2 -0
- package/types/generators/TcpServer.ts +5 -1
- package/types/generators/TextToSpeechApple.ts +113 -0
- package/types/generators/TextToSpeechAppleBuiltin.ts +114 -0
- package/types/generators/TextToSpeechGgml.ts +24 -3
- package/types/generators/TextToSpeechOnnx.ts +2 -0
- package/types/generators/TextToSpeechOpenAiLike.ts +2 -0
- package/types/generators/ThermalPrinter.ts +2 -0
- package/types/generators/Tick.ts +5 -1
- package/types/generators/TtsAppleBuiltin.ts +105 -0
- package/types/generators/Udp.ts +2 -0
- package/types/generators/VadGgml.ts +4 -2
- package/types/generators/VadOnnx.ts +201 -0
- package/types/generators/VadTraditional.ts +123 -0
- package/types/generators/VectorStore.ts +15 -2
- package/types/generators/Watchdog.ts +2 -0
- package/types/generators/WebCrawler.ts +2 -0
- package/types/generators/WebRtc.ts +4 -2
- package/types/generators/WebSocket.ts +2 -0
- package/types/generators/index.ts +5 -0
- package/types/index.ts +3 -0
- package/types/system.ts +48 -6
- package/utils/calc.ts +15 -9
- package/utils/data.ts +1 -0
- package/utils/event-props.ts +112 -2
- package/utils/id.ts +3 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Buttress (Remote Inference)
|
|
2
|
+
|
|
3
|
+
Backend system for offloading compute-intensive AI generator tasks from BRICKS devices to more powerful machines.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
When mobile devices or embedded systems lack hardware for local AI inference (LLM, speech-to-text), Buttress transparently delegates work to a server with appropriate resources (GPU).
|
|
8
|
+
|
|
9
|
+
## How It Works
|
|
10
|
+
|
|
11
|
+
1. **Capability Exchange**: Client and server share hardware capabilities
|
|
12
|
+
2. **Strategy Selection**: System decides local vs. remote execution
|
|
13
|
+
3. **Transparent Offloading**: Generator operates same way, execution happens remotely
|
|
14
|
+
|
|
15
|
+
## Supported Generators
|
|
16
|
+
|
|
17
|
+
- [LLM (GGML)](generator_LLM) - Local Large Language Model inference
|
|
18
|
+
- [Speech-to-Text (GGML)](generator_SpeechInference) - Local Speech-to-Text inference
|
|
19
|
+
|
|
20
|
+
## Client Configuration
|
|
21
|
+
|
|
22
|
+
In generator properties, configure Buttress settings:
|
|
23
|
+
|
|
24
|
+
| Setting | Description |
|
|
25
|
+
|---------|-------------|
|
|
26
|
+
| `Enabled` | Toggle Buttress offloading |
|
|
27
|
+
| `URL` | Buttress server URL (e.g., `http://192.168.1.100:2080`) |
|
|
28
|
+
| `Fallback Type` | Action if Buttress unavailable: `use-local` or `no-op` |
|
|
29
|
+
| `Strategy` | Execution preference |
|
|
30
|
+
|
|
31
|
+
### Strategy Options
|
|
32
|
+
|
|
33
|
+
| Strategy | Description |
|
|
34
|
+
|----------|-------------|
|
|
35
|
+
| `prefer-local` | Use local if capable, fallback to Buttress |
|
|
36
|
+
| `prefer-buttress` | Use Buttress if available, fallback to local |
|
|
37
|
+
| `prefer-best` | Auto-select based on capability comparison |
|
|
38
|
+
|
|
39
|
+
## Generator Configuration Example
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { makeId } from 'bricks-project'
|
|
43
|
+
|
|
44
|
+
const llmGenerator: GeneratorLLM = {
|
|
45
|
+
__typename: 'Generator',
|
|
46
|
+
templateKey: 'GENERATOR_LLM',
|
|
47
|
+
id: makeId('generator'),
|
|
48
|
+
title: 'Chat LLM',
|
|
49
|
+
description: '',
|
|
50
|
+
property: {
|
|
51
|
+
modelUrl: 'https://huggingface.co/ggml-org/gemma-3-12b-it-qat-GGUF/resolve/main/gemma-3-12b-it-qat-q4_0.gguf',
|
|
52
|
+
contextSize: 8192,
|
|
53
|
+
buttressEnabled: true,
|
|
54
|
+
buttressUrl: 'http://192.168.1.100:2080',
|
|
55
|
+
buttressFallbackType: 'use-local',
|
|
56
|
+
buttressStrategy: 'prefer-best',
|
|
57
|
+
},
|
|
58
|
+
events: {},
|
|
59
|
+
switches: [],
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Server Setup
|
|
64
|
+
|
|
65
|
+
### Requirements
|
|
66
|
+
- [Bun](https://bun.sh) v1.3+
|
|
67
|
+
- GPU recommended for LLM/STT
|
|
68
|
+
|
|
69
|
+
### Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
bun add -g @fugood/buttress-server
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Start Server
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bricks-buttress
|
|
79
|
+
# or with config
|
|
80
|
+
bricks-buttress --config ./config.toml
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### CLI Options
|
|
84
|
+
|
|
85
|
+
| Option | Description |
|
|
86
|
+
|--------|-------------|
|
|
87
|
+
| `-p, --port` | Port (default: 2080) |
|
|
88
|
+
| `-c, --config` | TOML config file path |
|
|
89
|
+
| `-v, --version` | Show version |
|
|
90
|
+
| `-h, --help` | Show help |
|
|
91
|
+
|
|
92
|
+
### Environment Variables
|
|
93
|
+
|
|
94
|
+
| Variable | Description |
|
|
95
|
+
|----------|-------------|
|
|
96
|
+
| `HF_TOKEN` | Hugging Face token for model downloads |
|
|
97
|
+
| `ENABLE_OPENAI_COMPAT_ENDPOINT` | Set to `1` for OpenAI-compatible API |
|
|
98
|
+
|
|
99
|
+
## Server Configuration (TOML)
|
|
100
|
+
|
|
101
|
+
```toml
|
|
102
|
+
[server]
|
|
103
|
+
port = 2080
|
|
104
|
+
|
|
105
|
+
[runtime]
|
|
106
|
+
cache_dir = "./.buttress-cache"
|
|
107
|
+
n_threads = 6
|
|
108
|
+
flash_attn_type = "on"
|
|
109
|
+
cache_type_k = "q8_0"
|
|
110
|
+
cache_type_v = "q8_0"
|
|
111
|
+
|
|
112
|
+
# LLM Generator
|
|
113
|
+
[[generators]]
|
|
114
|
+
type = "ggml-llm"
|
|
115
|
+
[generators.backend]
|
|
116
|
+
variant_preference = ["cuda", "vulkan", "default"]
|
|
117
|
+
gpu_memory_fraction = 0.95
|
|
118
|
+
[generators.model]
|
|
119
|
+
repo_id = "ggml-org/gemma-3-12b-it-qat-GGUF"
|
|
120
|
+
download = true
|
|
121
|
+
n_ctx = 8192
|
|
122
|
+
|
|
123
|
+
# STT Generator
|
|
124
|
+
[[generators]]
|
|
125
|
+
type = "ggml-stt"
|
|
126
|
+
[generators.backend]
|
|
127
|
+
variant_preference = ["cuda", "vulkan", "default"]
|
|
128
|
+
[generators.model]
|
|
129
|
+
repo_id = "BricksDisplay/whisper-ggml"
|
|
130
|
+
filename = "ggml-small-q8_0.bin"
|
|
131
|
+
download = true
|
|
132
|
+
use_gpu = true
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Use Cases
|
|
136
|
+
|
|
137
|
+
### Resource-Constrained Devices
|
|
138
|
+
Digital signage with basic hardware offloads LLM to powerful server.
|
|
139
|
+
|
|
140
|
+
### Shared GPU Resources
|
|
141
|
+
Multiple devices share single GPU server for inference.
|
|
142
|
+
|
|
143
|
+
### Development Testing
|
|
144
|
+
Test AI features on lightweight dev machines by connecting to beefy server.
|
|
145
|
+
|
|
146
|
+
## Best Practices
|
|
147
|
+
|
|
148
|
+
1. **Network reliability**: Ensure stable LAN connection to Buttress server
|
|
149
|
+
2. **Fallback strategy**: Configure appropriate fallback for critical features
|
|
150
|
+
3. **Server monitoring**: Monitor Buttress server resource usage
|
|
151
|
+
4. **Model consistency**: Ensure client and server use compatible models
|
|
152
|
+
5. **Security**: Run Buttress on private network, not public internet
|
|
153
|
+
6. **Latency awareness**: Account for network latency in UX design
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Data Calculation (JS Sandbox)
|
|
2
|
+
|
|
3
|
+
Transform and compute Data Bank values using JavaScript scripts.
|
|
4
|
+
|
|
5
|
+
## DataCalculationScript
|
|
6
|
+
|
|
7
|
+
JavaScript code executed in a sandbox with access to inputs and outputs.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { makeId } from 'bricks-project'
|
|
11
|
+
|
|
12
|
+
const calculation: DataCalculationScript = {
|
|
13
|
+
__typename: 'DataCalculationScript',
|
|
14
|
+
id: makeId('property_bank_calc'),
|
|
15
|
+
title: 'Format Price',
|
|
16
|
+
description: 'Formats price with currency symbol',
|
|
17
|
+
note: '',
|
|
18
|
+
triggerMode: 'auto', // 'auto' | 'manual'
|
|
19
|
+
enableAsync: false,
|
|
20
|
+
// Inline code
|
|
21
|
+
code: `
|
|
22
|
+
const price = inputs.price || 0
|
|
23
|
+
const currency = inputs.currency || 'USD'
|
|
24
|
+
return new Intl.NumberFormat('en-US', {
|
|
25
|
+
style: 'currency',
|
|
26
|
+
currency,
|
|
27
|
+
}).format(price)
|
|
28
|
+
`,
|
|
29
|
+
// Or load from file (preferred for longer scripts)
|
|
30
|
+
// code: await Bun.file(`${import.meta.dir}/format-price.sandbox.js`).text(),
|
|
31
|
+
inputs: [
|
|
32
|
+
{ key: 'price', data: () => priceData, trigger: true },
|
|
33
|
+
{ key: 'currency', data: () => currencyData, trigger: false },
|
|
34
|
+
],
|
|
35
|
+
output: () => formattedPriceData,
|
|
36
|
+
outputs: [], // Additional named outputs
|
|
37
|
+
error: null, // or () => errorData for error handling
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Trigger Modes
|
|
42
|
+
|
|
43
|
+
| Mode | Description |
|
|
44
|
+
|------|-------------|
|
|
45
|
+
| `auto` | Run when input values change (with trigger: true) |
|
|
46
|
+
| `manual` | Only run via `PROPERTY_BANK_COMMAND` action |
|
|
47
|
+
|
|
48
|
+
Use `manual` to prevent circular dependencies or for explicit control.
|
|
49
|
+
|
|
50
|
+
## Script Sandbox Features
|
|
51
|
+
|
|
52
|
+
Scripts run in `use strict` mode with a sandboxed set of globals and libraries.
|
|
53
|
+
|
|
54
|
+
### Built-in Globals
|
|
55
|
+
|
|
56
|
+
| Global | Description |
|
|
57
|
+
|--------|-------------|
|
|
58
|
+
| `inputs` | Object with input values |
|
|
59
|
+
| `console` | `{ log, error, warn, info }` for debugging |
|
|
60
|
+
| `Platform` | `{ OS, isTV, isPad, isVision, isElectron }` |
|
|
61
|
+
| `TextEncoder`, `TextDecoder` | Text encoding/decoding |
|
|
62
|
+
| `Buffer` | Node.js Buffer (without `allocUnsafe`) |
|
|
63
|
+
| `btoa`, `atob` | Base64 encoding/decoding |
|
|
64
|
+
|
|
65
|
+
### Available Libraries
|
|
66
|
+
|
|
67
|
+
**Utility**
|
|
68
|
+
| Library | Global | Description |
|
|
69
|
+
|---------|--------|-------------|
|
|
70
|
+
| [lodash](https://lodash.com) | `_`, `lodash` | Utility (sync: no debounce/delay/defer) |
|
|
71
|
+
| [voca](https://vocajs.com) | `voca` | String manipulation |
|
|
72
|
+
| [invariant](https://github.com/zertosh/invariant) | `invariant` | Assertions |
|
|
73
|
+
|
|
74
|
+
**Data & Encoding**
|
|
75
|
+
| Library | Global | Description |
|
|
76
|
+
|---------|--------|-------------|
|
|
77
|
+
| [json5](https://github.com/json5/json5) | `json5` | JSON5 parsing |
|
|
78
|
+
| [qs](https://github.com/ljharb/qs) | `qs` | Query string parsing |
|
|
79
|
+
| [url](https://github.com/defunctzombie/node-url) | `url` | URL parsing |
|
|
80
|
+
| [bytes](https://github.com/visionmedia/bytes.js) | `bytes` | Byte parsing/formatting |
|
|
81
|
+
| [ms](https://github.com/vercel/ms) | `ms` | Millisecond conversion |
|
|
82
|
+
| [base45](https://github.com/irony/base45) | `base45` | Base45 encoding |
|
|
83
|
+
| [iconv-lite](https://github.com/ashtuchkin/iconv-lite) | `iconv` | Character encoding |
|
|
84
|
+
|
|
85
|
+
**Math & Color**
|
|
86
|
+
| Library | Global | Description |
|
|
87
|
+
|---------|--------|-------------|
|
|
88
|
+
| [mathjs](https://mathjs.org) | `math`, `mathjs` | Math library |
|
|
89
|
+
| [chroma-js](https://gka.github.io/chroma.js) | `chroma` | Color manipulation |
|
|
90
|
+
|
|
91
|
+
**Date/Time**
|
|
92
|
+
| Library | Global | Description |
|
|
93
|
+
|---------|--------|-------------|
|
|
94
|
+
| [moment](https://momentjs.com) | `moment` | Date/time (auto parseFormat) |
|
|
95
|
+
|
|
96
|
+
**ID & Hash**
|
|
97
|
+
| Library | Global | Description |
|
|
98
|
+
|---------|--------|-------------|
|
|
99
|
+
| [nanoid](https://github.com/ai/nanoid) | `nanoid` | Unique ID generation |
|
|
100
|
+
| [md5](https://github.com/pvorb/node-md5) | `md5` | MD5 hashing |
|
|
101
|
+
|
|
102
|
+
**Crypto**
|
|
103
|
+
| Library | Global | Description |
|
|
104
|
+
|---------|--------|-------------|
|
|
105
|
+
| [crypto-browserify](https://github.com/crypto-browserify/crypto-browserify) | `crypto` | Crypto functions |
|
|
106
|
+
| [jsrsasign](https://github.com/kjur/jsrsasign) | `kjurJWS` | JWT/JWS signing |
|
|
107
|
+
| [cose-js](https://github.com/erdtman/COSE-JS) | `coseVerify` | COSE verification (sync) |
|
|
108
|
+
|
|
109
|
+
**Compression**
|
|
110
|
+
| Library | Global | Description |
|
|
111
|
+
|---------|--------|-------------|
|
|
112
|
+
| [fflate](https://github.com/101arrowz/fflate) | `fflate` | `{ zlibSync, unzlibSync, gzipSync, gunzipSync, compressSync, decompressSync, strFromU8 }` |
|
|
113
|
+
| [cbor](https://github.com/hildjj/node-cbor) | `cbor` | `{ encode, decode, decodeFirstSync, decodeAllSync }` |
|
|
114
|
+
|
|
115
|
+
**File & Document**
|
|
116
|
+
| Library | Global | Description |
|
|
117
|
+
|---------|--------|-------------|
|
|
118
|
+
| fs | `fs` | File system (limited, no download/upload) |
|
|
119
|
+
| [officeparser](https://github.com/nicktang) | `parseDocument` | Office document parsing (async) |
|
|
120
|
+
| [turndown](https://github.com/mixmark-io/turndown) | `TurndownService` | HTML to Markdown |
|
|
121
|
+
| [opencc-js](https://github.com/nk2028/opencc-js) | `OpenCC` | Chinese conversion `{ Converter, ConverterFactory, CustomConverter, Locale }` |
|
|
122
|
+
| [toon-format](https://github.com/nicktang) | `TOON` | TOON format parsing |
|
|
123
|
+
|
|
124
|
+
### Runtime Environment
|
|
125
|
+
|
|
126
|
+
| Platform | Engine |
|
|
127
|
+
|----------|--------|
|
|
128
|
+
| Android | Hermes engine sandbox |
|
|
129
|
+
| iOS | JavaScriptCore sandbox |
|
|
130
|
+
|
|
131
|
+
### Async Mode
|
|
132
|
+
|
|
133
|
+
Enable `enableAsync: true` to unlock additional capabilities:
|
|
134
|
+
|
|
135
|
+
**Additional async globals:**
|
|
136
|
+
- `Promise`, `setTimeout`, `setInterval`, `setImmediate`
|
|
137
|
+
- `clearTimeout`, `clearInterval`, `clearImmediate`
|
|
138
|
+
- `requestAnimationFrame`
|
|
139
|
+
- Full lodash (including `debounce`, `delay`, `defer`)
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
code: `
|
|
143
|
+
const result = await new Promise((resolve) => {
|
|
144
|
+
setTimeout(() => resolve(inputs.value * 2), 100)
|
|
145
|
+
})
|
|
146
|
+
return result
|
|
147
|
+
`,
|
|
148
|
+
enableAsync: true,
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Multiple Outputs
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
outputs: [
|
|
155
|
+
{ key: 'total', data: () => totalData },
|
|
156
|
+
{ key: 'tax', data: () => taxData },
|
|
157
|
+
{ key: 'subtotal', data: () => subtotalData },
|
|
158
|
+
],
|
|
159
|
+
code: `
|
|
160
|
+
const subtotal = inputs.price * inputs.quantity
|
|
161
|
+
const tax = subtotal * 0.1
|
|
162
|
+
const total = subtotal + tax
|
|
163
|
+
return { total, tax, subtotal }
|
|
164
|
+
`,
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Triggering Manually
|
|
168
|
+
|
|
169
|
+
Use `PROPERTY_BANK_COMMAND` system action to trigger a manual calculation:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const triggerCalc: EventAction = {
|
|
173
|
+
handler: 'system',
|
|
174
|
+
action: {
|
|
175
|
+
__actionName: 'PROPERTY_BANK_COMMAND',
|
|
176
|
+
parent: 'System',
|
|
177
|
+
dataParams: [
|
|
178
|
+
{ input: () => computeTotalCalc }, // Reference to DataCalculation
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Best Practices
|
|
185
|
+
|
|
186
|
+
1. **Avoid circular deps**: Set non-triggering inputs (`trigger: false`) or use `manual` mode
|
|
187
|
+
2. **Error handling**: Always set `error` output for scripts that might fail
|
|
188
|
+
3. **Keep scripts pure**: Avoid side effects, return computed values
|
|
189
|
+
4. **Debounce rapid updates**: Use `manual` mode + timer for high-frequency inputs
|
|
190
|
+
|
|
191
|
+
## Anti-Patterns (AVOID)
|
|
192
|
+
|
|
193
|
+
See [Architecture Patterns](architecture-patterns.md) for the full pattern selection guide.
|
|
194
|
+
|
|
195
|
+
### Using Data Calc as an orchestrator
|
|
196
|
+
Scripts that manage state machines, control UI flow, or coordinate multi-step processes belong in Event Action Chains, not here.
|
|
197
|
+
|
|
198
|
+
**Symptom**: Script has if/else branches deciding "what happens next" or tracks "current step".
|
|
199
|
+
|
|
200
|
+
### Quick reference
|
|
201
|
+
|
|
202
|
+
| If you need to... | Use instead |
|
|
203
|
+
|---|---|
|
|
204
|
+
| Call an LLM / AI model | Generator (Assistant, LLM, HTTP) |
|
|
205
|
+
| Sequence multiple actions | Event Action Chain |
|
|
206
|
+
| Set a data value directly | PROPERTY_BANK system action |
|
|
207
|
+
| Compute a simple expression | PROPERTY_BANK_EXPRESSION |
|
|
208
|
+
| Transform/format/parse data | Data Calculation (correct use) |
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Local Sync
|
|
2
|
+
|
|
3
|
+
Synchronize data between devices on a Local Area Network (LAN) without remote server storage. High synchronization rate for real-time multi-device experiences.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Update Data**: Sync Data Bank values across local devices
|
|
8
|
+
- **Execute Data Calculation**: Trigger calculations on other devices
|
|
9
|
+
- **No Remote Storage**: Direct device-to-device communication
|
|
10
|
+
|
|
11
|
+
## Main / Minor Device Model
|
|
12
|
+
|
|
13
|
+
| Role | Description |
|
|
14
|
+
|------|-------------|
|
|
15
|
+
| Main | Manages Data Bank if enabled, first device to start |
|
|
16
|
+
| Minor | Follows main device, subsequent devices |
|
|
17
|
+
|
|
18
|
+
### Role Determination
|
|
19
|
+
|
|
20
|
+
1. First device to start becomes Main
|
|
21
|
+
2. If simultaneous start: `Priority as Main Device` (0-9, set in Device Page) + random number determines Main
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
### Run Mode Options
|
|
26
|
+
|
|
27
|
+
| Mode | Description |
|
|
28
|
+
|------|-------------|
|
|
29
|
+
| `all` | Run on all devices |
|
|
30
|
+
| `main-only` | Only run on Main device |
|
|
31
|
+
| `minor-only` | Only run on Minor devices |
|
|
32
|
+
|
|
33
|
+
Apply run mode to:
|
|
34
|
+
- Data properties
|
|
35
|
+
- Generators
|
|
36
|
+
- Data Calculations
|
|
37
|
+
|
|
38
|
+
### Subspace Local Sync Settings
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const subspace: Subspace = {
|
|
42
|
+
__typename: 'Subspace',
|
|
43
|
+
id: 'main',
|
|
44
|
+
localSyncChangeCanvas: 'all', // 'all' | 'main-only' | 'minor-only' | 'none'
|
|
45
|
+
// ...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Data Local Sync
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { makeId } from 'bricks-project'
|
|
53
|
+
|
|
54
|
+
const data: Data = {
|
|
55
|
+
__typename: 'Data',
|
|
56
|
+
id: makeId('data'),
|
|
57
|
+
title: 'Shared Counter',
|
|
58
|
+
type: 'number',
|
|
59
|
+
value: 0,
|
|
60
|
+
localSyncUpdateMode: 'main-only', // 'main-only' | 'minor-only' | undefined (all)
|
|
61
|
+
events: {},
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Generator Local Sync
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { makeId } from 'bricks-project'
|
|
69
|
+
|
|
70
|
+
const generator: GeneratorTimer = {
|
|
71
|
+
__typename: 'Generator',
|
|
72
|
+
templateKey: 'Timer',
|
|
73
|
+
id: makeId('generator'),
|
|
74
|
+
title: 'Sync Timer',
|
|
75
|
+
description: '',
|
|
76
|
+
localSyncRunMode: 'main-only', // Timer only runs on main device
|
|
77
|
+
property: {},
|
|
78
|
+
events: {},
|
|
79
|
+
switches: [],
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Use Cases
|
|
84
|
+
|
|
85
|
+
### Synchronized Displays
|
|
86
|
+
Multiple screens showing coordinated content:
|
|
87
|
+
- Main device controls timing/state
|
|
88
|
+
- Minor devices follow state changes
|
|
89
|
+
|
|
90
|
+
### Interactive Kiosks
|
|
91
|
+
Touch on one device, update all:
|
|
92
|
+
- User interacts with input device (Minor)
|
|
93
|
+
- Main device processes and broadcasts result
|
|
94
|
+
- All devices update simultaneously
|
|
95
|
+
|
|
96
|
+
### Video Walls
|
|
97
|
+
Coordinated multi-screen layouts:
|
|
98
|
+
- Main device manages playback state
|
|
99
|
+
- Minor devices sync position/frame
|
|
100
|
+
|
|
101
|
+
## System Data
|
|
102
|
+
|
|
103
|
+
Access local sync status via System Data:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Is current device the main device?
|
|
107
|
+
systemData.isLocalSyncMainDevice // boolean
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Important Notes
|
|
111
|
+
|
|
112
|
+
1. **Version Matching**: All devices must use same BRICKS Foundation minor version
|
|
113
|
+
- ✅ v2.11.0 matches v2.11.1
|
|
114
|
+
- ❌ v2.11.0 does NOT match v2.10.8
|
|
115
|
+
|
|
116
|
+
2. **Network Requirements**:
|
|
117
|
+
- All devices on same LAN
|
|
118
|
+
- mDNS/Bonjour enabled
|
|
119
|
+
- Firewall allows local discovery
|
|
120
|
+
|
|
121
|
+
3. **Startup Order**: Consider device startup sequence when Main role matters
|
|
122
|
+
|
|
123
|
+
## Best Practices
|
|
124
|
+
|
|
125
|
+
1. **Designate Main explicitly**: Set high `Priority as Main Device` on intended main
|
|
126
|
+
2. **Idempotent logic**: Design for eventual consistency, not strict ordering
|
|
127
|
+
3. **Minimal sync scope**: Only enable local sync for data that truly needs it
|
|
128
|
+
4. **Test multi-device**: Validate behavior with actual device count
|
|
129
|
+
5. **Handle disconnection**: Design for graceful degradation if devices disconnect
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Media Flow
|
|
2
|
+
|
|
3
|
+
Centralized media asset management for BRICKS applications. Store, organize, and reference images, videos, and audio files.
|
|
4
|
+
|
|
5
|
+
## Enable Media Workspace
|
|
6
|
+
|
|
7
|
+
1. Visit `Media` tab in workspace page
|
|
8
|
+
2. Enable media workspace for your workspace
|
|
9
|
+
|
|
10
|
+
## Media Box
|
|
11
|
+
|
|
12
|
+
Organize assets into boxes (folders). Each box can contain files of various types.
|
|
13
|
+
|
|
14
|
+
### Generator Media Flow
|
|
15
|
+
|
|
16
|
+
Use `Generator Media Flow` to:
|
|
17
|
+
- Get file list from a box
|
|
18
|
+
- Download files
|
|
19
|
+
- Subscribe to box changes
|
|
20
|
+
|
|
21
|
+
Quick setup: Create new Property with `As Media Resource file list?` option.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { makeId } from 'bricks-project'
|
|
25
|
+
|
|
26
|
+
const mediaListGenerator: GeneratorMediaFlow = {
|
|
27
|
+
__typename: 'Generator',
|
|
28
|
+
templateKey: 'MediaFlow',
|
|
29
|
+
id: makeId('generator'),
|
|
30
|
+
title: 'Promo Images',
|
|
31
|
+
description: '',
|
|
32
|
+
property: {
|
|
33
|
+
boxId: 'promo-box-id',
|
|
34
|
+
},
|
|
35
|
+
outlets: {
|
|
36
|
+
files: () => promoFilesData, // Array of file objects
|
|
37
|
+
},
|
|
38
|
+
events: {},
|
|
39
|
+
switches: [],
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Property Kinds for Media
|
|
44
|
+
|
|
45
|
+
Link Data properties to Media Flow for asset selection:
|
|
46
|
+
|
|
47
|
+
| Kind | Description |
|
|
48
|
+
|------|-------------|
|
|
49
|
+
| `media-resource-image` | Image asset selector |
|
|
50
|
+
| `media-resource-video` | Video asset selector |
|
|
51
|
+
| `media-resource-audio` | Audio asset selector |
|
|
52
|
+
| `lottie-file-uri` | Lottie animation selector |
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { makeId } from 'bricks-project'
|
|
56
|
+
|
|
57
|
+
const backgroundImage: Data = {
|
|
58
|
+
__typename: 'Data',
|
|
59
|
+
id: makeId('data'),
|
|
60
|
+
title: 'Background Image',
|
|
61
|
+
type: 'string',
|
|
62
|
+
kind: { type: 'media-resource-image' },
|
|
63
|
+
value: '',
|
|
64
|
+
events: {},
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Assets with these kinds are **preloaded** during application launch.
|
|
69
|
+
|
|
70
|
+
## Compatible Bricks & Generators
|
|
71
|
+
|
|
72
|
+
### Bricks
|
|
73
|
+
- **Brick Image**: Display images from Media Flow
|
|
74
|
+
- **Brick Video**: Play videos from Media Flow
|
|
75
|
+
- **Brick Lottie**: Render Lottie animations
|
|
76
|
+
- **Brick Slideshow**: Cycle through Media Flow file list
|
|
77
|
+
|
|
78
|
+
### Generators
|
|
79
|
+
- **Generator Sound Player**: Play audio files
|
|
80
|
+
- **Generator File Reader**: Read file contents
|
|
81
|
+
|
|
82
|
+
## Slideshow with Media Flow
|
|
83
|
+
|
|
84
|
+
Connect Generator Media Flow output to Brick Slideshow:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { makeId, linkData } from 'bricks-project'
|
|
88
|
+
|
|
89
|
+
const slideshow: BrickSlideshow = {
|
|
90
|
+
__typename: 'Brick',
|
|
91
|
+
templateKey: 'Slideshow',
|
|
92
|
+
id: makeId('brick'),
|
|
93
|
+
title: 'Promo Slideshow',
|
|
94
|
+
description: '',
|
|
95
|
+
property: {
|
|
96
|
+
images: linkData(() => promoFilesData),
|
|
97
|
+
interval: 5000, // ms between slides
|
|
98
|
+
transition: 'fade',
|
|
99
|
+
},
|
|
100
|
+
events: {},
|
|
101
|
+
switches: [],
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## File Object Structure
|
|
106
|
+
|
|
107
|
+
Files from Media Flow include:
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
interface MediaFile {
|
|
111
|
+
id: string
|
|
112
|
+
name: string
|
|
113
|
+
url: string
|
|
114
|
+
thumbnailUrl?: string
|
|
115
|
+
mimeType: string
|
|
116
|
+
size: number
|
|
117
|
+
width?: number // For images/videos
|
|
118
|
+
height?: number
|
|
119
|
+
duration?: number // For videos/audio
|
|
120
|
+
createdAt: string
|
|
121
|
+
updatedAt: string
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Upload & Management
|
|
126
|
+
|
|
127
|
+
### Via Editor
|
|
128
|
+
1. Open Media tab in BRICKS Editor
|
|
129
|
+
2. Select or create a box
|
|
130
|
+
3. Drag & drop files or use upload button
|
|
131
|
+
|
|
132
|
+
### Via CLI
|
|
133
|
+
```bash
|
|
134
|
+
bricks media boxes # List media boxes
|
|
135
|
+
bricks media box <box-id> # Box details
|
|
136
|
+
bricks media files <box-id> # List files in box
|
|
137
|
+
bricks media file <file-id> # File details
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> Note: CLI currently supports read-only operations. Upload is not yet supported.
|
|
141
|
+
|
|
142
|
+
### Via API
|
|
143
|
+
Use BRICKS API for programmatic upload and management.
|
|
144
|
+
|
|
145
|
+
## Screenshot Storage
|
|
146
|
+
|
|
147
|
+
Automation `Match Screenshot` can save screenshots to Media Flow workspace:
|
|
148
|
+
- Baseline images stored in specified box
|
|
149
|
+
- Easy visual comparison and management
|
|
150
|
+
|
|
151
|
+
## Best Practices
|
|
152
|
+
|
|
153
|
+
1. **Organize by purpose**: Create boxes for different content types (backgrounds, icons, videos)
|
|
154
|
+
2. **Optimize assets**: Compress images/videos before upload
|
|
155
|
+
3. **Preload critical assets**: Use `media-resource-*` kinds for important visuals
|
|
156
|
+
4. **Slideshow performance**: Limit file count and resolution for smooth playback
|
|
157
|
+
5. **Version control**: Use box naming conventions for content versions
|
|
158
|
+
6. **CDN benefit**: Media Flow URLs are CDN-backed for fast delivery
|