@fugood/bricks-ctor 2.24.0-beta.40

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.
Files changed (129) hide show
  1. package/compile/action-name-map.ts +988 -0
  2. package/compile/index.ts +1245 -0
  3. package/compile/util.ts +358 -0
  4. package/index.ts +6 -0
  5. package/package.json +28 -0
  6. package/skills/bricks-design/LICENSE.txt +180 -0
  7. package/skills/bricks-design/SKILL.md +66 -0
  8. package/skills/bricks-project/SKILL.md +32 -0
  9. package/skills/bricks-project/rules/animation.md +159 -0
  10. package/skills/bricks-project/rules/architecture-patterns.md +69 -0
  11. package/skills/bricks-project/rules/automations.md +221 -0
  12. package/skills/bricks-project/rules/buttress.md +156 -0
  13. package/skills/bricks-project/rules/data-calculation.md +208 -0
  14. package/skills/bricks-project/rules/local-sync.md +129 -0
  15. package/skills/bricks-project/rules/media-flow.md +158 -0
  16. package/skills/bricks-project/rules/remote-data-bank.md +196 -0
  17. package/skills/bricks-project/rules/standby-transition.md +124 -0
  18. package/skills/rive-marketplace/SKILL.md +99 -0
  19. package/tools/deploy.ts +151 -0
  20. package/tools/icons/.gitattributes +1 -0
  21. package/tools/icons/fa6pro-glyphmap.json +4686 -0
  22. package/tools/icons/fa6pro-meta.json +3671 -0
  23. package/tools/mcp-server.ts +28 -0
  24. package/tools/mcp-tools/compile.ts +91 -0
  25. package/tools/mcp-tools/huggingface.ts +762 -0
  26. package/tools/mcp-tools/icons.ts +70 -0
  27. package/tools/mcp-tools/lottie.ts +102 -0
  28. package/tools/mcp-tools/media.ts +110 -0
  29. package/tools/postinstall.ts +229 -0
  30. package/tools/preview-main.mjs +293 -0
  31. package/tools/preview.ts +143 -0
  32. package/tools/pull.ts +116 -0
  33. package/tsconfig.json +16 -0
  34. package/types/animation.ts +100 -0
  35. package/types/automation.ts +235 -0
  36. package/types/brick-base.ts +80 -0
  37. package/types/bricks/Camera.ts +246 -0
  38. package/types/bricks/Chart.ts +372 -0
  39. package/types/bricks/GenerativeMedia.ts +276 -0
  40. package/types/bricks/Icon.ts +98 -0
  41. package/types/bricks/Image.ts +114 -0
  42. package/types/bricks/Items.ts +476 -0
  43. package/types/bricks/Lottie.ts +168 -0
  44. package/types/bricks/Maps.ts +262 -0
  45. package/types/bricks/QrCode.ts +117 -0
  46. package/types/bricks/Rect.ts +150 -0
  47. package/types/bricks/RichText.ts +128 -0
  48. package/types/bricks/Rive.ts +220 -0
  49. package/types/bricks/Slideshow.ts +201 -0
  50. package/types/bricks/Svg.ts +99 -0
  51. package/types/bricks/Text.ts +148 -0
  52. package/types/bricks/TextInput.ts +242 -0
  53. package/types/bricks/Video.ts +175 -0
  54. package/types/bricks/VideoStreaming.ts +112 -0
  55. package/types/bricks/WebRtcStream.ts +65 -0
  56. package/types/bricks/WebView.ts +168 -0
  57. package/types/bricks/index.ts +21 -0
  58. package/types/canvas.ts +82 -0
  59. package/types/common.ts +144 -0
  60. package/types/data-calc-command.ts +7005 -0
  61. package/types/data-calc-script.ts +21 -0
  62. package/types/data-calc.ts +11 -0
  63. package/types/data.ts +95 -0
  64. package/types/generators/AlarmClock.ts +110 -0
  65. package/types/generators/Assistant.ts +621 -0
  66. package/types/generators/BleCentral.ts +247 -0
  67. package/types/generators/BlePeripheral.ts +208 -0
  68. package/types/generators/CanvasMap.ts +74 -0
  69. package/types/generators/CastlesPay.ts +87 -0
  70. package/types/generators/DataBank.ts +160 -0
  71. package/types/generators/File.ts +432 -0
  72. package/types/generators/GraphQl.ts +132 -0
  73. package/types/generators/Http.ts +222 -0
  74. package/types/generators/HttpServer.ts +176 -0
  75. package/types/generators/Information.ts +103 -0
  76. package/types/generators/Intent.ts +168 -0
  77. package/types/generators/Iterator.ts +108 -0
  78. package/types/generators/Keyboard.ts +105 -0
  79. package/types/generators/LlmAnthropicCompat.ts +212 -0
  80. package/types/generators/LlmAppleBuiltin.ts +159 -0
  81. package/types/generators/LlmGgml.ts +861 -0
  82. package/types/generators/LlmMediaTekNeuroPilot.ts +235 -0
  83. package/types/generators/LlmMlx.ts +227 -0
  84. package/types/generators/LlmOnnx.ts +213 -0
  85. package/types/generators/LlmOpenAiCompat.ts +244 -0
  86. package/types/generators/LlmQualcommAiEngine.ts +247 -0
  87. package/types/generators/Mcp.ts +637 -0
  88. package/types/generators/McpServer.ts +289 -0
  89. package/types/generators/MediaFlow.ts +170 -0
  90. package/types/generators/MqttBroker.ts +141 -0
  91. package/types/generators/MqttClient.ts +141 -0
  92. package/types/generators/Question.ts +408 -0
  93. package/types/generators/RealtimeTranscription.ts +279 -0
  94. package/types/generators/RerankerGgml.ts +191 -0
  95. package/types/generators/SerialPort.ts +151 -0
  96. package/types/generators/SoundPlayer.ts +94 -0
  97. package/types/generators/SoundRecorder.ts +130 -0
  98. package/types/generators/SpeechToTextGgml.ts +415 -0
  99. package/types/generators/SpeechToTextOnnx.ts +236 -0
  100. package/types/generators/SpeechToTextPlatform.ts +85 -0
  101. package/types/generators/SqLite.ts +159 -0
  102. package/types/generators/Step.ts +107 -0
  103. package/types/generators/SttAppleBuiltin.ts +130 -0
  104. package/types/generators/Tcp.ts +126 -0
  105. package/types/generators/TcpServer.ts +147 -0
  106. package/types/generators/TextToSpeechAppleBuiltin.ts +127 -0
  107. package/types/generators/TextToSpeechGgml.ts +221 -0
  108. package/types/generators/TextToSpeechOnnx.ts +178 -0
  109. package/types/generators/TextToSpeechOpenAiLike.ts +121 -0
  110. package/types/generators/ThermalPrinter.ts +191 -0
  111. package/types/generators/Tick.ts +83 -0
  112. package/types/generators/Udp.ts +120 -0
  113. package/types/generators/VadGgml.ts +250 -0
  114. package/types/generators/VadOnnx.ts +231 -0
  115. package/types/generators/VadTraditional.ts +138 -0
  116. package/types/generators/VectorStore.ts +257 -0
  117. package/types/generators/Watchdog.ts +107 -0
  118. package/types/generators/WebCrawler.ts +103 -0
  119. package/types/generators/WebRtc.ts +181 -0
  120. package/types/generators/WebSocket.ts +148 -0
  121. package/types/generators/index.ts +57 -0
  122. package/types/index.ts +13 -0
  123. package/types/subspace.ts +59 -0
  124. package/types/switch.ts +51 -0
  125. package/types/system.ts +707 -0
  126. package/utils/calc.ts +126 -0
  127. package/utils/data.ts +497 -0
  128. package/utils/event-props.ts +836 -0
  129. package/utils/id.ts +80 -0
@@ -0,0 +1,159 @@
1
+ # Animation
2
+
3
+ BRICKS Animation system for animating brick transforms and opacity. Animations are defined at the Subspace level and triggered via events or Dynamic Animation actions.
4
+
5
+ ## Animation Types
6
+
7
+ ### Timing Animation
8
+ Standard duration-based animation with easing.
9
+
10
+ ```typescript
11
+ import { makeId } from 'bricks-ctor'
12
+
13
+ const fadeIn: AnimationDef = {
14
+ __typename: 'Animation',
15
+ id: makeId('animation'),
16
+ title: 'Fade In',
17
+ runType: 'once', // 'once' | 'loop'
18
+ property: 'opacity',
19
+ config: {
20
+ __type: 'AnimationTimingConfig',
21
+ toValue: 1,
22
+ duration: 300, // ms
23
+ easing: 'easeOutCubic',
24
+ delay: 0, // ms
25
+ isInteraction: true,
26
+ },
27
+ }
28
+ ```
29
+
30
+ ### Spring Animation
31
+ Physics-based spring animation.
32
+
33
+ ```typescript
34
+ const bounce: AnimationDef = {
35
+ __typename: 'Animation',
36
+ id: makeId('animation'),
37
+ title: 'Bounce In',
38
+ property: 'transform.scale',
39
+ config: {
40
+ __type: 'AnimationSpringConfig',
41
+ toValue: 1,
42
+ friction: 7,
43
+ tension: 40,
44
+ speed: 12,
45
+ bounciness: 8,
46
+ },
47
+ }
48
+ ```
49
+
50
+ ### Decay Animation
51
+ Velocity-based deceleration animation.
52
+
53
+ ```typescript
54
+ const slideOut: AnimationDef = {
55
+ __typename: 'Animation',
56
+ id: makeId('animation'),
57
+ title: 'Slide Out',
58
+ property: 'transform.translateX',
59
+ config: {
60
+ __type: 'AnimationDecayConfig',
61
+ toValue: 500,
62
+ velocity: 0.5,
63
+ deceleration: 0.997,
64
+ isInteraction: true,
65
+ },
66
+ }
67
+ ```
68
+
69
+ ## Animatable Properties
70
+
71
+ | Property | Description |
72
+ |----------|-------------|
73
+ | `transform.translateX` | Horizontal position offset |
74
+ | `transform.translateY` | Vertical position offset |
75
+ | `transform.scale` | Uniform scale |
76
+ | `transform.scaleX` | Horizontal scale |
77
+ | `transform.scaleY` | Vertical scale |
78
+ | `transform.rotate` | Rotation (degrees) |
79
+ | `transform.rotateX` | X-axis rotation |
80
+ | `transform.rotateY` | Y-axis rotation |
81
+ | `opacity` | Transparency (0-1) |
82
+
83
+ ## Easing Functions
84
+
85
+ Standard easing from [easings.net](https://easings.net):
86
+ - `easeInSine`, `easeOutSine`, `easeInOutSine`
87
+ - `easeInQuad`, `easeOutQuad`, `easeInOutQuad`
88
+ - `easeInCubic`, `easeOutCubic`, `easeInOutCubic`
89
+ - `easeInQuart`, `easeOutQuart`, `easeInOutQuart`
90
+ - `easeInQuint`, `easeOutQuint`, `easeInOutQuint`
91
+ - `easeInExpo`, `easeOutExpo`, `easeInOutExpo`
92
+ - `easeInCirc`, `easeOutCirc`, `easeInOutCirc`
93
+ - `easeInBack`, `easeOutBack`, `easeInOutBack`
94
+ - `easeInElastic`, `easeOutElastic`, `easeInOutElastic`
95
+ - `easeInBounce`, `easeOutBounce`, `easeInOutBounce`
96
+ - Custom: `'cubic-bezier(x1, y1, x2, y2)'`
97
+
98
+ ## Composed Animations
99
+
100
+ Combine multiple animations in parallel or sequence.
101
+
102
+ ```typescript
103
+ const enterAnimation: AnimationComposeDef = {
104
+ __typename: 'AnimationCompose',
105
+ id: makeId('animation'),
106
+ title: 'Enter Animation',
107
+ runType: 'once',
108
+ composeType: 'parallel', // 'parallel' | 'sequence'
109
+ items: [
110
+ () => fadeIn,
111
+ () => scaleUp,
112
+ ],
113
+ }
114
+ ```
115
+
116
+ ## Brick Animation Events
117
+
118
+ Bricks support automatic animation binding:
119
+
120
+ ```typescript
121
+ // In brick definition
122
+ animations: {
123
+ showStart: () => fadeInAnimation, // On brick first render
124
+ standby: () => standbyAnimation, // After standby transition
125
+ breatheStart: () => pulseAnimation, // Breathing effect (looping)
126
+ }
127
+ ```
128
+
129
+ ## Dynamic Animation (Runtime)
130
+
131
+ Trigger animations programmatically via System Action:
132
+
133
+ ```typescript
134
+ const runAnimation: EventAction = {
135
+ handler: 'system',
136
+ action: {
137
+ __actionName: 'DYNAMIC_ANIMATION',
138
+ parent: 'System',
139
+ params: [
140
+ { input: 'brickId', value: () => targetBrick },
141
+ { input: 'animationId', value: () => pulseAnimation },
142
+ { input: 'runType', value: 'once' }, // 'once' | 'loop'
143
+ { input: 'resetInitialValue', value: false },
144
+ ],
145
+ },
146
+ }
147
+ ```
148
+
149
+ Related actions:
150
+ - `DYNAMIC_ANIMATION_RESET` - Reset animation state
151
+ - `DYNAMIC_ANIMATION_STOP` - Stop running animation
152
+
153
+ ## Best Practices
154
+
155
+ 1. **Performance**: Keep animations simple, prefer `opacity` and `transform` over layout changes
156
+ 2. **Timing**: Use `easeOut` for enter animations, `easeIn` for exit
157
+ 3. **Spring animations**: Good for natural, bouncy UI elements
158
+ 4. **Looping**: Use `runType: 'loop'` for attention-grabbing elements
159
+ 5. **Composition**: Use `sequence` for staged reveals, `parallel` for coordinated effects
@@ -0,0 +1,69 @@
1
+ # Architecture Patterns
2
+
3
+ How to decompose complex flows into the right combination of BRICKS patterns.
4
+
5
+ ## Pattern Selection Priority
6
+
7
+ Prefer higher-priority patterns; only fall to lower when they genuinely can't solve the sub-problem:
8
+
9
+ | Priority | Pattern | Use For |
10
+ |----------|---------|---------|
11
+ | 1 | Generator + Events | I/O, AI inference, external data |
12
+ | 2 | Event Action Chains | Orchestration, sequential steps |
13
+ | 3 | System Actions | State changes, navigation, UI triggers |
14
+ | 4 | Data Calculation | Pure data transformation ONLY |
15
+
16
+ ### Generators (Priority 1)
17
+ For all external I/O and AI inference. Each generator emits events that naturally chain into actions.
18
+ - **GeneratorAssistant**: multi-turn LLM conversations, function calling, built-in message history
19
+ - **GeneratorLLM**: single-shot local inference (GGML)
20
+ - **GeneratorHttp**: REST API calls
21
+ - **GeneratorMqtt / GeneratorWebSocket**: real-time messaging
22
+
23
+ ### Event Action Chains (Priority 2)
24
+ The primary way to orchestrate multi-step flows. A single event can contain an array of EventActions executed sequentially.
25
+ - Use `waitAsync: true` to await async actions before the next step
26
+ - Use `dataParams` + `mapping` to pass event data downstream
27
+ - This is the "glue" that wires generators, state, and UI together
28
+
29
+ ### System Actions (Priority 3)
30
+ Built-in commands for direct state and UI changes.
31
+ - **PROPERTY_BANK**: set data value
32
+ - **PROPERTY_BANK_EXPRESSION**: inline JS expression for simple compute
33
+ - **CHANGE_CANVAS**: navigate to another canvas
34
+ - **DYNAMIC_ANIMATION**: trigger animation
35
+ - **ALERT / MESSAGE**: system feedback
36
+
37
+ ### Data Calculation (Priority 4)
38
+ ONLY for deriving, formatting, or aggregating values from other data. Not for orchestration, side effects, or flow control.
39
+
40
+ ## Entity Aliases
41
+
42
+ Set `alias` on entities to give them a stable, human-readable name:
43
+ - Code generation uses alias as the variable name (e.g., `alias: 'submitBtn'` → `export const submitBtn`)
44
+ - At runtime, devtools MCP tools accept alias instead of short ID and selectors can match by alias. Note: bricks-ctor does not directly interact with devtools MCP — aliases here primarily affect code generation
45
+ - Aliases must be unique across the application — duplicates are excluded from resolution
46
+
47
+ ## Flow Decomposition
48
+
49
+ When the user describes a complex flow, decompose it BEFORE writing code:
50
+
51
+ ### Step 1: Extract I/O boundaries
52
+ Every external interaction maps to a Generator:
53
+ - "call LLM" → GeneratorAssistant or GeneratorLLM
54
+ - "fetch API" → GeneratorHttp
55
+ - "speech to text" → GeneratorSpeechInference
56
+
57
+ ### Step 2: Extract state transitions
58
+ Every UI change maps to a System Action in an event chain:
59
+ - "show loading" → PROPERTY_BANK on a boolean data
60
+ - "go to result screen" → CHANGE_CANVAS
61
+ - "animate in" → DYNAMIC_ANIMATION
62
+
63
+ ### Step 3: Extract pure transformations
64
+ Only actual data derivation maps to Data Calculation:
65
+ - "format the response" → DataCalculationScript
66
+ - "compute a score" → DataCalculationScript or DataCalculationMap
67
+
68
+ ### Step 4: Wire with Event Action Chains
69
+ Connect the pieces through events on generators and bricks.
@@ -0,0 +1,221 @@
1
+ # Automations
2
+
3
+ E2E testing and scheduled execution for BRICKS applications. Simulates user behavior and validates application state.
4
+
5
+ ## Automation Types
6
+
7
+ | Type | Description |
8
+ | --------- | ---------------------------------------------------------- |
9
+ | `launch` | Run on application launch (restarts app when run manually) |
10
+ | `anytime` | Execute anytime via manual trigger |
11
+ | `cron` | Scheduled execution using crontab expressions |
12
+
13
+ ## Simulation Actions
14
+
15
+ Automations can simulate:
16
+
17
+ - **Brick Press**: Tap/click on bricks
18
+ - **Key Events**: Key up/down for keyboard input
19
+ - **HTTP Request**: API calls
20
+ - **Execute Action**: Trigger system or generator actions
21
+
22
+ ## Assertions
23
+
24
+ Automations can validate:
25
+
26
+ - **Brick Exists**: Check if brick is rendered
27
+ - **Event Triggered**: Verify event from Brick/Generator/Canvas
28
+ - **Canvas Changed**: Confirm canvas navigation
29
+ - **Property Assert**: Check Data Bank values
30
+ - **Property Updated**: Wait for property change
31
+ - **Match Screenshot**: Visual regression testing
32
+
33
+ ## TypeScript Example
34
+
35
+ ```typescript
36
+ const testLoginFlow: AutomationTest = {
37
+ __typename: 'AutomationTest',
38
+ id: makeId('test'),
39
+ title: 'Test Login Flow',
40
+ timeout: 30000,
41
+ trigger_type: 'launch',
42
+ cases: [
43
+ {
44
+ __typename: 'TestCase',
45
+ id: makeId('test_case'),
46
+ name: 'Wait for login canvas',
47
+ run: ['wait_until_canvas_change', () => mainSubspace, () => loginCanvas, 5000],
48
+ exit_on_failed: true,
49
+ commented: false,
50
+ pre_delay: 0,
51
+ post_delay: 0,
52
+ jump_cond: [],
53
+ },
54
+ {
55
+ __typename: 'TestCase',
56
+ id: makeId('test_case'),
57
+ name: 'Press username input',
58
+ run: ['brick_press', () => mainSubspace, () => usernameInput],
59
+ exit_on_failed: true,
60
+ commented: false,
61
+ pre_delay: 0,
62
+ post_delay: 100,
63
+ jump_cond: [],
64
+ },
65
+ {
66
+ __typename: 'TestCase',
67
+ id: makeId('test_case'),
68
+ name: 'Assert username value',
69
+ run: ['assert_property', () => mainSubspace, () => usernameData, 'testuser'],
70
+ exit_on_failed: true,
71
+ commented: false,
72
+ pre_delay: 0,
73
+ post_delay: 0,
74
+ jump_cond: [],
75
+ },
76
+ {
77
+ __typename: 'TestCase',
78
+ id: makeId('test_case'),
79
+ name: 'Press login button',
80
+ run: ['brick_press', () => mainSubspace, () => loginButton],
81
+ exit_on_failed: true,
82
+ commented: false,
83
+ pre_delay: 0,
84
+ post_delay: 0,
85
+ jump_cond: [],
86
+ },
87
+ {
88
+ __typename: 'TestCase',
89
+ id: makeId('test_case'),
90
+ name: 'Wait for dashboard',
91
+ run: ['wait_until_canvas_change', () => mainSubspace, () => dashboardCanvas, 10000],
92
+ exit_on_failed: true,
93
+ commented: false,
94
+ pre_delay: 0,
95
+ post_delay: 0,
96
+ jump_cond: [],
97
+ },
98
+ ],
99
+ variables: [],
100
+ }
101
+ ```
102
+
103
+ ## Test Methods
104
+
105
+ | Method | Signature | Description |
106
+ | ---------------------------- | ------------------------------------------------ | -------------------- |
107
+ | `brick_press` | `[subspace, brick, options?]` | Simulate brick press |
108
+ | `brick_exists` | `[subspace, brick, frame?]` | Check brick exists |
109
+ | `wait_until_brick_exists` | `[subspace, brick, timeout?, frame?]` | Wait for brick |
110
+ | `wait_until_event_trigger` | `[subspace, sender, eventKey, timeout?]` | Wait for event |
111
+ | `wait_until_canvas_change` | `[subspace, canvas, timeout?]` | Wait for canvas |
112
+ | `keydown` | `[keyCode, pressedKey?, flags?]` | Key down event |
113
+ | `keyup` | `[keyCode, pressedKey?, flags?]` | Key up event |
114
+ | `http_request` | `[url, options?]` | HTTP request |
115
+ | `assert_property` | `[subspace, property, value]` | Assert data value |
116
+ | `wait_until_property_change` | `[subspace, property, value, timeout?]` | Wait for value |
117
+ | `execute_action` | `[subspace, handler, action, params?, options?]` | Execute action |
118
+ | `match_screenshot` | `[name, threshold?, maxRetry?]` | Screenshot compare |
119
+ | `delay` | `[subspace?, property?, defaultValue?]` | Delay execution |
120
+
121
+ ### execute_action Params
122
+
123
+ The `params` object in `execute_action` uses **runtime event property keys** from `event-props.ts`, NOT the action config `input` names from type definitions.
124
+
125
+ ```typescript
126
+ // CORRECT — use runtime event property key
127
+ run: ['execute_action', () => subspace0, bricks.bInput.id, 'BRICK_TEXT_INPUT_SET_TEXT',
128
+ { BRICK_TEXT_INPUT_TEXT: 'hello' }]
129
+
130
+ // WRONG — action config input name doesn't work in automation
131
+ run: ['execute_action', () => subspace0, bricks.bInput.id, 'BRICK_TEXT_INPUT_SET_TEXT',
132
+ { text: 'hello' }]
133
+ ```
134
+
135
+ Reference `event-props.ts` for the correct runtime keys (e.g., `BRICK_TEXT_INPUT_TEXT`, `GENERATOR_MQTT_PAYLOAD`).
136
+
137
+ ### Prefer UI Interactions Over Direct Generator Calls
138
+
139
+ For realistic E2E testing, prefer simulating user actions (set text input + press button) over calling generator actions directly:
140
+
141
+ ```typescript
142
+ // GOOD — simulates real user behavior
143
+ { run: ['execute_action', () => sub, bricks.bInput.id, 'BRICK_TEXT_INPUT_SET_TEXT',
144
+ { BRICK_TEXT_INPUT_TEXT: 'hello' }] },
145
+ { run: ['brick_press', () => sub, () => bricks.bSendBtn] },
146
+ { run: ['wait_until_property_change', () => sub, () => data.dPayload, 'hello', 10000] },
147
+
148
+ // AVOID — bypasses UI, doesn't test the full flow
149
+ { run: ['execute_action', () => sub, generators.gClient.id, 'GENERATOR_MQTT_PUBLISH',
150
+ { topic: 'test', payload: 'hello', qos: '0' }] },
151
+ ```
152
+
153
+ ## Recording Automations
154
+
155
+ In BRICKS Editor Preview mode:
156
+
157
+ 1. Perform operations normally
158
+ 2. Open menu (right-bottom corner)
159
+ 3. Select "Record Events as Automation"
160
+ 4. Generated automation appears in Automations list
161
+
162
+ ## Running Automations
163
+
164
+ ### Manual Run
165
+
166
+ `Menu` → `Automations` → Select automation → `Run`
167
+
168
+ ### On Launch
169
+
170
+ `Bind Device` → `Select Automation` (only `launch` or `cron` types)
171
+
172
+ ### Scheduled (Cron)
173
+
174
+ `Bind Device` → `Cron Automation` (allows multi-select)
175
+
176
+ Use [crontab.guru](https://crontab.guru) to build cron expressions.
177
+
178
+ ## Screenshot Testing
179
+
180
+ Visual regression testing with screenshot comparison:
181
+
182
+ ```typescript
183
+ {
184
+ __typename: 'TestCase',
185
+ id: makeId('test_case'),
186
+ name: 'Match dashboard screenshot',
187
+ run: ['match_screenshot', 'dashboard-initial-state', 0.01, 3],
188
+ exit_on_failed: true,
189
+ commented: false,
190
+ pre_delay: 500, // Wait for UI to settle
191
+ post_delay: 0,
192
+ jump_cond: [],
193
+ }
194
+ ```
195
+
196
+ Screenshots can be stored:
197
+
198
+ - Local file system
199
+ - Media Flow workspace
200
+
201
+ First run captures baseline. Use "Run with Update" to update baseline.
202
+
203
+ ## Module Support
204
+
205
+ Automations work with Modules. Use Manual Run in Preview mode for module testing.
206
+
207
+ ## Important Notes
208
+
209
+ - **Automation map key**: Always use `'AUTOMATION_MAP_DEFAULT'` as the automation map ID (not `makeId()`). The preview test runner reads from `automationMap['AUTOMATION_MAP_DEFAULT']?.map`.
210
+ - **Valid makeId types**: Use `'test'` for AutomationTest, `'test_case'` for TestCase, `'test_var'` for TestVariable. Do NOT use `'automation_test'` or `'automation_test_map'`.
211
+ - **handler in execute_action**: Pass the entity's `.id` string (e.g., `bricks.bInput.id`), not a getter function.
212
+
213
+ ## Best Practices
214
+
215
+ 1. **Test culture**: Create automations for every significant flow
216
+ 2. **CI/CD integration**: Use `launch` automations for deployment validation
217
+ 3. **Incremental waits**: Use `wait_until_property_change` with appropriate timeouts
218
+ 4. **Visual testing**: Add screenshot comparisons for critical UI states
219
+ 5. **Cron monitoring**: Schedule health checks for production displays
220
+ 6. **Isolation**: Each automation should be independent and idempotent
221
+ 7. **UI-first testing**: Simulate real user interactions (text input, button press) rather than calling generators directly
@@ -0,0 +1,156 @@
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) (LlmMlx.ts) - Local Large Language Model inference with GGML
18
+ - LLM (MLX) (LlmGgml.ts) - Local Large Language Model inference with MLX
19
+ - Speech-to-Text (GGML) (SpeechToTextGgml.ts) - Local Speech-to-Text inference with GGML
20
+
21
+ ## Client Configuration
22
+
23
+ In generator properties, configure Buttress settings:
24
+
25
+ | Setting | Description |
26
+ |---------|-------------|
27
+ | `Enabled` | Toggle Buttress offloading |
28
+ | `URL` | Buttress server URL (e.g., `http://192.168.1.100:2080`) |
29
+ | `Fallback Type` | Action if Buttress unavailable: `use-local` or `no-op` |
30
+ | `Strategy` | Execution preference |
31
+
32
+ ### Strategy Options
33
+
34
+ | Strategy | Description |
35
+ |----------|-------------|
36
+ | `prefer-local` | Use local if capable, fallback to Buttress |
37
+ | `prefer-buttress` | Use Buttress if available, fallback to local |
38
+ | `prefer-best` | Auto-select based on capability comparison |
39
+
40
+ ## Generator Configuration Example
41
+
42
+ ```typescript
43
+ import { makeId } from 'bricks-ctor'
44
+
45
+ const llmGenerator: GeneratorLLM = {
46
+ __typename: 'Generator',
47
+ templateKey: 'GENERATOR_LLM',
48
+ id: makeId('generator'),
49
+ title: 'Chat LLM',
50
+ description: '',
51
+ property: {
52
+ modelUrl: 'https://huggingface.co/ggml-org/gemma-3-12b-it-qat-GGUF/resolve/main/gemma-3-12b-it-qat-q4_0.gguf',
53
+ contextSize: 8192,
54
+ buttressConnectionSettings: {
55
+ enabled: true,
56
+ url: 'http://192.168.1.100:2080',
57
+ fallbackType: 'use-local',
58
+ strategy: 'prefer-best',
59
+ },
60
+ },
61
+ events: {},
62
+ switches: [],
63
+ }
64
+ ```
65
+
66
+ ## Server Setup
67
+
68
+ ### Requirements
69
+ - [Bun](https://bun.sh) v1.3+
70
+ - GPU recommended for LLM/STT
71
+
72
+ ### Installation
73
+
74
+ ```bash
75
+ bun add -g @fugood/buttress-server
76
+ ```
77
+
78
+ ### Start Server
79
+
80
+ ```bash
81
+ bricks-buttress
82
+ # or with config
83
+ bricks-buttress --config ./config.toml
84
+ ```
85
+
86
+ ### CLI Options
87
+
88
+ | Option | Description |
89
+ |--------|-------------|
90
+ | `-p, --port` | Port (default: 2080) |
91
+ | `-c, --config` | TOML config file path |
92
+ | `-v, --version` | Show version |
93
+ | `-h, --help` | Show help |
94
+
95
+ ### Environment Variables
96
+
97
+ | Variable | Description |
98
+ |----------|-------------|
99
+ | `HF_TOKEN` | Hugging Face token for model downloads |
100
+ | `ENABLE_OPENAI_COMPAT_ENDPOINT` | Set to `1` for OpenAI-compatible API |
101
+
102
+ ## Server Configuration (TOML)
103
+
104
+ ```toml
105
+ [server]
106
+ port = 2080
107
+
108
+ [runtime]
109
+ cache_dir = "./.buttress-cache"
110
+ n_threads = 6
111
+ flash_attn_type = "on"
112
+ cache_type_k = "q8_0"
113
+ cache_type_v = "q8_0"
114
+
115
+ # LLM Generator
116
+ [[generators]]
117
+ type = "ggml-llm"
118
+ [generators.backend]
119
+ variant_preference = ["cuda", "vulkan", "default"]
120
+ gpu_memory_fraction = 0.95
121
+ [generators.model]
122
+ repo_id = "ggml-org/gemma-3-12b-it-qat-GGUF"
123
+ download = true
124
+ n_ctx = 8192
125
+
126
+ # STT Generator
127
+ [[generators]]
128
+ type = "ggml-stt"
129
+ [generators.backend]
130
+ variant_preference = ["cuda", "vulkan", "default"]
131
+ [generators.model]
132
+ repo_id = "BricksDisplay/whisper-ggml"
133
+ filename = "ggml-small-q8_0.bin"
134
+ download = true
135
+ use_gpu = true
136
+ ```
137
+
138
+ ## Use Cases
139
+
140
+ ### Resource-Constrained Devices
141
+ Digital signage with basic hardware offloads LLM to powerful server.
142
+
143
+ ### Shared GPU Resources
144
+ Multiple devices share single GPU server for inference.
145
+
146
+ ### Development Testing
147
+ Test AI features on lightweight dev machines by connecting to beefy server.
148
+
149
+ ## Best Practices
150
+
151
+ 1. **Network reliability**: Ensure stable LAN connection to Buttress server
152
+ 2. **Fallback strategy**: Configure appropriate fallback for critical features
153
+ 3. **Server monitoring**: Monitor Buttress server resource usage
154
+ 4. **Model consistency**: Ensure client and server use compatible models
155
+ 5. **Security**: Run Buttress on private network, not public internet
156
+ 6. **Latency awareness**: Account for network latency in UX design