bleam 0.0.8 → 0.0.10

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 (96) hide show
  1. package/dist/cli.cjs +269 -22
  2. package/dist/cli.d.cts +32 -2
  3. package/dist/cli.d.ts +32 -2
  4. package/dist/cli.js +270 -23
  5. package/dist/platform.d.cts +2 -0
  6. package/dist/platform.d.ts +2 -0
  7. package/dist/{ui-1WepaMS4.d.cts → ui-Bg11tvlc.d.ts} +1 -1
  8. package/dist/{ui-Ce-pnUUA.d.ts → ui-Dd7SXdbg.d.cts} +7 -7
  9. package/dist/ui.d.cts +1 -1
  10. package/dist/ui.d.ts +1 -1
  11. package/dist/window.d.cts +1 -1
  12. package/dist/window.d.ts +1 -1
  13. package/package.json +5 -1
  14. package/templates/image-generation/app/index.tsx +1 -1
  15. package/templates/native/.gitattributes +1 -0
  16. package/templates/native/App.tsx +26 -0
  17. package/templates/native/app.json +12 -0
  18. package/templates/native/index.ts +8 -0
  19. package/templates/native/ios/.xcode.env +11 -0
  20. package/templates/native/ios/Bleam/AI/Flux2/Configuration/Flux2Config.swift +288 -0
  21. package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryConfig.swift +233 -0
  22. package/templates/native/ios/Bleam/AI/Flux2/Configuration/MemoryOptimizationConfig.swift +157 -0
  23. package/templates/native/ios/Bleam/AI/Flux2/Configuration/ModelRegistry.swift +425 -0
  24. package/templates/native/ios/Bleam/AI/Flux2/Configuration/QuantizationConfig.swift +138 -0
  25. package/templates/native/ios/Bleam/AI/Flux2/Configuration/TransformerRepoProfile.swift +59 -0
  26. package/templates/native/ios/Bleam/AI/Flux2/Configuration/VAEConfig.swift +134 -0
  27. package/templates/native/ios/Bleam/AI/Flux2/Flux2Core.swift +55 -0
  28. package/templates/native/ios/Bleam/AI/Flux2/Loading/WeightLoader.swift +1192 -0
  29. package/templates/native/ios/Bleam/AI/Flux2/Pipeline/FluxImageRunner.swift +1282 -0
  30. package/templates/native/ios/Bleam/AI/Flux2/Pipeline/LatentUtils.swift +191 -0
  31. package/templates/native/ios/Bleam/AI/Flux2/Scheduler/FlowMatchEulerScheduler.swift +279 -0
  32. package/templates/native/ios/Bleam/AI/Flux2/Text/KleinTextEncoder.swift +380 -0
  33. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Attention.swift +379 -0
  34. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Embeddings.swift +159 -0
  35. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FeedForward.swift +154 -0
  36. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2FusedKernels.swift +198 -0
  37. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2KVCache.swift +36 -0
  38. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Modulation.swift +193 -0
  39. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2ParallelAttention.swift +389 -0
  40. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2RoPE.swift +304 -0
  41. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2SingleBlock.swift +290 -0
  42. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2Transformer.swift +530 -0
  43. package/templates/native/ios/Bleam/AI/Flux2/Transformer/Flux2TransformerBlock.swift +362 -0
  44. package/templates/native/ios/Bleam/AI/Flux2/Utils/Flux2Debug.swift +101 -0
  45. package/templates/native/ios/Bleam/AI/Flux2/Utils/MLXCheckpoint.swift +118 -0
  46. package/templates/native/ios/Bleam/AI/Flux2/Utils/MemoryManager.swift +201 -0
  47. package/templates/native/ios/Bleam/AI/Flux2/VAE/AutoencoderKL.swift +476 -0
  48. package/templates/native/ios/Bleam/AI/Flux2/VAE/ResnetBlock.swift +316 -0
  49. package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEDecoder.swift +120 -0
  50. package/templates/native/ios/Bleam/AI/Flux2/VAE/VAEEncoder.swift +136 -0
  51. package/templates/native/ios/Bleam/AppDelegate.swift +482 -0
  52. package/templates/native/ios/Bleam/Appearance.swift +62 -0
  53. package/templates/native/ios/Bleam/Bridging-Header.h +3 -0
  54. package/templates/native/ios/Bleam/Images.xcassets/AppIcon.appiconset/Contents.json +13 -0
  55. package/templates/native/ios/Bleam/Images.xcassets/Contents.json +6 -0
  56. package/templates/native/ios/Bleam/Info.plist +76 -0
  57. package/templates/native/ios/Bleam/PrivacyInfo.xcprivacy +48 -0
  58. package/templates/native/ios/Bleam/SceneDelegate.swift +58 -0
  59. package/templates/native/ios/Bleam/SplashScreen.storyboard +47 -0
  60. package/templates/native/ios/Bleam/Supporting/Expo.plist +6 -0
  61. package/templates/native/ios/Bleam/bleam.entitlements +10 -0
  62. package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +1147 -0
  63. package/templates/native/ios/Bleam.xcodeproj/xcshareddata/xcschemes/Bleam.xcscheme +88 -0
  64. package/templates/native/ios/GenerationService/GenerationService.entitlements +10 -0
  65. package/templates/native/ios/GenerationService/ImageGenerationRunner.swift +591 -0
  66. package/templates/native/ios/GenerationService/Info.plist +31 -0
  67. package/templates/native/ios/GenerationService/main.swift +165 -0
  68. package/templates/native/ios/PlatformHelper/main.swift +726 -0
  69. package/templates/native/ios/Podfile +198 -0
  70. package/templates/native/ios/Podfile.lock +2284 -0
  71. package/templates/native/ios/Podfile.properties.json +5 -0
  72. package/templates/native/ios/Shared/Generation/GenerationServiceProtocol.swift +12 -0
  73. package/templates/native/ios/Shared/Generation/GenerationWorkerProtocol.swift +124 -0
  74. package/templates/native/metro.config.js +6 -0
  75. package/templates/native/modules/bleam-runtime/BleamRuntime.podspec +14 -0
  76. package/templates/native/modules/bleam-runtime/expo-module.config.json +8 -0
  77. package/templates/native/modules/bleam-runtime/ios/AIModule.swift +1258 -0
  78. package/templates/native/modules/bleam-runtime/ios/GenerationContracts.swift +135 -0
  79. package/templates/native/modules/bleam-runtime/ios/PlatformModule.swift +329 -0
  80. package/templates/native/modules/bleam-runtime/package.json +5 -0
  81. package/templates/native/package.json +39 -0
  82. package/templates/native/scripts/build/mlx-frameworks.ts +421 -0
  83. package/templates/native/scripts/start/index.ts +474 -0
  84. package/templates/native/scripts/start/known-failures.ts +20 -0
  85. package/templates/native/scripts/start/loader.ts +76 -0
  86. package/templates/native/scripts/start/native-state.ts +242 -0
  87. package/templates/native/scripts/start/package.json +4 -0
  88. package/templates/native/scripts/start/swift-packages.ts +414 -0
  89. package/templates/native/scripts/start/xcode-formatter.ts +106 -0
  90. package/templates/native/tsconfig.json +14 -0
  91. package/templates/native/yarn.lock +3749 -0
  92. package/templates/updates/README.md +272 -0
  93. package/templates/updates/src/index.ts +385 -0
  94. package/templates/updates/src/schema.ts +385 -0
  95. package/templates/updates/tsconfig.json +12 -0
  96. package/templates/updates/wrangler.jsonc +19 -0
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>XPC!</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>$(MARKETING_VERSION)</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>AppGroupIdentifier</key>
22
+ <string>group.dev.bleam.app</string>
23
+ <key>RCTNewArchEnabled</key>
24
+ <true/>
25
+ <key>XPCService</key>
26
+ <dict>
27
+ <key>ServiceType</key>
28
+ <string>Application</string>
29
+ </dict>
30
+ </dict>
31
+ </plist>
@@ -0,0 +1,165 @@
1
+ import Foundation
2
+ import MLX
3
+
4
+ private final class GenerationRuntime: @unchecked Sendable {
5
+ private let modelWarmTimeout: Duration = .seconds(60)
6
+ private var activeTask: Task<Void, Never>?
7
+ private var activeRunner: ImageGenerationRunner?
8
+ private var trimTask: Task<Void, Never>?
9
+ private var isCancelled = false
10
+
11
+ var isRunning: Bool {
12
+ activeTask != nil
13
+ }
14
+
15
+ func start(
16
+ request: GenerationWorkerRequest,
17
+ emit: @escaping @Sendable (GenerationWorkerEvent) -> Void
18
+ ) -> Bool {
19
+ guard activeTask == nil else { return false }
20
+
21
+ trimTask?.cancel()
22
+ trimTask = nil
23
+ isCancelled = false
24
+ activeTask = Task { [weak self] in
25
+ await self?.run(request, emit: emit)
26
+ }
27
+ return true
28
+ }
29
+
30
+ func cancel() {
31
+ isCancelled = true
32
+ trimTask?.cancel()
33
+ trimTask = nil
34
+ activeTask?.cancel()
35
+ activeRunner?.cancel()
36
+ }
37
+
38
+ func trimModelsNow() async {
39
+ trimTask?.cancel()
40
+ trimTask = nil
41
+ // We currently reload every stage per generation, but keep the explicit
42
+ // trim hook from ImageStudio's service architecture. Warm model caching
43
+ // should be added here later, never back in the app process.
44
+ MLX.Memory.clearCache()
45
+ await Task.yield()
46
+ MLX.Memory.clearCache()
47
+ print("[GenerationService] trim active=\(MLX.Memory.activeMemory / 1_048_576)MB cache=\(MLX.Memory.cacheMemory / 1_048_576)MB")
48
+ }
49
+
50
+ private func run(
51
+ _ request: GenerationWorkerRequest,
52
+ emit: @escaping @Sendable (GenerationWorkerEvent) -> Void
53
+ ) async {
54
+ let runner = ImageGenerationRunner(request: request, emit: emit)
55
+ activeRunner = runner
56
+ defer {
57
+ if activeRunner === runner {
58
+ activeRunner = nil
59
+ }
60
+ activeTask = nil
61
+ scheduleTrimAfterIdle()
62
+ }
63
+
64
+ do {
65
+ try await runner.run(isCancelled: { [weak self] in
66
+ Task.isCancelled || (self?.isCancelled ?? false)
67
+ })
68
+ } catch is CancellationError {
69
+ emit(.init(type: .canceled))
70
+ } catch let failure as GenerationWorkerFailure {
71
+ print("[GenerationService] failed - \(failure.localizedDescription)")
72
+ emit(.init(type: .failed, message: failure.localizedDescription, stage: failure.stage))
73
+ } catch {
74
+ print("[GenerationService] failed - \(error.localizedDescription)")
75
+ emit(.init(type: .failed, message: error.localizedDescription))
76
+ }
77
+ }
78
+
79
+ private func scheduleTrimAfterIdle() {
80
+ trimTask?.cancel()
81
+ trimTask = Task { [weak self] in
82
+ guard let self else { return }
83
+ do {
84
+ try await Task.sleep(for: modelWarmTimeout)
85
+ } catch {
86
+ return
87
+ }
88
+ guard !Task.isCancelled else { return }
89
+ await self.trimModelsNow()
90
+ }
91
+ print("[GenerationService] model trim scheduled 60s")
92
+ }
93
+ }
94
+
95
+ private final class GenerationService: NSObject, GenerationServiceProtocol {
96
+ private weak var connection: NSXPCConnection?
97
+ private let runtime = GenerationRuntime()
98
+
99
+ init(connection: NSXPCConnection) {
100
+ self.connection = connection
101
+ }
102
+
103
+ func startGeneration(requestData: Data, reply: @escaping (Bool) -> Void) {
104
+ guard let request = try? JSONDecoder().decode(GenerationWorkerRequest.self, from: requestData) else {
105
+ emit(.init(type: .failed, message: "Invalid generation request."))
106
+ reply(false)
107
+ return
108
+ }
109
+
110
+ reply(runtime.start(request: request) { [weak self] event in
111
+ self?.emit(event)
112
+ })
113
+ }
114
+
115
+ func cancelGeneration(reply: @escaping (Bool) -> Void) {
116
+ runtime.cancel()
117
+ reply(true)
118
+ }
119
+
120
+ func memoryTelemetry(reply: @escaping (Data?) -> Void) {
121
+ let value: [String: Any] = [
122
+ "activeMB": Double(MLX.Memory.activeMemory) / 1_048_576,
123
+ "cacheMB": Double(MLX.Memory.cacheMemory) / 1_048_576,
124
+ ]
125
+ reply(try? JSONSerialization.data(withJSONObject: value))
126
+ }
127
+
128
+ func shutdown(reply: @escaping (Bool) -> Void) {
129
+ guard !runtime.isRunning else {
130
+ reply(false)
131
+ return
132
+ }
133
+ Task { [runtime] in
134
+ await runtime.trimModelsNow()
135
+ reply(true)
136
+ exit(0)
137
+ }
138
+ }
139
+
140
+ private func emit(_ event: GenerationWorkerEvent) {
141
+ guard let data = try? JSONEncoder().encode(event) else { return }
142
+ let client = connection?.remoteObjectProxy as? GenerationServiceClientProtocol
143
+ client?.generationWorkerDidEmit(eventData: data)
144
+ }
145
+ }
146
+
147
+ private final class GenerationServiceDelegate: NSObject, NSXPCListenerDelegate {
148
+ func listener(_ listener: NSXPCListener, shouldAcceptNewConnection connection: NSXPCConnection) -> Bool {
149
+ connection.exportedInterface = NSXPCInterface(with: GenerationServiceProtocol.self)
150
+ connection.remoteObjectInterface = NSXPCInterface(with: GenerationServiceClientProtocol.self)
151
+ connection.exportedObject = GenerationService(connection: connection)
152
+ connection.resume()
153
+ return true
154
+ }
155
+ }
156
+
157
+ // Heavy MLX generation is intentionally isolated in this XPC service. If model
158
+ // loading or Metal memory pressure takes the service down, the app shell can
159
+ // reconnect or report failure instead of dying with the generation process.
160
+ private let delegate = GenerationServiceDelegate()
161
+ private let listener = NSXPCListener.service()
162
+ listener.delegate = delegate
163
+ listener.resume()
164
+
165
+ RunLoop.main.run()