@bendyline/gezel-capacitor 0.0.0-stage → 1.0.0

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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/Package.swift +26 -0
  3. package/README.md +230 -2
  4. package/android/build.gradle +30 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelKnowledgePlugin.java +153 -0
  7. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelOfflineSpeechPlugin.java +216 -0
  8. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelRuntimePlugin.java +84 -0
  9. package/android/src/main/java/com/bendyline/gezel/capacitor/KnowledgeFiles.java +101 -0
  10. package/android/src/main/java/com/bendyline/gezel/capacitor/SpeechModels.java +230 -0
  11. package/android/src/main/java/com/bendyline/gezel/speech/SpeechRuntime.java +38 -0
  12. package/dist/index.d.ts +561 -0
  13. package/dist/index.js +7512 -0
  14. package/dist/knowledge-worker.js +211 -0
  15. package/dist/licenses/npm/manifest.json +76 -0
  16. package/dist/licenses/npm/texts/1583809bf1155510d2961f94aa9bca6dc4b44b6f59fd773de33bd6c20860d781.txt +29 -0
  17. package/dist/licenses/npm/texts/1cd39aa4a566eba49eb206b969ef423295e79b50503df567bbdb2e8877d78892.txt +8 -0
  18. package/dist/licenses/npm/texts/3f1189b28e3866e0d979968d466b78f813f76827cfdca1fbb124cc0a5c8841f8.txt +21 -0
  19. package/dist/licenses/npm/texts/5b37224c080cdcc97c871ada971c224e9926370fe74f11b539aa1cf9f3b1aca1.txt +21 -0
  20. package/dist/licenses/npm/texts/c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4.txt +201 -0
  21. package/dist/sqlite3.wasm +0 -0
  22. package/embedding-manifest.json +210 -0
  23. package/ios/Sources/GezelCapacitor/GezelKnowledgePlugin.swift +200 -0
  24. package/ios/Sources/GezelCapacitor/GezelOfflineSpeechPlugin.swift +484 -0
  25. package/ios/Sources/GezelCapacitor/GezelRuntimePlugin.swift +102 -0
  26. package/kokoro-lexicon/LICENSE +202 -0
  27. package/kokoro-lexicon/lexicon-gb-en.txt.gz +0 -0
  28. package/kokoro-lexicon/lexicon-us-en.txt.gz +0 -0
  29. package/native/android/LICENSE-gezel.txt +21 -0
  30. package/native/android/PUBLIC-DISTRIBUTION.md +97 -0
  31. package/native/android/THIRD_PARTY_LICENSES/LICENSE-arm-optimized-routines-MIT-OR-Apache-2.0.txt +249 -0
  32. package/native/android/THIRD_PARTY_LICENSES/LICENSE-cpp-httplib-MIT.txt +22 -0
  33. package/native/android/THIRD_PARTY_LICENSES/LICENSE-fp16-MIT.txt +11 -0
  34. package/native/android/THIRD_PARTY_LICENSES/LICENSE-ggml-MIT.txt +21 -0
  35. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-llamafile-sgemm-MIT.txt +21 -0
  36. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-openvino-APACHE.txt +201 -0
  37. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-pillow-MIT-CMU.txt +30 -0
  38. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-rotate-bits-MIT.txt +21 -0
  39. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-unicode-data-Unicode-3.0.txt +39 -0
  40. package/native/android/THIRD_PARTY_LICENSES/LICENSE-nlohmann-json-MIT.txt +21 -0
  41. package/native/android/THIRD_PARTY_LICENSES/LICENSE-nvidia-cub-BSD-3-Clause.txt +24 -0
  42. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-headers-Apache-2.0-OR-MIT.txt +33 -0
  43. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-APACHE.txt +201 -0
  44. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-cjson-MIT.txt +32 -0
  45. package/native/android/THIRD_PARTY_LICENSES/LICENSE-yarn-MIT.txt +21 -0
  46. package/native/android/THIRD_PARTY_LICENSES/manifest.json +21 -0
  47. package/native/android/engine-manifest.json +88 -0
  48. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.aar +0 -0
  49. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.aar.sha256 +1 -0
  50. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.pom +8 -0
  51. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.pom.sha256 +1 -0
  52. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar +0 -0
  53. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.md5 +1 -0
  54. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha1 +1 -0
  55. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha256 +1 -0
  56. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha512 +1 -0
  57. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar +0 -0
  58. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.md5 +1 -0
  59. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha1 +1 -0
  60. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha256 +1 -0
  61. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha512 +1 -0
  62. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module +118 -0
  63. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.md5 +1 -0
  64. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha1 +1 -0
  65. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha256 +1 -0
  66. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha512 +1 -0
  67. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom +51 -0
  68. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.md5 +1 -0
  69. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha1 +1 -0
  70. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha256 +1 -0
  71. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha512 +1 -0
  72. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml +13 -0
  73. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.md5 +1 -0
  74. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha1 +1 -0
  75. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha256 +1 -0
  76. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha512 +1 -0
  77. package/native/android/sdk-manifest.json +98 -0
  78. package/native/ios/GezelLlama.xcframework/Info.plist +47 -0
  79. package/native/ios/GezelLlama.xcframework/ios-arm64/Headers/gezel_llama.h +290 -0
  80. package/native/ios/GezelLlama.xcframework/ios-arm64/Headers/module.modulemap +9 -0
  81. package/native/ios/GezelLlama.xcframework/ios-arm64/libGezelLlama.a +0 -0
  82. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/Headers/gezel_llama.h +290 -0
  83. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/Headers/module.modulemap +9 -0
  84. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/libGezelLlama.a +0 -0
  85. package/native/ios/LICENSE-gezel.txt +21 -0
  86. package/native/ios/LICENSE-ggml.txt +21 -0
  87. package/native/ios/LICENSE-llama-cpp.txt +21 -0
  88. package/native/ios/PUBLIC-DISTRIBUTION.md +97 -0
  89. package/native/ios/Package.swift +17 -0
  90. package/native/ios/Sources/GezelModelStorage/MobileModelStore.swift +286 -0
  91. package/native/ios/Sources/GezelModelStorage/ModelDownloadHTTP.swift +55 -0
  92. package/native/ios/Sources/GezelModelStorage/ModelDownloadSource.swift +46 -0
  93. package/native/ios/Sources/GezelModelStorage/ModelDownloads.swift +289 -0
  94. package/native/ios/Sources/GezelModelStorage/PrivacyInfo.xcprivacy +32 -0
  95. package/native/ios/Sources/GezelRuntime/AppleFoundationProvider.swift +292 -0
  96. package/native/ios/Sources/GezelRuntime/AppleNativeTools.swift +152 -0
  97. package/native/ios/Sources/GezelRuntime/GezelNativeRuntime.swift +1349 -0
  98. package/native/ios/Sources/GezelRuntime/NativeCall.swift +35 -0
  99. package/native/ios/Sources/GezelRuntime/PrivacyInfo.xcprivacy +31 -0
  100. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-arm-optimized-routines-MIT-OR-Apache-2.0.txt +249 -0
  101. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-cpp-httplib-MIT.txt +22 -0
  102. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-fp16-MIT.txt +11 -0
  103. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-ggml-MIT.txt +21 -0
  104. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-llamafile-sgemm-MIT.txt +21 -0
  105. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-openvino-APACHE.txt +201 -0
  106. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-pillow-MIT-CMU.txt +30 -0
  107. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-rotate-bits-MIT.txt +21 -0
  108. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-unicode-data-Unicode-3.0.txt +39 -0
  109. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-nlohmann-json-MIT.txt +21 -0
  110. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-nvidia-cub-BSD-3-Clause.txt +24 -0
  111. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-headers-Apache-2.0-OR-MIT.txt +33 -0
  112. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-APACHE.txt +201 -0
  113. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-cjson-MIT.txt +32 -0
  114. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-yarn-MIT.txt +21 -0
  115. package/native/ios/THIRD_PARTY_LICENSES/manifest.json +21 -0
  116. package/native/ios/engine-manifest.json +102 -0
  117. package/native/ios/sdk-manifest.json +89 -0
  118. package/package.json +94 -3
  119. package/scripts/embedding-package.d.mts +23 -0
  120. package/scripts/embedding-package.mjs +185 -0
  121. package/scripts/stage-native.mjs +168 -0
@@ -0,0 +1,152 @@
1
+ import Foundation
2
+ import FoundationModels
3
+
4
+ /// One argument shape from `MobileNativeToolSchema` (core/src/mobile/inference.ts).
5
+ /// Core normalizes JSON Schema into this ordered form because Foundation-decoded
6
+ /// dictionaries lose key order, and property order steers Apple's decoder.
7
+ indirect enum NativeToolNode {
8
+ case string(description: String?, choices: [String]?)
9
+ case integer(description: String?)
10
+ case number(description: String?)
11
+ case boolean(description: String?)
12
+ case json(description: String?)
13
+ case array(description: String?, items: NativeToolNode, minItems: Int?, maxItems: Int?)
14
+ case object(description: String?, properties: [(name: String, optional: Bool, schema: NativeToolNode)])
15
+ case anyOf(description: String?, choices: [NativeToolNode])
16
+
17
+ static let maximumDepth = 8
18
+
19
+ init(_ value: Any?, depth: Int = 0) throws {
20
+ guard depth <= Self.maximumDepth, let node = value as? [String: Any], let kind = node["kind"] as? String else {
21
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool argument schema.")
22
+ }
23
+ let description = try Self.text(node["description"], limit: 1_000)
24
+ switch kind {
25
+ case "string":
26
+ var choices: [String]?
27
+ if let raw = node["choices"] {
28
+ guard let values = raw as? [String], (1...64).contains(values.count),
29
+ values.allSatisfy({ !$0.isEmpty && $0.utf8.count <= 200 }) else {
30
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool argument choices.")
31
+ }
32
+ choices = values
33
+ }
34
+ self = .string(description: description, choices: choices)
35
+ case "integer": self = .integer(description: description)
36
+ case "number": self = .number(description: description)
37
+ case "boolean": self = .boolean(description: description)
38
+ case "json": self = .json(description: description)
39
+ case "array":
40
+ self = .array(description: description, items: try NativeToolNode(node["items"], depth: depth + 1),
41
+ minItems: node["minItems"] as? Int, maxItems: node["maxItems"] as? Int)
42
+ case "object":
43
+ guard let raw = node["properties"] as? [[String: Any]], raw.count <= 64 else {
44
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool argument properties.")
45
+ }
46
+ var seen = Set<String>()
47
+ self = .object(description: description, properties: try raw.map { property in
48
+ guard let name = property["name"] as? String, Self.isIdentifier(name), seen.insert(name).inserted,
49
+ let optional = property["optional"] as? Bool else {
50
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool argument property.")
51
+ }
52
+ return (name, optional, try NativeToolNode(property["schema"], depth: depth + 1))
53
+ })
54
+ case "anyOf":
55
+ guard let raw = node["choices"] as? [Any], (2...16).contains(raw.count) else {
56
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool argument union.")
57
+ }
58
+ self = .anyOf(description: description, choices: try raw.map { try NativeToolNode($0, depth: depth + 1) })
59
+ default:
60
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Unsupported tool argument kind.")
61
+ }
62
+ }
63
+
64
+ static func isIdentifier(_ value: String) -> Bool {
65
+ !value.isEmpty && value.utf8.count <= 80 && value.unicodeScalars.allSatisfy {
66
+ CharacterSet.alphanumerics.contains($0) || $0 == "_" || $0 == "-"
67
+ } && value.unicodeScalars.allSatisfy { $0.isASCII }
68
+ }
69
+
70
+ private static func text(_ value: Any?, limit: Int) throws -> String? {
71
+ guard let value else { return nil }
72
+ guard let text = value as? String, text.utf8.count <= limit, !text.contains("\0") else {
73
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool description.")
74
+ }
75
+ return text
76
+ }
77
+
78
+ var description: String? {
79
+ switch self {
80
+ case .string(let d, _), .integer(let d), .number(let d), .boolean(let d), .json(let d),
81
+ .array(let d, _, _, _), .object(let d, _), .anyOf(let d, _):
82
+ return d
83
+ }
84
+ }
85
+
86
+ /// Names only label definitions inside one tool's schema; a path keeps them unique.
87
+ @available(iOS 26.0, macOS 26.0, *)
88
+ func dynamicSchema(name: String) -> DynamicGenerationSchema {
89
+ switch self {
90
+ case .string(_, let choices?): return DynamicGenerationSchema(name: name, description: description, anyOf: choices)
91
+ case .string, .json: return DynamicGenerationSchema(type: String.self)
92
+ case .integer: return DynamicGenerationSchema(type: Int.self)
93
+ case .number: return DynamicGenerationSchema(type: Double.self)
94
+ case .boolean: return DynamicGenerationSchema(type: Bool.self)
95
+ case .array(_, let items, let minItems, let maxItems):
96
+ return DynamicGenerationSchema(arrayOf: items.dynamicSchema(name: "\(name)_item"), minimumElements: minItems, maximumElements: maxItems)
97
+ case .object(let description, let properties):
98
+ return DynamicGenerationSchema(name: name, description: description, properties: properties.map {
99
+ DynamicGenerationSchema.Property(name: $0.name, description: $0.schema.description,
100
+ schema: $0.schema.dynamicSchema(name: "\(name)_\($0.name)"), isOptional: $0.optional)
101
+ })
102
+ case .anyOf(let description, let choices):
103
+ return DynamicGenerationSchema(name: name, description: description,
104
+ anyOf: choices.enumerated().map { $1.dynamicSchema(name: "\(name)_\($0)") })
105
+ }
106
+ }
107
+ }
108
+
109
+ /// What the app's tool loop decided about one call.
110
+ struct NativeToolReply: Sendable {
111
+ let output: String
112
+ let endTurn: Bool
113
+ }
114
+
115
+ /// Thrown from a tool to stop generation once the app ends the turn after its result.
116
+ struct NativeToolTurnEnded: Error {}
117
+
118
+ /// A tool whose execution belongs to the app: the durable record, authorization
119
+ /// and effects all happen in the shared tool loop, reached through `invoke`.
120
+ @available(iOS 26.0, macOS 26.0, *)
121
+ struct AppleBridgedTool: Tool {
122
+ typealias Arguments = GeneratedContent
123
+ typealias Output = String
124
+ let name: String
125
+ let description: String
126
+ let parameters: GenerationSchema
127
+ let invoke: @Sendable (_ name: String, _ arguments: String) async throws -> NativeToolReply
128
+
129
+ init(_ value: [String: Any], invoke: @escaping @Sendable (String, String) async throws -> NativeToolReply) throws {
130
+ guard let name = value["name"] as? String, name.utf8.count <= 80,
131
+ name.range(of: "^[a-z][a-z0-9_]*$", options: .regularExpression) != nil,
132
+ let description = value["description"] as? String, description.utf8.count <= 4_000,
133
+ case .object = try NativeToolNode(value["parameters"]) else {
134
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Invalid tool definition.")
135
+ }
136
+ let node = try NativeToolNode(value["parameters"])
137
+ do {
138
+ parameters = try GenerationSchema(root: node.dynamicSchema(name: "\(name)_arguments"), dependencies: [])
139
+ } catch {
140
+ throw MobileInferenceError(code: "INVALID_ARGUMENT", message: "Tool \(name) has an argument schema Apple on-device AI cannot use.")
141
+ }
142
+ self.name = name
143
+ self.description = description
144
+ self.invoke = invoke
145
+ }
146
+
147
+ func call(arguments: GeneratedContent) async throws -> String {
148
+ let reply = try await invoke(name, arguments.jsonString)
149
+ if reply.endTurn { throw NativeToolTurnEnded() }
150
+ return reply.output
151
+ }
152
+ }