@fugood/bricks-ctor 2.25.0-beta.5 → 2.25.0-beta.50

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 (185) hide show
  1. package/compile/__tests__/config-diff.test.js +100 -0
  2. package/compile/__tests__/index.test.js +365 -0
  3. package/compile/__tests__/util.test.js +317 -0
  4. package/compile/action-name-map.ts +64 -0
  5. package/compile/config-diff.ts +155 -0
  6. package/compile/index.ts +273 -32
  7. package/compile/util.ts +26 -7
  8. package/package.json +7 -3
  9. package/skills/bricks-ctor/SKILL.md +23 -17
  10. package/skills/bricks-ctor/{rules → references}/animation.md +3 -2
  11. package/skills/bricks-ctor/{rules → references}/architecture-patterns.md +18 -0
  12. package/skills/bricks-ctor/{rules → references}/automations.md +11 -0
  13. package/skills/bricks-ctor/references/buttress.md +245 -0
  14. package/skills/bricks-ctor/references/data-calculation.md +239 -0
  15. package/skills/bricks-ctor/references/simulator.md +132 -0
  16. package/skills/bricks-ctor/references/source-editing-tools.md +81 -0
  17. package/skills/bricks-ctor/references/verification-toolchain.md +200 -0
  18. package/skills/bricks-design/SKILL.md +150 -45
  19. package/skills/bricks-design/references/architecture-truths.md +132 -0
  20. package/skills/bricks-design/references/avoiding-complexity.md +91 -0
  21. package/skills/bricks-design/references/design-critique.md +195 -0
  22. package/skills/bricks-design/references/design-languages.md +265 -0
  23. package/skills/bricks-design/references/performance.md +116 -0
  24. package/skills/bricks-design/references/presentation-and-slideshow.md +137 -0
  25. package/skills/bricks-design/references/translating-inputs.md +152 -0
  26. package/skills/bricks-design/references/variations-and-tweaks.md +124 -0
  27. package/skills/bricks-design/references/when-the-brief-is-branded.md +284 -0
  28. package/skills/bricks-design/references/when-the-brief-is-vague.md +85 -0
  29. package/skills/bricks-design/references/workflow.md +134 -0
  30. package/skills/bricks-ux/SKILL.md +114 -0
  31. package/skills/bricks-ux/references/accessibility.md +162 -0
  32. package/skills/bricks-ux/references/flow-states.md +175 -0
  33. package/skills/bricks-ux/references/interaction-archetypes.md +189 -0
  34. package/skills/bricks-ux/references/monitoring-screens.md +153 -0
  35. package/skills/bricks-ux/references/pressable-composition.md +126 -0
  36. package/skills/bricks-ux/references/user-journey.md +168 -0
  37. package/skills/bricks-ux/references/ux-critique.md +256 -0
  38. package/tools/__tests__/_cli-error.test.ts +35 -0
  39. package/tools/_cli-error.ts +17 -0
  40. package/tools/_edits-log.ts +41 -0
  41. package/tools/_git-author.ts +10 -2
  42. package/tools/_last-pushed-commit.ts +28 -0
  43. package/tools/_shell.ts +8 -1
  44. package/tools/deploy.ts +17 -6
  45. package/tools/mcp-env.ts +13 -0
  46. package/tools/mcp-server.ts +8 -0
  47. package/tools/mcp-tools/__tests__/data-calc-editing.test.js +516 -0
  48. package/tools/mcp-tools/__tests__/entry-editing.test.js +866 -0
  49. package/tools/mcp-tools/__tests__/huggingface.test.ts +49 -0
  50. package/tools/mcp-tools/__tests__/icons.test.ts +21 -0
  51. package/tools/mcp-tools/__tests__/mcp-env.test.js +19 -0
  52. package/tools/mcp-tools/_editing-helpers.ts +58 -0
  53. package/tools/mcp-tools/_verify.ts +50 -0
  54. package/tools/mcp-tools/compile.ts +21 -9
  55. package/tools/mcp-tools/data-calc-editing.ts +1349 -0
  56. package/tools/mcp-tools/entry-editing.ts +2336 -0
  57. package/tools/mcp-tools/huggingface.ts +23 -13
  58. package/tools/mcp-tools/icons.ts +23 -7
  59. package/tools/mcp-tools/media.ts +4 -1
  60. package/tools/postinstall.ts +80 -3
  61. package/tools/pull.ts +93 -22
  62. package/tools/push-config.ts +114 -0
  63. package/tools/{preview-main.mjs → simulator-main.mjs} +207 -12
  64. package/tools/simulator-preload.cjs +16 -0
  65. package/tools/{preview.ts → simulator.ts} +4 -4
  66. package/types/{animation.ts → animation.d.ts} +24 -8
  67. package/types/{automation.ts → automation.d.ts} +16 -20
  68. package/types/{brick-base.ts → brick-base.d.ts} +1 -1
  69. package/types/bricks/{Camera.ts → Camera.d.ts} +8 -8
  70. package/types/bricks/{Chart.ts → Chart.d.ts} +4 -4
  71. package/types/bricks/{GenerativeMedia.ts → GenerativeMedia.d.ts} +15 -15
  72. package/types/bricks/{Icon.ts → Icon.d.ts} +7 -7
  73. package/types/bricks/{Image.ts → Image.d.ts} +21 -9
  74. package/types/bricks/{Items.ts → Items.d.ts} +7 -7
  75. package/types/bricks/{Lottie.ts → Lottie.d.ts} +10 -10
  76. package/types/bricks/{Maps.ts → Maps.d.ts} +11 -11
  77. package/types/bricks/{QrCode.ts → QrCode.d.ts} +7 -7
  78. package/types/bricks/{Rect.ts → Rect.d.ts} +7 -7
  79. package/types/bricks/{RichText.ts → RichText.d.ts} +12 -9
  80. package/types/bricks/{Rive.ts → Rive.d.ts} +9 -9
  81. package/types/bricks/Scene3D.d.ts +676 -0
  82. package/types/bricks/{Sketch.ts → Sketch.d.ts} +6 -6
  83. package/types/bricks/{Slideshow.ts → Slideshow.d.ts} +7 -7
  84. package/types/bricks/{Svg.ts → Svg.d.ts} +7 -7
  85. package/types/bricks/{Text.ts → Text.d.ts} +9 -9
  86. package/types/bricks/{TextInput.ts → TextInput.d.ts} +10 -10
  87. package/types/bricks/{Video.ts → Video.d.ts} +12 -12
  88. package/types/bricks/{VideoStreaming.ts → VideoStreaming.d.ts} +10 -10
  89. package/types/bricks/{WebRtcStream.ts → WebRtcStream.d.ts} +1 -1
  90. package/types/bricks/{WebView.ts → WebView.d.ts} +4 -4
  91. package/types/bricks/{index.ts → index.d.ts} +1 -0
  92. package/types/{common.ts → common.d.ts} +3 -6
  93. package/types/data-calc-command/base.d.ts +57 -0
  94. package/types/data-calc-command/collection.d.ts +418 -0
  95. package/types/data-calc-command/color.d.ts +432 -0
  96. package/types/data-calc-command/constant.d.ts +50 -0
  97. package/types/data-calc-command/datetime.d.ts +147 -0
  98. package/types/data-calc-command/file.d.ts +129 -0
  99. package/types/data-calc-command/index.d.ts +13 -0
  100. package/types/data-calc-command/iteratee.d.ts +23 -0
  101. package/types/data-calc-command/logictype.d.ts +190 -0
  102. package/types/data-calc-command/math.d.ts +275 -0
  103. package/types/data-calc-command/object.d.ts +119 -0
  104. package/types/data-calc-command/sandbox.d.ts +66 -0
  105. package/types/data-calc-command/string.d.ts +407 -0
  106. package/types/{data-calc.ts → data-calc.d.ts} +1 -0
  107. package/types/{data.ts → data.d.ts} +4 -2
  108. package/types/generators/{Assistant.ts → Assistant.d.ts} +19 -0
  109. package/types/generators/{LlmGgml.ts → LlmGgml.d.ts} +43 -1
  110. package/types/generators/{LlmMlx.ts → LlmMlx.d.ts} +1 -0
  111. package/types/generators/{RerankerGgml.ts → RerankerGgml.d.ts} +5 -1
  112. package/types/generators/{SoundRecorder.ts → SoundRecorder.d.ts} +10 -1
  113. package/types/generators/{SpeechToTextGgml.ts → SpeechToTextGgml.d.ts} +6 -1
  114. package/types/generators/{SttAppleBuiltin.ts → SttAppleBuiltin.d.ts} +27 -4
  115. package/types/generators/{ThermalPrinter.ts → ThermalPrinter.d.ts} +9 -7
  116. package/types/generators/{VadGgml.ts → VadGgml.d.ts} +12 -2
  117. package/types/{subspace.ts → subspace.d.ts} +1 -1
  118. package/utils/__tests__/calc.test.js +25 -0
  119. package/utils/__tests__/id.test.js +154 -0
  120. package/utils/calc.ts +5 -1
  121. package/utils/data.ts +5 -7
  122. package/utils/event-props.ts +17 -0
  123. package/utils/id.ts +109 -56
  124. package/skills/bricks-ctor/rules/buttress.md +0 -156
  125. package/skills/bricks-ctor/rules/data-calculation.md +0 -209
  126. package/skills/bricks-design/LICENSE.txt +0 -180
  127. package/types/data-calc-command.ts +0 -7005
  128. /package/skills/bricks-ctor/{rules → references}/local-sync.md +0 -0
  129. /package/skills/bricks-ctor/{rules → references}/media-flow.md +0 -0
  130. /package/skills/bricks-ctor/{rules → references}/remote-data-bank.md +0 -0
  131. /package/skills/bricks-ctor/{rules → references}/standby-transition.md +0 -0
  132. /package/types/{canvas.ts → canvas.d.ts} +0 -0
  133. /package/types/{data-calc-script.ts → data-calc-script.d.ts} +0 -0
  134. /package/types/generators/{AlarmClock.ts → AlarmClock.d.ts} +0 -0
  135. /package/types/generators/{BleCentral.ts → BleCentral.d.ts} +0 -0
  136. /package/types/generators/{BlePeripheral.ts → BlePeripheral.d.ts} +0 -0
  137. /package/types/generators/{CanvasMap.ts → CanvasMap.d.ts} +0 -0
  138. /package/types/generators/{CastlesPay.ts → CastlesPay.d.ts} +0 -0
  139. /package/types/generators/{DataBank.ts → DataBank.d.ts} +0 -0
  140. /package/types/generators/{File.ts → File.d.ts} +0 -0
  141. /package/types/generators/{GraphQl.ts → GraphQl.d.ts} +0 -0
  142. /package/types/generators/{Http.ts → Http.d.ts} +0 -0
  143. /package/types/generators/{HttpServer.ts → HttpServer.d.ts} +0 -0
  144. /package/types/generators/{Information.ts → Information.d.ts} +0 -0
  145. /package/types/generators/{Intent.ts → Intent.d.ts} +0 -0
  146. /package/types/generators/{Iterator.ts → Iterator.d.ts} +0 -0
  147. /package/types/generators/{Keyboard.ts → Keyboard.d.ts} +0 -0
  148. /package/types/generators/{LlmAnthropicCompat.ts → LlmAnthropicCompat.d.ts} +0 -0
  149. /package/types/generators/{LlmAppleBuiltin.ts → LlmAppleBuiltin.d.ts} +0 -0
  150. /package/types/generators/{LlmMediaTekNeuroPilot.ts → LlmMediaTekNeuroPilot.d.ts} +0 -0
  151. /package/types/generators/{LlmOnnx.ts → LlmOnnx.d.ts} +0 -0
  152. /package/types/generators/{LlmOpenAiCompat.ts → LlmOpenAiCompat.d.ts} +0 -0
  153. /package/types/generators/{LlmQualcommAiEngine.ts → LlmQualcommAiEngine.d.ts} +0 -0
  154. /package/types/generators/{Mcp.ts → Mcp.d.ts} +0 -0
  155. /package/types/generators/{McpServer.ts → McpServer.d.ts} +0 -0
  156. /package/types/generators/{MediaFlow.ts → MediaFlow.d.ts} +0 -0
  157. /package/types/generators/{MqttBroker.ts → MqttBroker.d.ts} +0 -0
  158. /package/types/generators/{MqttClient.ts → MqttClient.d.ts} +0 -0
  159. /package/types/generators/{Question.ts → Question.d.ts} +0 -0
  160. /package/types/generators/{RealtimeTranscription.ts → RealtimeTranscription.d.ts} +0 -0
  161. /package/types/generators/{SerialPort.ts → SerialPort.d.ts} +0 -0
  162. /package/types/generators/{SoundPlayer.ts → SoundPlayer.d.ts} +0 -0
  163. /package/types/generators/{SpeechToTextOnnx.ts → SpeechToTextOnnx.d.ts} +0 -0
  164. /package/types/generators/{SpeechToTextPlatform.ts → SpeechToTextPlatform.d.ts} +0 -0
  165. /package/types/generators/{SqLite.ts → SqLite.d.ts} +0 -0
  166. /package/types/generators/{Step.ts → Step.d.ts} +0 -0
  167. /package/types/generators/{Tcp.ts → Tcp.d.ts} +0 -0
  168. /package/types/generators/{TcpServer.ts → TcpServer.d.ts} +0 -0
  169. /package/types/generators/{TextToSpeechAppleBuiltin.ts → TextToSpeechAppleBuiltin.d.ts} +0 -0
  170. /package/types/generators/{TextToSpeechGgml.ts → TextToSpeechGgml.d.ts} +0 -0
  171. /package/types/generators/{TextToSpeechOnnx.ts → TextToSpeechOnnx.d.ts} +0 -0
  172. /package/types/generators/{TextToSpeechOpenAiLike.ts → TextToSpeechOpenAiLike.d.ts} +0 -0
  173. /package/types/generators/{Tick.ts → Tick.d.ts} +0 -0
  174. /package/types/generators/{Udp.ts → Udp.d.ts} +0 -0
  175. /package/types/generators/{VadOnnx.ts → VadOnnx.d.ts} +0 -0
  176. /package/types/generators/{VadTraditional.ts → VadTraditional.d.ts} +0 -0
  177. /package/types/generators/{VectorStore.ts → VectorStore.d.ts} +0 -0
  178. /package/types/generators/{Watchdog.ts → Watchdog.d.ts} +0 -0
  179. /package/types/generators/{WebCrawler.ts → WebCrawler.d.ts} +0 -0
  180. /package/types/generators/{WebRtc.ts → WebRtc.d.ts} +0 -0
  181. /package/types/generators/{WebSocket.ts → WebSocket.d.ts} +0 -0
  182. /package/types/generators/{index.ts → index.d.ts} +0 -0
  183. /package/types/{index.ts → index.d.ts} +0 -0
  184. /package/types/{switch.ts → switch.d.ts} +0 -0
  185. /package/types/{system.ts → system.d.ts} +0 -0
@@ -0,0 +1,317 @@
1
+ import { generateCalulationMap, validateConfig } from '../util'
2
+
3
+ const baseConfig = (overrides = {}) => ({
4
+ inputs: {},
5
+ enable_async: false,
6
+ disabled_triggers: {},
7
+ output: null,
8
+ outputs: {},
9
+ error: null,
10
+ code: 'return inputs',
11
+ ...overrides,
12
+ })
13
+
14
+ const SANDBOX_PREFIX = 'PROPERTY_BANK_COMMAND_NODE_'
15
+
16
+ const sandboxNodeIds = (map) =>
17
+ Object.entries(map)
18
+ .filter(([id, node]) => id.startsWith(SANDBOX_PREFIX) && node.type === 'command-node-sandbox')
19
+ .map(([id, node]) => ({ id, command: node.properties.command }))
20
+
21
+ const findSandboxIds = (map) => {
22
+ const sandbox = sandboxNodeIds(map)
23
+ return {
24
+ run: sandbox.find((s) => s.command === 'SANDBOX_RUN_JAVASCRIPT')?.id,
25
+ error: sandbox.find((s) => s.command === 'SANDBOX_GET_ERROR')?.id,
26
+ result: sandbox.find((s) => s.command === 'SANDBOX_GET_RETURN_VALUE')?.id,
27
+ }
28
+ }
29
+
30
+ describe('validateConfig', () => {
31
+ test('returns without throwing for a clean config', () => {
32
+ expect(() => validateConfig(baseConfig({ inputs: { a: 'foo' } }))).not.toThrow()
33
+ })
34
+
35
+ test('skips overlap checks in manual trigger mode', () => {
36
+ const config = baseConfig({
37
+ trigger_mode: 'manual',
38
+ inputs: { a: 'foo' },
39
+ output: 'a',
40
+ error: 'a',
41
+ outputs: { x: ['a'] },
42
+ })
43
+ expect(() => validateConfig(config)).not.toThrow()
44
+ })
45
+
46
+ test('throws when error key collides with an input id', () => {
47
+ const config = baseConfig({ inputs: { a: 'foo' }, error: 'a' })
48
+ expect(() => validateConfig(config)).toThrow(/key: error/)
49
+ })
50
+
51
+ test('throws when output key collides with an input id', () => {
52
+ const config = baseConfig({ inputs: { a: 'foo' }, output: 'a' })
53
+ expect(() => validateConfig(config)).toThrow(/key: output/)
54
+ })
55
+
56
+ test('throws when any outputs entry references an input id', () => {
57
+ const config = baseConfig({
58
+ inputs: { a: 'foo', b: 'bar' },
59
+ outputs: { x: ['c', 'b'] },
60
+ })
61
+ expect(() => validateConfig(config)).toThrow(/key: outputs/)
62
+ })
63
+
64
+ test('does not throw when error/output are falsy and inputs are empty', () => {
65
+ expect(() => validateConfig(baseConfig())).not.toThrow()
66
+ })
67
+
68
+ test('throws when error and output target the same id', () => {
69
+ const config = baseConfig({ output: 'shared', error: 'shared' })
70
+ expect(() => validateConfig(config)).toThrow(/key: error\/output/)
71
+ })
72
+
73
+ test('throws when output collides with an outputs target id', () => {
74
+ const config = baseConfig({ output: 'shared', outputs: { x: ['shared'] } })
75
+ expect(() => validateConfig(config)).toThrow(/key: output\/outputs/)
76
+ })
77
+
78
+ test('throws when error collides with an outputs target id', () => {
79
+ const config = baseConfig({ error: 'shared', outputs: { x: ['shared'] } })
80
+ expect(() => validateConfig(config)).toThrow(/key: error\/outputs/)
81
+ })
82
+
83
+ // The same id reused across *different* outputs entries is a supported last-wins case
84
+ // (see generateCalulationMap test below) and must stay allowed.
85
+ test('allows the same id across multiple outputs entries', () => {
86
+ const config = baseConfig({ outputs: { first: ['pb1'], second: ['pb1'] } })
87
+ expect(() => validateConfig(config)).not.toThrow()
88
+ })
89
+ })
90
+
91
+ // generateCalulationMap now seeds command ids from the owning calc id; tests that don't
92
+ // assert id values share one fixed id (ids stay deterministic with no global state).
93
+ const CALC_ID = 'PROPERTY_BANK_COMMAND_MAP_00000000-0000-4000-8000-000000000000'
94
+ const genMap = (config, calcId = CALC_ID) => generateCalulationMap(config, calcId)
95
+
96
+ describe('generateCalulationMap', () => {
97
+ test('produces only the three sandbox nodes for an empty config', () => {
98
+ const result = genMap(baseConfig())
99
+
100
+ expect(Object.keys(result.map)).toHaveLength(3)
101
+ const { run, error, result: returnValue } = findSandboxIds(result.map)
102
+
103
+ expect(result.map[run].in.inputs).toEqual([])
104
+ expect(result.map[error].out.result).toEqual([])
105
+ expect(result.map[returnValue].out.result).toEqual([])
106
+ expect(Object.keys(result.editor_info)).toHaveLength(3)
107
+ })
108
+
109
+ test('chains multiple inputs through OBJECT_SET commands', () => {
110
+ const result = genMap(baseConfig({ inputs: { a: 'foo.bar', b: 'baz' } }))
111
+
112
+ const { run } = findSandboxIds(result.map)
113
+
114
+ // Each input gets a data-node + an OBJECT_SET command-node.
115
+ expect(result.map.a.type).toBe('data-node')
116
+ expect(result.map.b.type).toBe('data-node')
117
+
118
+ const aCommandId = result.map.a.out.value[0].id
119
+ const bCommandId = result.map.b.out.value[0].id
120
+ expect(aCommandId).not.toBe(bCommandId)
121
+
122
+ const aCmd = result.map[aCommandId]
123
+ const bCmd = result.map[bCommandId]
124
+ expect(aCmd.properties.command).toBe('OBJECT_SET')
125
+ expect(aCmd.properties.args.path).toBe('foo.bar')
126
+ expect(bCmd.properties.command).toBe('OBJECT_SET')
127
+ expect(bCmd.properties.args.path).toBe('baz')
128
+
129
+ // First command has no upstream obj; second command's obj input is the first command.
130
+ expect(aCmd.in.obj).toBeNull()
131
+ expect(bCmd.in.obj).toEqual([{ id: aCommandId, port: 'result' }])
132
+ // First command forwards its result to the second command's `obj` input.
133
+ expect(aCmd.out.result).toEqual([{ id: bCommandId, port: 'obj' }])
134
+ // The last command feeds the SANDBOX_RUN_JAVASCRIPT `inputs` port.
135
+ expect(bCmd.out.result).toEqual([{ id: run, port: 'inputs' }])
136
+ expect(result.map[run].in.inputs).toEqual([{ id: bCommandId, port: 'result' }])
137
+ })
138
+
139
+ test('builds OBJECT_GET commands and target data-nodes for outputs', () => {
140
+ const result = genMap(baseConfig({ outputs: { resultPath: ['pb1', 'pb2'] } }))
141
+
142
+ const { result: returnValue } = findSandboxIds(result.map)
143
+
144
+ // Both target property-bank nodes are created as data-nodes.
145
+ expect(result.map.pb1.type).toBe('data-node')
146
+ expect(result.map.pb2.type).toBe('data-node')
147
+
148
+ // The SANDBOX_GET_RETURN_VALUE forwards to the OBJECT_GET command for the output entry.
149
+ const objectGetRefs = result.map[returnValue].out.result
150
+ expect(objectGetRefs).toHaveLength(1)
151
+ const getCommandId = objectGetRefs[0].id
152
+ expect(objectGetRefs[0].port).toBe('obj')
153
+
154
+ const getCmd = result.map[getCommandId]
155
+ expect(getCmd.type).toBe('command-node-object')
156
+ expect(getCmd.properties.command).toBe('OBJECT_GET')
157
+ expect(getCmd.properties.args.path).toBe('resultPath')
158
+ expect(getCmd.in.obj).toEqual([{ id: returnValue, port: 'result' }])
159
+
160
+ // OBJECT_GET feeds both target data-nodes' `change` ports.
161
+ expect(getCmd.out.result).toEqual([
162
+ { id: 'pb1', port: 'change' },
163
+ { id: 'pb2', port: 'change' },
164
+ ])
165
+ // Target data-nodes consume the OBJECT_GET result via their `change` port.
166
+ expect(result.map.pb1.in.change).toEqual([{ id: getCommandId, port: 'result' }])
167
+ expect(result.map.pb2.in.change).toEqual([{ id: getCommandId, port: 'result' }])
168
+
169
+ // Without input usage their `out.value` defaults to null.
170
+ expect(result.map.pb1.out.value).toBeNull()
171
+ expect(result.map.pb2.out.value).toBeNull()
172
+ })
173
+
174
+ // Manual mode is the only mode that lets an output target reuse an input id
175
+ // (see validateConfig tests). When that happens, generateCalulationMap must
176
+ // keep the input-side `out.value` so the data-node remains a usable input.
177
+ test.each([
178
+ ['outputs', { outputs: { result: ['shared'] } }],
179
+ ['output', { output: 'shared' }],
180
+ ['error', { error: 'shared' }],
181
+ ])('preserves input out.value when %s target reuses an input id', (_, overrides) => {
182
+ const result = genMap(
183
+ baseConfig({ trigger_mode: 'manual', inputs: { shared: 'foo' }, ...overrides }),
184
+ )
185
+ expect(Array.isArray(result.map.shared.out.value)).toBe(true)
186
+ expect(result.map[result.map.shared.out.value[0].id].properties.command).toBe('OBJECT_SET')
187
+ })
188
+
189
+ test('also rewires in.change to OBJECT_GET when an outputs target reuses an input id', () => {
190
+ const result = genMap(
191
+ baseConfig({
192
+ trigger_mode: 'manual',
193
+ inputs: { shared: 'foo' },
194
+ outputs: { result: ['shared'] },
195
+ }),
196
+ )
197
+ expect(result.map.shared.in.change).toHaveLength(1)
198
+ expect(result.map[result.map.shared.in.change[0].id].properties.command).toBe('OBJECT_GET')
199
+ })
200
+
201
+ test('preserves out.value when the same pb appears in multiple outputs entries', () => {
202
+ // Two outputs entries both target `pb1`. The reduce visits each entry in turn
203
+ // and must preserve the accumulated `out.value` from the first iteration via
204
+ // `acc.map[pb]` rather than wiping it on the second.
205
+ const result = genMap(baseConfig({ outputs: { first: ['pb1'], second: ['pb1'] } }))
206
+ expect(result.map.pb1.type).toBe('data-node')
207
+ // Without an input, out.value remains null after both passes.
208
+ expect(result.map.pb1.out.value).toBeNull()
209
+ // The latest OBJECT_GET wins as the change source — each iteration overwrites
210
+ // `in.change`, so we end up pointing at the second outputs entry's command.
211
+ expect(result.map.pb1.in.change).toHaveLength(1)
212
+ })
213
+
214
+ test('wires the error data-node when error is configured', () => {
215
+ const result = genMap(baseConfig({ error: 'errNode' }))
216
+
217
+ const { error } = findSandboxIds(result.map)
218
+ // SANDBOX_GET_ERROR now broadcasts to the error data-node's `change` port.
219
+ expect(result.map[error].out.result).toEqual([{ id: 'errNode', port: 'change' }])
220
+ expect(result.map.errNode.type).toBe('data-node')
221
+ expect(result.map.errNode.in.change).toEqual([{ id: error, port: 'result' }])
222
+ // No upstream input → out.value falls back to null.
223
+ expect(result.map.errNode.out.value).toBeNull()
224
+ // editor_info contains the new node.
225
+ expect(result.editor_info.errNode).toBeDefined()
226
+ })
227
+
228
+ test('wires the output data-node when output is configured', () => {
229
+ const result = genMap(baseConfig({ output: 'outNode' }))
230
+
231
+ const { result: returnValue } = findSandboxIds(result.map)
232
+ expect(result.map[returnValue].out.result).toEqual([{ id: 'outNode', port: 'change' }])
233
+ expect(result.map.outNode.type).toBe('data-node')
234
+ expect(result.map.outNode.in.change).toEqual([{ id: returnValue, port: 'result' }])
235
+ expect(result.editor_info.outNode).toBeDefined()
236
+ })
237
+
238
+ test('manual trigger mode sets disable_trigger_command on input value ports', () => {
239
+ const result = genMap(
240
+ baseConfig({
241
+ trigger_mode: 'manual',
242
+ inputs: { a: 'foo', b: 'bar' },
243
+ }),
244
+ )
245
+ const aCmdId = result.map.a.out.value[0].id
246
+ const bCmdId = result.map.b.out.value[0].id
247
+ expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBe(true)
248
+ expect(result.map[bCmdId].in.value[0].disable_trigger_command).toBe(true)
249
+ })
250
+
251
+ test('auto trigger mode honours per-key disabled_triggers', () => {
252
+ const result = genMap(
253
+ baseConfig({
254
+ inputs: { a: 'foo', b: 'bar' },
255
+ disabled_triggers: { a: true, b: false },
256
+ }),
257
+ )
258
+ const aCmdId = result.map.a.out.value[0].id
259
+ const bCmdId = result.map.b.out.value[0].id
260
+ expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBe(true)
261
+ // Falsy disabled_triggers entry → property is not set (or set to undefined).
262
+ expect(result.map[bCmdId].in.value[0].disable_trigger_command).toBeUndefined()
263
+ })
264
+
265
+ test('auto trigger mode without disabled_triggers leaves disable_trigger_command undefined', () => {
266
+ const result = genMap(baseConfig({ inputs: { a: 'foo' } }))
267
+ const aCmdId = result.map.a.out.value[0].id
268
+ expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBeUndefined()
269
+ })
270
+
271
+ test('derives command ids deterministically from the calc id (stable across compiles)', () => {
272
+ const config = baseConfig({ inputs: { a: 'foo' }, outputs: { out: ['pb1'] } })
273
+ const first = generateCalulationMap(config, CALC_ID)
274
+ const second = generateCalulationMap(config, CALC_ID)
275
+ // Same calc id + same config must yield byte-identical ids, so recompiling unchanged
276
+ // source produces no spurious property_bank_calc_map diff.
277
+ expect(Object.keys(second.map)).toEqual(Object.keys(first.map))
278
+
279
+ const uuid = '[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}'
280
+ sandboxNodeIds(first.map).forEach(({ id }) => {
281
+ expect(id).toMatch(new RegExp(`^PROPERTY_BANK_COMMAND_NODE_${uuid}$`))
282
+ })
283
+ })
284
+
285
+ test('seeds command ids per calc so different calcs never collide (edit isolation)', () => {
286
+ const config = baseConfig({ inputs: { a: 'foo' } })
287
+ const a = generateCalulationMap(
288
+ config,
289
+ 'PROPERTY_BANK_COMMAND_MAP_aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa',
290
+ )
291
+ const b = generateCalulationMap(
292
+ config,
293
+ 'PROPERTY_BANK_COMMAND_MAP_bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb',
294
+ )
295
+ expect(findSandboxIds(a.map).run).not.toBe(findSandboxIds(b.map).run)
296
+ })
297
+
298
+ test('validateConfig errors propagate out of generateCalulationMap', () => {
299
+ expect(() => genMap(baseConfig({ inputs: { a: 'foo' }, error: 'a' }))).toThrow(/key: error/)
300
+ })
301
+
302
+ test('SANDBOX_GET_RETURN_VALUE broadcasts to both output target and outputs commands', () => {
303
+ const result = genMap(
304
+ baseConfig({
305
+ output: 'outNode',
306
+ outputs: { foo: ['pb1'] },
307
+ }),
308
+ )
309
+ const { result: returnValue } = findSandboxIds(result.map)
310
+ const refs = result.map[returnValue].out.result
311
+ // First entry is the output data-node's `change` port; remainder are OBJECT_GET ids.
312
+ expect(refs[0]).toEqual({ id: 'outNode', port: 'change' })
313
+ expect(refs).toHaveLength(2)
314
+ expect(refs[1].port).toBe('obj')
315
+ expect(result.map[refs[1].id].properties.command).toBe('OBJECT_GET')
316
+ })
317
+ })
@@ -350,6 +350,63 @@ export const templateActionNameMap = {
350
350
  strokeWidth: 'BRICK_SKETCH_STROKE_WIDTH',
351
351
  },
352
352
  },
353
+ BRICK_SCENE_3D: {
354
+ BRICK_SCENE_3D_ADD_OBJECT: {
355
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
356
+ objectType: 'BRICK_SCENE_3D_OBJECT_TYPE',
357
+ objectUrl: 'BRICK_SCENE_3D_OBJECT_URL',
358
+ objectMd5: 'BRICK_SCENE_3D_OBJECT_MD5',
359
+ objectPosition: 'BRICK_SCENE_3D_OBJECT_POSITION',
360
+ objectRotation: 'BRICK_SCENE_3D_OBJECT_ROTATION',
361
+ objectScale: 'BRICK_SCENE_3D_OBJECT_SCALE',
362
+ objectColor: 'BRICK_SCENE_3D_OBJECT_COLOR',
363
+ },
364
+ BRICK_SCENE_3D_REMOVE_OBJECT: {
365
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
366
+ },
367
+ BRICK_SCENE_3D_UPDATE_OBJECT: {
368
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
369
+ objectPosition: 'BRICK_SCENE_3D_OBJECT_POSITION',
370
+ objectRotation: 'BRICK_SCENE_3D_OBJECT_ROTATION',
371
+ objectScale: 'BRICK_SCENE_3D_OBJECT_SCALE',
372
+ objectVisible: 'BRICK_SCENE_3D_OBJECT_VISIBLE',
373
+ objectColor: 'BRICK_SCENE_3D_OBJECT_COLOR',
374
+ objectNodes: 'BRICK_SCENE_3D_OBJECT_NODES',
375
+ },
376
+ BRICK_SCENE_3D_SET_CAMERA: {
377
+ cameraPosition: 'BRICK_SCENE_3D_CAMERA_POSITION',
378
+ cameraTarget: 'BRICK_SCENE_3D_CAMERA_TARGET',
379
+ cameraFov: 'BRICK_SCENE_3D_CAMERA_FOV',
380
+ cameraAnimateMs: 'BRICK_SCENE_3D_CAMERA_ANIMATE_MS',
381
+ },
382
+ BRICK_SCENE_3D_LOOK_AT: {
383
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
384
+ },
385
+ BRICK_SCENE_3D_PLAY_ANIMATION: {
386
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
387
+ animationName: 'BRICK_SCENE_3D_ANIMATION_NAME',
388
+ animationLoop: 'BRICK_SCENE_3D_ANIMATION_LOOP',
389
+ animationSpeed: 'BRICK_SCENE_3D_ANIMATION_SPEED',
390
+ },
391
+ BRICK_SCENE_3D_STOP_ANIMATION: {
392
+ objectId: 'BRICK_SCENE_3D_OBJECT_ID',
393
+ animationName: 'BRICK_SCENE_3D_ANIMATION_NAME',
394
+ },
395
+ BRICK_SCENE_3D_SET_BACKGROUND: {
396
+ backgroundColor: 'BRICK_SCENE_3D_BACKGROUND_COLOR',
397
+ backgroundHdrUrl: 'BRICK_SCENE_3D_BACKGROUND_HDR_URL',
398
+ backgroundMd5: 'BRICK_SCENE_3D_BACKGROUND_MD5',
399
+ },
400
+ BRICK_SCENE_3D_SET_CONTROLS: {
401
+ controlsEnabled: 'BRICK_SCENE_3D_CONTROLS_ENABLED',
402
+ controlsAutoRotate: 'BRICK_SCENE_3D_CONTROLS_AUTO_ROTATE',
403
+ controlsAutoRotateSpeed: 'BRICK_SCENE_3D_CONTROLS_AUTO_ROTATE_SPEED',
404
+ },
405
+ BRICK_SCENE_3D_SCREENSHOT: {
406
+ screenshotFormat: 'BRICK_SCENE_3D_SCREENSHOT_FORMAT',
407
+ screenshotQuality: 'BRICK_SCENE_3D_SCREENSHOT_QUALITY',
408
+ },
409
+ },
353
410
 
354
411
  GENERATOR_FILE: {
355
412
  GENERATOR_FILE_READ_CONTENT: {
@@ -782,6 +839,11 @@ export const templateActionNameMap = {
782
839
  seed: 'GENERATOR_LLM_SEED',
783
840
  typicalP: 'GENERATOR_LLM_TYPICAL_P',
784
841
  ignoreEos: 'GENERATOR_LLM_IGNORE_EOS',
842
+ mtpSpeculativeDecoding: 'GENERATOR_LLM_MTP_SPECULATIVE_DECODING',
843
+ mtpDraftTokens: 'GENERATOR_LLM_MTP_DRAFT_TOKENS',
844
+ mtpDraftMinTokens: 'GENERATOR_LLM_MTP_DRAFT_MIN_TOKENS',
845
+ mtpDraftMinProbability: 'GENERATOR_LLM_MTP_DRAFT_MIN_PROBABILITY',
846
+ mtpDraftSplitProbability: 'GENERATOR_LLM_MTP_DRAFT_SPLIT_PROBABILITY',
785
847
  functionCallEnabled: 'GENERATOR_LLM_FUNCTION_CALL_ENABLED',
786
848
  functionCallSchema: 'GENERATOR_LLM_FUNCTION_CALL_SCHEMA',
787
849
  },
@@ -894,10 +956,12 @@ export const templateActionNameMap = {
894
956
  GENERATOR_APPLE_STT_TRANSCRIBE_FILE: {
895
957
  fileUrl: 'GENERATOR_APPLE_STT_FILE_URL',
896
958
  language: 'GENERATOR_APPLE_STT_LANGUAGE',
959
+ contextualStrings: 'GENERATOR_APPLE_STT_CONTEXTUAL_STRINGS',
897
960
  },
898
961
  GENERATOR_APPLE_STT_TRANSCRIBE_DATA: {
899
962
  data: 'GENERATOR_APPLE_STT_DATA',
900
963
  language: 'GENERATOR_APPLE_STT_LANGUAGE',
964
+ contextualStrings: 'GENERATOR_APPLE_STT_CONTEXTUAL_STRINGS',
901
965
  },
902
966
  },
903
967
  GENERATOR_APPLE_TTS: {
@@ -0,0 +1,155 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ // The compiled config artifact written by `bun compile` (see the generated
5
+ // project's `compile.ts`; bricks-project-generator/index.js:762).
6
+ export const BUILD_CONFIG_RELATIVE = '.bricks/build/application-config.json'
7
+
8
+ // `compile()` derives these top-level fields from `Date.now()`
9
+ // (compile/index.ts `title: \`${app.name}(${timestamp})\`` and `update_timestamp`),
10
+ // so they differ on every run regardless of source. Excluded from the comparison —
11
+ // only the *top-level* keys are dropped, so nested subspace/brick `title`s still diff.
12
+ const VOLATILE_TOP_LEVEL_FIELDS = ['title', 'update_timestamp']
13
+
14
+ // A minimal, path-keyed config change (Option A): a generic patch, not coupled to
15
+ // bricks-config-editor's action vocabulary. `path` is an array of object keys /
16
+ // array indices, ready for the editor's `setYValueAtPath` (or a delete) so applying
17
+ // the patch is a single Yjs `'local'` transaction == one undo/redo entry.
18
+ export type ConfigPatchOp =
19
+ | { op: 'set'; path: Array<string | number>; value: unknown }
20
+ | { op: 'unset'; path: Array<string | number> }
21
+
22
+ export type ConfigChange =
23
+ | { status: 'ok'; ops: ConfigPatchOp[]; opCount: number }
24
+ | { status: 'no_baseline' }
25
+ | { status: 'unavailable' }
26
+
27
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
28
+ typeof value === 'object' && value !== null && !Array.isArray(value)
29
+
30
+ const isJsonDroppedValue = (value: unknown) =>
31
+ value === undefined || typeof value === 'function' || typeof value === 'symbol'
32
+
33
+ const toJsonComparableScalar = (value: unknown) => {
34
+ if (typeof value === 'number' && !Number.isFinite(value)) return null
35
+ return value
36
+ }
37
+
38
+ const toJsonCompatibleValue = (value: unknown): unknown => {
39
+ if (isJsonDroppedValue(value)) return undefined
40
+ if (Array.isArray(value)) {
41
+ return value.map((item) => (isJsonDroppedValue(item) ? null : toJsonCompatibleValue(item)))
42
+ }
43
+ if (isRecord(value)) {
44
+ return Object.entries(value).reduce((acc, [key, item]) => {
45
+ if (!isJsonDroppedValue(item)) acc[key] = toJsonCompatibleValue(item)
46
+ return acc
47
+ }, {})
48
+ }
49
+ return toJsonComparableScalar(value)
50
+ }
51
+
52
+ const hasJsonObjectKey = (value: Record<string, unknown>, key: string) =>
53
+ Object.prototype.hasOwnProperty.call(value, key) && !isJsonDroppedValue(value[key])
54
+
55
+ const getJsonArrayItem = (value: unknown[], index: number) => {
56
+ const item = value[index]
57
+ return isJsonDroppedValue(item) ? null : item
58
+ }
59
+
60
+ const deepEqual = (a: unknown, b: unknown): boolean => {
61
+ a = toJsonComparableScalar(a)
62
+ b = toJsonComparableScalar(b)
63
+ if (a === b) return true
64
+ if (Array.isArray(a) && Array.isArray(b)) {
65
+ if (a.length !== b.length) return false
66
+ for (let index = 0; index < a.length; index += 1) {
67
+ if (!deepEqual(getJsonArrayItem(a, index), getJsonArrayItem(b, index))) return false
68
+ }
69
+ return true
70
+ }
71
+ if (isRecord(a) && isRecord(b)) {
72
+ let comparableAKeys = 0
73
+ for (const key of Object.keys(a)) {
74
+ if (isJsonDroppedValue(a[key])) continue
75
+ comparableAKeys += 1
76
+ if (!hasJsonObjectKey(b, key) || !deepEqual(a[key], b[key])) return false
77
+ }
78
+
79
+ let comparableBKeys = 0
80
+ for (const key of Object.keys(b)) {
81
+ if (!isJsonDroppedValue(b[key])) comparableBKeys += 1
82
+ }
83
+ return comparableAKeys === comparableBKeys
84
+ }
85
+ return false
86
+ }
87
+
88
+ const normalizeConfig = (config: unknown) => {
89
+ if (!isRecord(config)) return config
90
+ const normalized = { ...config }
91
+ for (const field of VOLATILE_TOP_LEVEL_FIELDS) delete normalized[field]
92
+ return normalized
93
+ }
94
+
95
+ // Objects recurse key-wise; equal-length arrays recurse element-wise; everything else
96
+ // (scalars, type changes, length-changed arrays) emits one whole-value `set` at that
97
+ // path. The editor's `applyJsonDiffToYType` minimizes the actual Yjs ops downstream,
98
+ // so a whole-array `set` on insert/remove still yields a minimal CRDT mutation.
99
+ const diffInto = (
100
+ before: unknown,
101
+ after: unknown,
102
+ currentPath: Array<string | number>,
103
+ ops: ConfigPatchOp[],
104
+ ) => {
105
+ if (deepEqual(before, after)) return
106
+
107
+ if (isRecord(before) && isRecord(after)) {
108
+ const keys = new Set([...Object.keys(before), ...Object.keys(after)])
109
+ for (const key of keys) {
110
+ const beforeHasKey = hasJsonObjectKey(before, key)
111
+ const afterHasKey = hasJsonObjectKey(after, key)
112
+ if (!beforeHasKey && !afterHasKey) continue
113
+
114
+ const nextPath = [...currentPath, key]
115
+ if (!afterHasKey) ops.push({ op: 'unset', path: nextPath })
116
+ else if (!beforeHasKey) {
117
+ ops.push({ op: 'set', path: nextPath, value: toJsonCompatibleValue(after[key]) })
118
+ } else diffInto(before[key], after[key], nextPath, ops)
119
+ }
120
+ return
121
+ }
122
+
123
+ if (Array.isArray(before) && Array.isArray(after) && before.length === after.length) {
124
+ for (let index = 0; index < after.length; index += 1) {
125
+ diffInto(
126
+ getJsonArrayItem(before, index),
127
+ getJsonArrayItem(after, index),
128
+ [...currentPath, index],
129
+ ops,
130
+ )
131
+ }
132
+ return
133
+ }
134
+
135
+ ops.push({ op: 'set', path: currentPath, value: toJsonCompatibleValue(after) })
136
+ }
137
+
138
+ // Diff two compiled configs. `before == null` means there was no prior build to compare
139
+ // (first compile); `after == null` means the fresh artifact could not be read.
140
+ export const computeConfigChange = (before: unknown, after: unknown): ConfigChange => {
141
+ if (before == null) return { status: 'no_baseline' }
142
+ if (after == null) return { status: 'unavailable' }
143
+ const ops: ConfigPatchOp[] = []
144
+ diffInto(normalizeConfig(before), normalizeConfig(after), [], ops)
145
+ return { status: 'ok', ops, opCount: ops.length }
146
+ }
147
+
148
+ // Read the last-compiled config artifact. Returns null when it is absent or unreadable.
149
+ export const readBuildConfig = async (projectDir: string): Promise<unknown> => {
150
+ try {
151
+ return JSON.parse(await readFile(path.join(projectDir, BUILD_CONFIG_RELATIVE), 'utf8'))
152
+ } catch {
153
+ return null
154
+ }
155
+ }