@fugood/bricks-ctor 2.24.1 → 2.24.3

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.
@@ -327,6 +327,29 @@ export const templateActionNameMap = {
327
327
  animated: 'BRICK_MAPS_ANIMATED',
328
328
  },
329
329
  },
330
+ BRICK_SKETCH: {
331
+ BRICK_SKETCH_SET_TOOL: {
332
+ tool: 'BRICK_SKETCH_TOOL',
333
+ },
334
+ BRICK_SKETCH_SET_COLOR: {
335
+ color: 'BRICK_SKETCH_COLOR',
336
+ },
337
+ BRICK_SKETCH_SET_STROKE_WIDTH: {
338
+ strokeWidth: 'BRICK_SKETCH_STROKE_WIDTH',
339
+ },
340
+ BRICK_SKETCH_IMPORT_STATE: {
341
+ stateJson: 'BRICK_SKETCH_STATE_JSON',
342
+ },
343
+ BRICK_SKETCH_EXPORT_IMAGE: {
344
+ imageFormat: 'BRICK_SKETCH_IMAGE_FORMAT',
345
+ imageQuality: 'BRICK_SKETCH_IMAGE_QUALITY',
346
+ },
347
+ BRICK_SKETCH_ADD_STROKE: {
348
+ strokePoints: 'BRICK_SKETCH_STROKE_POINTS',
349
+ strokeColor: 'BRICK_SKETCH_STROKE_COLOR',
350
+ strokeWidth: 'BRICK_SKETCH_STROKE_WIDTH',
351
+ },
352
+ },
330
353
 
331
354
  GENERATOR_FILE: {
332
355
  GENERATOR_FILE_READ_CONTENT: {
package/compile/index.ts CHANGED
@@ -301,6 +301,162 @@ const animationTypeMap = {
301
301
  AnimationTimingConfig: 'timing',
302
302
  AnimationSpringConfig: 'spring',
303
303
  AnimationDecayConfig: 'decay',
304
+ } as const
305
+
306
+ type CompiledAnimationType = (typeof animationTypeMap)[keyof typeof animationTypeMap]
307
+ type WarningMetadata = Record<string, unknown>
308
+
309
+ const animationProperties = new Set([
310
+ 'transform.translateX',
311
+ 'transform.translateY',
312
+ 'transform.scale',
313
+ 'transform.scaleX',
314
+ 'transform.scaleY',
315
+ 'transform.rotate',
316
+ 'transform.rotateX',
317
+ 'transform.rotateY',
318
+ 'opacity',
319
+ ])
320
+
321
+ const animationComposeTypes = new Set(['parallel', 'sequence'])
322
+ const springConfigFamilies = [
323
+ ['stiffness', 'damping', 'mass'],
324
+ ['tension', 'friction'],
325
+ ['bounciness', 'speed'],
326
+ ]
327
+ const springConfigFamilyKeys = new Set(springConfigFamilies.flat())
328
+
329
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
330
+ Boolean(value) && typeof value === 'object' && !Array.isArray(value)
331
+
332
+ const hasDefinedConfigValue = (config: Record<string, unknown>, key: string) =>
333
+ config[key] !== undefined
334
+
335
+ const assertConfigValue = (
336
+ config: Record<string, unknown>,
337
+ key: string,
338
+ errorReference: string,
339
+ ) => {
340
+ if (!hasDefinedConfigValue(config, key)) {
341
+ throw new Error(`Invalid animation config ${errorReference}: missing "${key}"`)
342
+ }
343
+ }
344
+
345
+ const assertAnimationProperty = (property: unknown, errorReference: string) => {
346
+ if (typeof property !== 'string' || !animationProperties.has(property)) {
347
+ throw new Error(
348
+ `Invalid animation property${errorReference ? ` ${errorReference}` : ''}: ${String(
349
+ property,
350
+ )}`,
351
+ )
352
+ }
353
+ return property
354
+ }
355
+
356
+ const getAnimationType = (config: unknown, errorReference: string): CompiledAnimationType => {
357
+ if (!isRecord(config)) {
358
+ throw new Error(`Invalid animation config ${errorReference}: config must be an object`)
359
+ }
360
+
361
+ const animationType = animationTypeMap[config.__type as keyof typeof animationTypeMap]
362
+ if (!animationType) {
363
+ throw new Error(`Invalid animation config type ${errorReference}: ${String(config.__type)}`)
364
+ }
365
+ return animationType
366
+ }
367
+
368
+ const assertAnimationComposeType = (composeType: unknown, errorReference: string) => {
369
+ if (typeof composeType !== 'string' || !animationComposeTypes.has(composeType)) {
370
+ throw new Error(`Invalid animation compose type ${errorReference}: ${String(composeType)}`)
371
+ }
372
+ return composeType
373
+ }
374
+
375
+ const pickDefinedConfigValues = (config: Record<string, unknown>, keys: string[]) =>
376
+ keys.reduce((acc, key) => {
377
+ if (hasDefinedConfigValue(config, key)) acc[key] = config[key]
378
+ return acc
379
+ }, {})
380
+
381
+ const getDefinedConfigKeys = (config: Record<string, unknown>, keys: string[]) =>
382
+ keys.filter((key) => hasDefinedConfigValue(config, key))
383
+
384
+ const formatWarningMetadata = (metadata: WarningMetadata = {}) =>
385
+ Object.entries(metadata)
386
+ .filter(([, value]) => value !== undefined && value !== null && value !== '')
387
+ .map(([key, value]) => `${key}: ${String(value)}`)
388
+ .join(', ')
389
+
390
+ const formatWarningReference = (metadata?: WarningMetadata) => {
391
+ const metadataText = formatWarningMetadata(metadata)
392
+ return metadataText ? ` [${metadataText}]` : ''
393
+ }
394
+
395
+ const normalizeSpringConfig = (
396
+ config: Record<string, unknown>,
397
+ errorReference: string,
398
+ warningMetadata?: WarningMetadata,
399
+ ): Record<string, unknown> => {
400
+ assertConfigValue(config, 'toValue', errorReference)
401
+
402
+ const usedFamilies = springConfigFamilies.filter((keys) =>
403
+ keys.some((key) => hasDefinedConfigValue(config, key)),
404
+ )
405
+ if (usedFamilies.length <= 1) return config
406
+
407
+ const configWithoutSpringFamily = Object.entries(config).reduce((acc, [key, value]) => {
408
+ if (!springConfigFamilyKeys.has(key)) acc[key] = value
409
+ return acc
410
+ }, {})
411
+
412
+ // Match runtime normalization: physical spring values are most explicit,
413
+ // otherwise preserve BRICKS' historical tension/friction controls.
414
+ const resolvedFamily =
415
+ usedFamilies.find((keys) => keys.includes('stiffness')) ||
416
+ usedFamilies.find((keys) => keys.includes('tension')) ||
417
+ usedFamilies[0]
418
+ const resolvedFamilyKeys = getDefinedConfigKeys(config, resolvedFamily)
419
+ const droppedFamilyKeys = usedFamilies
420
+ .filter((keys) => keys !== resolvedFamily)
421
+ .flatMap((keys) => getDefinedConfigKeys(config, keys))
422
+
423
+ console.warn(
424
+ `[Warning] Resolved animation spring config${formatWarningReference(
425
+ warningMetadata,
426
+ )}: using ${resolvedFamilyKeys.join('/')}, dropping ${droppedFamilyKeys.join('/')}`,
427
+ )
428
+
429
+ return {
430
+ ...configWithoutSpringFamily,
431
+ ...pickDefinedConfigValues(config, resolvedFamily),
432
+ }
433
+ }
434
+
435
+ const compileAnimationConfig = (
436
+ animationType: CompiledAnimationType,
437
+ config: unknown,
438
+ errorReference: string,
439
+ warningMetadata?: WarningMetadata,
440
+ ) => {
441
+ if (!isRecord(config)) {
442
+ throw new Error(`Invalid animation config ${errorReference}: config must be an object`)
443
+ }
444
+
445
+ const compiledConfig = compileProperty(omit(config, '__type'), errorReference)
446
+
447
+ if (!isRecord(compiledConfig)) {
448
+ throw new Error(`Invalid animation config ${errorReference}: config must compile to an object`)
449
+ }
450
+
451
+ if (animationType === 'timing') {
452
+ assertConfigValue(compiledConfig, 'toValue', errorReference)
453
+ } else if (animationType === 'spring') {
454
+ return normalizeSpringConfig(compiledConfig, errorReference, warningMetadata)
455
+ } else if (animationType === 'decay') {
456
+ assertConfigValue(compiledConfig, 'velocity', errorReference)
457
+ }
458
+
459
+ return compiledConfig
304
460
  }
305
461
 
306
462
  const compileFrame = (frame: Canvas['items'][number]['frame']) => ({
@@ -629,39 +785,63 @@ export const compile = async (app: Application) => {
629
785
  `(animation index: ${animationIndex}, subspace: ${subspaceId})`,
630
786
  )
631
787
 
632
- if (animation.__typename === 'Animation') {
788
+ const animationTypename = animation.__typename
789
+ if (animationTypename === 'Animation') {
633
790
  const animationDef = animation as AnimationDef
791
+ const animationErrorReference = `(animation: ${animationId}, subspace ${subspaceId})`
792
+ const animationWarningMetadata = {
793
+ animationIndex,
794
+ animationTitle: animationDef.title,
795
+ animationAlias: animationDef.alias,
796
+ animationProperty: animationDef.property,
797
+ subspaceIndex,
798
+ subspaceTitle: subspace.title,
799
+ }
800
+ const animationType = getAnimationType(animationDef.config, animationErrorReference)
634
801
  map[animationId] = {
635
802
  alias: animationDef.alias,
636
803
  title: animationDef.title,
637
804
  description: animationDef.description,
638
805
  hide_short_ref: animationDef.hideShortRef,
639
806
  animationRunType: animationDef.runType,
640
- property: animationDef.property,
641
- type: animationTypeMap[animationDef.config.__type],
642
- config: compileProperty(
643
- omit(animationDef.config, '__type'),
644
- `(animation: ${animationId}, subspace ${subspaceId})`,
807
+ property: assertAnimationProperty(animationDef.property, animationErrorReference),
808
+ type: animationType,
809
+ config: compileAnimationConfig(
810
+ animationType,
811
+ animationDef.config,
812
+ animationErrorReference,
813
+ animationWarningMetadata,
645
814
  ),
646
815
  }
647
- } else if (animation.__typename === 'AnimationCompose') {
816
+ } else if (animationTypename === 'AnimationCompose') {
648
817
  const animationDef = animation as AnimationComposeDef
818
+ const animationErrorReference = `(animation: ${animationId}, subspace ${subspaceId})`
649
819
  map[animationId] = {
650
820
  alias: animationDef.alias,
651
821
  title: animationDef.title,
652
822
  description: animationDef.description,
653
823
  hide_short_ref: animationDef.hideShortRef,
654
824
  animationRunType: animationDef.runType,
655
- compose_type: animationDef.composeType,
825
+ compose_type: assertAnimationComposeType(
826
+ animationDef.composeType,
827
+ animationErrorReference,
828
+ ),
656
829
  item_list: animationDef.items.map((item, index) => {
657
830
  const innerAnimation = item()
658
- if (!innerAnimation?.id)
659
- throw new Error(
660
- `Invalid animation index: ${index} (animation: ${innerAnimation.id}, subspace ${subspaceId})`,
661
- )
662
- return { animation_id: innerAnimation.id }
831
+ const innerAnimationId = assertEntryId(
832
+ innerAnimation?.id,
833
+ 'ANIMATION',
834
+ `(animation item index: ${index}, animation: ${animationId}, subspace ${subspaceId})`,
835
+ )
836
+ return { animation_id: innerAnimationId }
663
837
  }),
664
838
  }
839
+ } else {
840
+ throw new Error(
841
+ `Invalid animation typename (animation: ${animationId}, subspace ${subspaceId}): ${String(
842
+ animationTypename,
843
+ )}`,
844
+ )
665
845
  }
666
846
  return map
667
847
  }, {}),
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@fugood/bricks-ctor",
3
- "version": "2.24.1",
3
+ "version": "2.24.3",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "typecheck": "tsc --noEmit",
7
7
  "build": "bun scripts/build.js"
8
8
  },
9
9
  "dependencies": {
10
- "@fugood/bricks-cli": "^2.24.1",
10
+ "@fugood/bricks-cli": "^2.24.3",
11
11
  "@huggingface/gguf": "^0.3.2",
12
12
  "@iarna/toml": "^3.0.0",
13
13
  "@modelcontextprotocol/sdk": "^1.15.0",
@@ -24,6 +24,5 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "oxfmt": "^0.36.0"
27
- },
28
- "gitHead": "b424a8d24a5dc09ad69bf2242e021e6315379bf2"
27
+ }
29
28
  }
@@ -41,12 +41,13 @@ const bounce: AnimationDef = {
41
41
  toValue: 1,
42
42
  friction: 7,
43
43
  tension: 40,
44
- speed: 12,
45
- bounciness: 8,
46
44
  },
47
45
  }
48
46
  ```
49
47
 
48
+ Use one spring parameter family per config: `tension/friction`, `speed/bounciness`, or
49
+ `stiffness/damping/mass`.
50
+
50
51
  ### Decay Animation
51
52
  Velocity-based deceleration animation.
52
53
 
@@ -20,16 +20,26 @@ When mobile devices or embedded systems lack hardware for local AI inference (LL
20
20
 
21
21
  ## Client Configuration
22
22
 
23
- In generator properties, configure Buttress settings:
23
+ In generator properties, configure `buttressConnectionSettings`:
24
24
 
25
25
  | Setting | Description |
26
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 |
27
+ | `enabled` | Toggle Buttress offloading |
28
+ | `autoDiscoverType` | `auto` (LAN auto-discovery, recommended) or `manual` (typed URL) |
29
+ | `url` | Server URL (`manual` mode only — leave empty for `auto`) |
30
+ | `fallbackType` | If Buttress is unreachable: `use-local` runs locally, `no-op` blocks the load |
31
+ | `strategy` | Execution preference (see below) |
31
32
 
32
- ### Strategy Options
33
+ The launcher provides the access token automatically — there is **no user-facing access-token setting**. In `auto` mode the launcher discovers servers bound to the device's workspace and uses its workspace-scoped JWT; in `manual` mode it sends the same JWT only when the typed URL belongs to a server bound to the same workspace (verified against the server's `/buttress/info`).
34
+
35
+ ### `autoDiscoverType` options
36
+
37
+ | Mode | When to use | What the device does |
38
+ |------|-------------|----------------------|
39
+ | `auto` | LAN deployment with a workspace-bound buttress-server | Listens for UDP announcements and picks the strongest server bound to its workspace; reconnects automatically when the workspace flips |
40
+ | `manual` | Internet-reachable server, mixed networks, or a public/unbound server | Connects to the typed `url` directly; sends a token only when the server is bound to the same workspace |
41
+
42
+ ### Strategy options
33
43
 
34
44
  | Strategy | Description |
35
45
  |----------|-------------|
@@ -37,7 +47,11 @@ In generator properties, configure Buttress settings:
37
47
  | `prefer-buttress` | Use Buttress if available, fallback to local |
38
48
  | `prefer-best` | Auto-select based on capability comparison |
39
49
 
40
- ## Generator Configuration Example
50
+ ## Generator Configuration Examples
51
+
52
+ ### Auto-discovery (recommended)
53
+
54
+ Workspace-bound launcher + workspace-bound buttress-server on the same LAN. No URL needed — discovery picks the highest-scoring server that runs the requested backend.
41
55
 
42
56
  ```typescript
43
57
  import { makeId } from 'bricks-ctor'
@@ -53,7 +67,7 @@ const llmGenerator: GeneratorLLM = {
53
67
  contextSize: 8192,
54
68
  buttressConnectionSettings: {
55
69
  enabled: true,
56
- url: 'http://192.168.1.100:2080',
70
+ autoDiscoverType: 'auto',
57
71
  fallbackType: 'use-local',
58
72
  strategy: 'prefer-best',
59
73
  },
@@ -63,6 +77,44 @@ const llmGenerator: GeneratorLLM = {
63
77
  }
64
78
  ```
65
79
 
80
+ ### Manual URL
81
+
82
+ Use when the server isn't on the launcher's broadcast domain (cross-subnet, internet, behind a reverse proxy) or you want to point at a specific public/unbound server.
83
+
84
+ ```typescript
85
+ buttressConnectionSettings: {
86
+ enabled: true,
87
+ autoDiscoverType: 'manual',
88
+ url: 'http://192.168.1.100:2080',
89
+ fallbackType: 'use-local',
90
+ strategy: 'prefer-best',
91
+ }
92
+ ```
93
+
94
+ > ⚠️ With `fallbackType: 'no-op'` the generator refuses to load locally if Buttress is unreachable. Use `'use-local'` whenever the device can also run the model standalone.
95
+
96
+ ## Integrating a discovered buttress-server
97
+
98
+ The ctor-desktop "Local Devices" panel (and the `bricks buttress scan` CLI) can hand you a server's identity, workspace, and announced generator caps. When the user asks to integrate one:
99
+
100
+ 1. **Confirm workspace match.** The discovery message says whether the server's workspace matches this project's. If it doesn't, do NOT add the integration — instruct the user to run `bricks buttress unbind && bricks buttress bind` from this workspace's owner CLI on the server host. The launcher won't trust a cross-workspace server.
101
+
102
+ 2. **Map announced types to generator templates.** For each `generators[].type` in the announce, target the matching templateKey (create the generator if absent):
103
+
104
+ | Announced type | templateKey | Default model |
105
+ |----------------|------------------------------|---------------|
106
+ | `ggml-llm` | `GENERATOR_LLM` | `ggml-org/gemma-3-12b-it-qat-GGUF` (≥20 GB usable) or `ggml-org/gpt-oss-20b-GGUF` (~12 GB usable) |
107
+ | `mlx-llm` | `GENERATOR_MLX_LLM` | `mlx-community/Qwen3-4B-4bit` (or a larger 4-bit quant if `usableBytes` allows) |
108
+ | `ggml-stt` | `GENERATOR_SPEECH_INFERENCE` | `BricksDisplay/whisper-ggml` (filename `ggml-small-q8_0.bin`) |
109
+
110
+ Pick a model that fits the announced `usableBytes`. Set `contextSize` to match.
111
+
112
+ 3. **Use the canonical auto-discovery config** from "Auto-discovery (recommended)" above. Don't switch to manual mode just because the server is on the LAN — auto mode picks the workspace-bound server automatically and rebinds when the device's workspace flips.
113
+
114
+ ### Real-device caveat
115
+
116
+ Buttress LAN auto-discovery uses native UDP via `react-native-jsi-udp`. The iOS Simulator silently fails to bind UDP, so auto mode is a no-op there. With `fallbackType: 'use-local'` the generator falls back to local inference in the simulator — dev/test stays functional. **Validate the buttress path itself only when deploying to a real Foundation device; don't gate the build on simulator validation.**
117
+
66
118
  ## Server Setup
67
119
 
68
120
  ### Requirements
@@ -98,6 +150,43 @@ bricks-buttress --config ./config.toml
98
150
  |----------|-------------|
99
151
  | `HF_TOKEN` | Hugging Face token for model downloads |
100
152
  | `ENABLE_OPENAI_COMPAT_ENDPOINT` | Set to `1` for OpenAI-compatible API |
153
+ | `BRICKS_BUTTRESS_STATE_DIR` | Override the workspace state directory (default `~/.bricks-cli/buttress`) |
154
+
155
+ ## Bind the Server to a Workspace
156
+
157
+ To use `autoDiscoverType: 'auto'` — and to require workspace-scoped JWT auth — pair the buttress-server with a BRICKS workspace using the `bricks buttress` CLI commands. An unbound server stays in legacy public mode and accepts any LAN client.
158
+
159
+ ### One-time bind
160
+
161
+ ```bash
162
+ # Log into the cloud bricks-server with the workspace owner's account
163
+ bricks auth login
164
+
165
+ # Pair the buttress-server running on this machine with the active workspace
166
+ bricks buttress bind
167
+
168
+ # Restart bricks-buttress so it picks up the new state.json
169
+ ```
170
+
171
+ `bricks buttress bind` writes `~/.bricks-cli/buttress/state.json` containing the workspace id, the issuer's Ed25519 public key, and a stable `serverId` (defaults to `buttress-<machineId>`). Override location with `--state-dir` or `$BRICKS_BUTTRESS_STATE_DIR`. For headless setups, use `bricks buttress bind --print` to emit state.json to stdout.
172
+
173
+ ### Verify and manage
174
+
175
+ ```bash
176
+ # Show local binding + workspace-side bound list
177
+ bricks buttress status
178
+
179
+ # Discover buttress-servers on the LAN (with version, auth state, generator caps)
180
+ bricks buttress scan
181
+
182
+ # Issue a long-lived workspace access token (CI / ctor agents that already hold a workspace token)
183
+ bricks buttress issue-token --ttl 86400
184
+
185
+ # Detach this server from the workspace
186
+ bricks buttress unbind
187
+ ```
188
+
189
+ After binding, launchers in the same workspace will auto-discover this server; manual-mode generators will only send their access token if the server's reported workspace matches their own.
101
190
 
102
191
  ## Server Configuration (TOML)
103
192