ai.muna.muna 0.0.42

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/Editor/Build/AndroidBuildHandler.cs +96 -0
  2. package/Editor/Build/AndroidBuildHandler.cs.meta +11 -0
  3. package/Editor/Build/BuildHandler.cs +128 -0
  4. package/Editor/Build/BuildHandler.cs.meta +11 -0
  5. package/Editor/Build/LinuxBuildHandler.cs +26 -0
  6. package/Editor/Build/LinuxBuildHandler.cs.meta +11 -0
  7. package/Editor/Build/WebGLBuildHandler.cs +69 -0
  8. package/Editor/Build/WebGLBuildHandler.cs.meta +11 -0
  9. package/Editor/Build/WindowsBuildHandler.cs +24 -0
  10. package/Editor/Build/WindowsBuildHandler.cs.meta +11 -0
  11. package/Editor/Build/iOSBuildHandler.cs +119 -0
  12. package/Editor/Build/iOSBuildHandler.cs.meta +11 -0
  13. package/Editor/Build/macOSBuildHandler.cs +133 -0
  14. package/Editor/Build/macOSBuildHandler.cs.meta +11 -0
  15. package/Editor/Build.meta +8 -0
  16. package/Editor/Muna.Editor.asmdef +18 -0
  17. package/Editor/Muna.Editor.asmdef.meta +7 -0
  18. package/Editor/MunaMenu.cs +32 -0
  19. package/Editor/MunaMenu.cs.meta +11 -0
  20. package/Editor/MunaProjectSettings.cs +43 -0
  21. package/Editor/MunaProjectSettings.cs.meta +11 -0
  22. package/Editor/MunaSettingsProvider.cs +27 -0
  23. package/Editor/MunaSettingsProvider.cs.meta +11 -0
  24. package/Editor.meta +8 -0
  25. package/LICENSE +201 -0
  26. package/LICENSE.meta +7 -0
  27. package/Plugins/Android/Function.aar +0 -0
  28. package/Plugins/Android/Function.aar.meta +32 -0
  29. package/Plugins/Android.meta +8 -0
  30. package/Plugins/Linux/arm64/libFunction.so +0 -0
  31. package/Plugins/Linux/arm64/libFunction.so.meta +62 -0
  32. package/Plugins/Linux/arm64.meta +8 -0
  33. package/Plugins/Linux/x86_64/libFunction.so +0 -0
  34. package/Plugins/Linux/x86_64/libFunction.so.meta +82 -0
  35. package/Plugins/Linux/x86_64.meta +8 -0
  36. package/Plugins/Linux.meta +8 -0
  37. package/Plugins/Web/libFunction.a +0 -0
  38. package/Plugins/Web/libFunction.a.meta +87 -0
  39. package/Plugins/Web.meta +8 -0
  40. package/Plugins/Windows/arm64/Function.dll +0 -0
  41. package/Plugins/Windows/arm64/Function.dll.meta +58 -0
  42. package/Plugins/Windows/arm64.meta +8 -0
  43. package/Plugins/Windows/x86_64/Function.dll +0 -0
  44. package/Plugins/Windows/x86_64/Function.dll.meta +82 -0
  45. package/Plugins/Windows/x86_64.meta +8 -0
  46. package/Plugins/Windows.meta +8 -0
  47. package/Plugins/iOS/Function.xcframework/Info.plist +75 -0
  48. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Function +0 -0
  49. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
  50. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
  51. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
  52. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
  53. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNStatus.h +42 -0
  54. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValue.h +395 -0
  55. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
  56. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/FXNVersion.h +26 -0
  57. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Headers/Function.h +18 -0
  58. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Info.plist +0 -0
  59. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/Modules/module.modulemap +6 -0
  60. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
  61. package/Plugins/iOS/Function.xcframework/ios-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
  62. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Function +0 -0
  63. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
  64. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
  65. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
  66. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
  67. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
  68. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
  69. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
  70. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
  71. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
  72. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
  73. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
  74. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
  75. package/Plugins/iOS/Function.xcframework/ios-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
  76. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Function +0 -0
  77. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNConfiguration.h +313 -0
  78. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPrediction.h +165 -0
  79. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictionStream.h +63 -0
  80. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNPredictor.h +108 -0
  81. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNStatus.h +42 -0
  82. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValue.h +395 -0
  83. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNValueMap.h +148 -0
  84. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/FXNVersion.h +26 -0
  85. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Headers/Function.h +18 -0
  86. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Info.plist +0 -0
  87. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/Modules/module.modulemap +6 -0
  88. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/PrivacyInfo.xcprivacy +36 -0
  89. package/Plugins/iOS/Function.xcframework/xros-arm64/Function.framework/_CodeSignature/CodeResources +223 -0
  90. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Function +0 -0
  91. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNConfiguration.h +313 -0
  92. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPrediction.h +165 -0
  93. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictionStream.h +63 -0
  94. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNPredictor.h +108 -0
  95. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNStatus.h +42 -0
  96. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValue.h +395 -0
  97. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNValueMap.h +148 -0
  98. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/FXNVersion.h +26 -0
  99. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Headers/Function.h +18 -0
  100. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Info.plist +0 -0
  101. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/Modules/module.modulemap +6 -0
  102. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/PrivacyInfo.xcprivacy +36 -0
  103. package/Plugins/iOS/Function.xcframework/xros-arm64_x86_64-simulator/Function.framework/_CodeSignature/CodeResources +223 -0
  104. package/Plugins/iOS/Function.xcframework.meta +83 -0
  105. package/Plugins/iOS.meta +8 -0
  106. package/Plugins/macOS/Function.dylib +0 -0
  107. package/Plugins/macOS/Function.dylib.meta +82 -0
  108. package/Plugins/macOS.meta +8 -0
  109. package/Plugins.meta +8 -0
  110. package/README.md +79 -0
  111. package/README.md.meta +7 -0
  112. package/Runtime/API/DotNetClient.cs +106 -0
  113. package/Runtime/API/DotNetClient.cs.meta +11 -0
  114. package/Runtime/API/MunaClient.cs +96 -0
  115. package/Runtime/API/MunaClient.cs.meta +11 -0
  116. package/Runtime/API.meta +8 -0
  117. package/Runtime/Beta/BetaClient.cs +33 -0
  118. package/Runtime/Beta/BetaClient.cs.meta +11 -0
  119. package/Runtime/Beta/PredictionService.cs +32 -0
  120. package/Runtime/Beta/PredictionService.cs.meta +11 -0
  121. package/Runtime/Beta/RemoteAcceleration.cs +38 -0
  122. package/Runtime/Beta/RemoteAcceleration.cs.meta +11 -0
  123. package/Runtime/Beta/RemotePredictionService.cs +187 -0
  124. package/Runtime/Beta/RemotePredictionService.cs.meta +11 -0
  125. package/Runtime/Beta/Value.cs +92 -0
  126. package/Runtime/Beta/Value.cs.meta +11 -0
  127. package/Runtime/Beta.meta +8 -0
  128. package/Runtime/C/Configuration.cs +139 -0
  129. package/Runtime/C/Configuration.cs.meta +11 -0
  130. package/Runtime/C/Function.cs +294 -0
  131. package/Runtime/C/Function.cs.meta +11 -0
  132. package/Runtime/C/Prediction.cs +70 -0
  133. package/Runtime/C/Prediction.cs.meta +11 -0
  134. package/Runtime/C/PredictionStream.cs +36 -0
  135. package/Runtime/C/PredictionStream.cs.meta +11 -0
  136. package/Runtime/C/Predictor.cs +42 -0
  137. package/Runtime/C/Predictor.cs.meta +11 -0
  138. package/Runtime/C/Value.cs +194 -0
  139. package/Runtime/C/Value.cs.meta +11 -0
  140. package/Runtime/C/ValueMap.cs +50 -0
  141. package/Runtime/C/ValueMap.cs.meta +11 -0
  142. package/Runtime/C.meta +8 -0
  143. package/Runtime/Muna.Runtime.asmdef +27 -0
  144. package/Runtime/Muna.Runtime.asmdef.meta +7 -0
  145. package/Runtime/Muna.cs +109 -0
  146. package/Runtime/Muna.cs.meta +11 -0
  147. package/Runtime/Services/Prediction.cs +247 -0
  148. package/Runtime/Services/Prediction.cs.meta +11 -0
  149. package/Runtime/Services/Predictor.cs +44 -0
  150. package/Runtime/Services/Predictor.cs.meta +11 -0
  151. package/Runtime/Services/User.cs +43 -0
  152. package/Runtime/Services/User.cs.meta +11 -0
  153. package/Runtime/Services.meta +8 -0
  154. package/Runtime/Types/Dtype.cs +118 -0
  155. package/Runtime/Types/Dtype.cs.meta +11 -0
  156. package/Runtime/Types/Image.cs +93 -0
  157. package/Runtime/Types/Image.cs.meta +11 -0
  158. package/Runtime/Types/Prediction.cs +113 -0
  159. package/Runtime/Types/Prediction.cs.meta +11 -0
  160. package/Runtime/Types/Predictor.cs +193 -0
  161. package/Runtime/Types/Predictor.cs.meta +11 -0
  162. package/Runtime/Types/Tensor.cs +58 -0
  163. package/Runtime/Types/Tensor.cs.meta +11 -0
  164. package/Runtime/Types/User.cs +54 -0
  165. package/Runtime/Types/User.cs.meta +11 -0
  166. package/Runtime/Types.meta +8 -0
  167. package/Runtime.meta +8 -0
  168. package/Unity/API/PredictionCacheClient.cs +144 -0
  169. package/Unity/API/PredictionCacheClient.cs.meta +11 -0
  170. package/Unity/API/UnityClient.cs +147 -0
  171. package/Unity/API/UnityClient.cs.meta +11 -0
  172. package/Unity/API.meta +8 -0
  173. package/Unity/Internal/MunaSettings.cs +59 -0
  174. package/Unity/Internal/MunaSettings.cs.meta +11 -0
  175. package/Unity/Internal.meta +8 -0
  176. package/Unity/Muna.Unity.asmdef +29 -0
  177. package/Unity/Muna.Unity.asmdef.meta +7 -0
  178. package/Unity/MunaUnity.cs +130 -0
  179. package/Unity/MunaUnity.cs.meta +11 -0
  180. package/Unity/Types/CachedPrediction.cs +36 -0
  181. package/Unity/Types/CachedPrediction.cs.meta +11 -0
  182. package/Unity/Types.meta +8 -0
  183. package/Unity.meta +8 -0
  184. package/package.json +38 -0
  185. package/package.json.meta +7 -0
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Muna
3
+ * Copyright © 2025 NatML Inc. All rights reserved.
4
+ */
5
+
6
+ #nullable enable
7
+
8
+ namespace Muna.Beta {
9
+
10
+ using System;
11
+ using System.IO;
12
+ using System.Linq;
13
+ using System.Runtime.CompilerServices;
14
+ using System.Runtime.Serialization;
15
+ using System.Text;
16
+
17
+ /// <summary>
18
+ /// Remote prediction value.
19
+ /// </summary>
20
+ [Preserve, Serializable]
21
+ internal class Value {
22
+
23
+ /// <summary>
24
+ /// Value URL.
25
+ /// </summary>
26
+ public string? data;
27
+
28
+ /// <summary>
29
+ /// Value type.
30
+ /// </summary>
31
+ public Dtype type;
32
+
33
+ /// <summary>
34
+ /// Value shape.
35
+ /// This is `null` if shape information is not available or applicable.
36
+ /// </summary>
37
+ public int[]? shape;
38
+ }
39
+
40
+ internal static class ValueUtils {
41
+
42
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
43
+ public static object ToObject<T>(this Stream stream, int[] shape) where T : unmanaged {
44
+ var data = stream.ToArray<T>();
45
+ return shape.Length > 0 ? new Tensor<T>(data, shape) : data[0];
46
+ }
47
+
48
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
49
+ public static object ToObject(this Enum value) {
50
+ var fieldInfo = value.GetType().GetField(value.ToString());
51
+ var attribute = fieldInfo?
52
+ .GetCustomAttributes(typeof(EnumMemberAttribute), false)?
53
+ .FirstOrDefault() as EnumMemberAttribute;
54
+ return (attribute?.IsValueSetExplicitly ?? false) ? attribute.Value : Convert.ToInt32(value);
55
+ }
56
+
57
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
58
+ public static unsafe Stream ToStream<T>(this T[] data) where T : unmanaged {
59
+ if (data is byte[] raw)
60
+ return new MemoryStream(raw);
61
+ var size = data.Length * sizeof(T);
62
+ var array = new byte[size];
63
+ fixed (void* src = data, dst = array)
64
+ Buffer.MemoryCopy(src, dst, size, size);
65
+ return new MemoryStream(array);
66
+ }
67
+
68
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
69
+ public static Stream ToStream(this string data) => new MemoryStream(Encoding.UTF8.GetBytes(data));
70
+
71
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
72
+ public static unsafe T[] ToArray<T>(this Stream stream) where T : unmanaged {
73
+ var result = new T[stream.Length / sizeof(T)];
74
+ fixed (T* dst = result)
75
+ using (var dstStream = new UnmanagedMemoryStream(
76
+ (byte*)dst,
77
+ stream.Length,
78
+ stream.Length,
79
+ FileAccess.Write
80
+ ))
81
+ stream.CopyTo(dstStream);
82
+ return result;
83
+ }
84
+
85
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
86
+ public static Stream Clone(this Stream stream) {
87
+ var result = new MemoryStream();
88
+ stream.CopyTo(result);
89
+ return result;
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: aefa75d7ec457459fa9daca138d258fd
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: e93ff2e15287c4e6d9881c345b63276d
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,139 @@
1
+ /*
2
+ * Muna
3
+ * Copyright © 2025 NatML Inc. All rights reserved.
4
+ */
5
+
6
+ #nullable enable
7
+
8
+ namespace Muna.C {
9
+
10
+ using System;
11
+ using System.Runtime.InteropServices;
12
+ using System.Text;
13
+ using System.Threading.Tasks;
14
+ using static Muna;
15
+
16
+ public sealed class Configuration : IDisposable {
17
+
18
+ #region --Client API--
19
+
20
+ public string tag {
21
+ get {
22
+ var sb = new StringBuilder(2048);
23
+ configuration.GetConfigurationTag(sb, sb.Capacity).Throw();
24
+ return sb.ToString();
25
+ }
26
+ set => configuration.SetConfigurationTag(value).Throw();
27
+ }
28
+
29
+ public string token {
30
+ get {
31
+ var sb = new StringBuilder(2048);
32
+ configuration.GetConfigurationToken(sb, sb.Capacity).Throw();
33
+ return sb.ToString();
34
+ }
35
+ set => configuration.SetConfigurationToken(value).Throw();
36
+ }
37
+
38
+ public Acceleration acceleration {
39
+ get => configuration.GetConfigurationAcceleration(out var acceleration).Throw() == Status.Ok ? acceleration : default;
40
+ set => configuration.SetConfigurationAcceleration(value).Throw();
41
+ }
42
+
43
+ public IntPtr device {
44
+ get => configuration.GetConfigurationDevice(out var device).Throw() == Status.Ok ? device : default;
45
+ set => configuration.SetConfigurationDevice(value).Throw();
46
+ }
47
+
48
+ public static string ConfigurationId {
49
+ get {
50
+ var sb = new StringBuilder(2048);
51
+ GetConfigurationUniqueID(sb, sb.Capacity).Throw();
52
+ return sb.ToString();
53
+ }
54
+ }
55
+
56
+ public static string ClientId {
57
+ get {
58
+ var sb = new StringBuilder(64);
59
+ GetConfigurationClientID(sb, sb.Capacity).Throw();
60
+ return sb.ToString();
61
+ }
62
+ }
63
+
64
+ public static Task InitializationTask {
65
+ get {
66
+ #if UNITY_WEBGL && !UNITY_EDITOR
67
+ var tcs = new TaskCompletionSource<bool>();
68
+ var context = GCHandle.Alloc(tcs, GCHandleType.Normal);
69
+ SetInitializationHandler(OnFunctionInitialized, (IntPtr)context);
70
+ return tcs.Task;
71
+ [DllImport(Muna.Assembly, EntryPoint = @"FXNSetInitializationHandler")]
72
+ static extern Status SetInitializationHandler (Action<IntPtr> handler, IntPtr context);
73
+ #else
74
+ return Task.CompletedTask;
75
+ #endif
76
+ }
77
+ }
78
+
79
+ public Configuration() {
80
+ CreateConfiguration(out var configuration).Throw();
81
+ this.configuration = configuration;
82
+ }
83
+
84
+ public Task AddResource(string type, string path) {
85
+ #if UNITY_WEBGL && !UNITY_EDITOR
86
+ var tcs = new TaskCompletionSource<bool>();
87
+ var context = GCHandle.Alloc(tcs, GCHandleType.Normal);
88
+ AddConfigurationResource(configuration, type, path, OnAddConfigurationResource, (IntPtr)context);
89
+ return tcs.Task;
90
+ [DllImport(Muna.Assembly, EntryPoint = @"FXNConfigurationAddResourceAsync")]
91
+ static extern Status AddConfigurationResource(
92
+ IntPtr configuration,
93
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string type,
94
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string path,
95
+ Action<IntPtr, Status> handler,
96
+ IntPtr context
97
+ );
98
+ #else
99
+ try {
100
+ configuration.AddConfigurationResource(type, path).Throw();
101
+ return Task.CompletedTask;
102
+ } catch (Exception ex) {
103
+ return Task.FromException(ex);
104
+ }
105
+ #endif
106
+ }
107
+
108
+ public void Dispose() => configuration.ReleaseConfiguration();
109
+ #endregion
110
+
111
+
112
+ #region --Operations--
113
+ private readonly IntPtr configuration;
114
+
115
+ public static implicit operator IntPtr(Configuration configuration) => configuration.configuration;
116
+
117
+ [MonoPInvokeCallback(typeof(Action<IntPtr>))]
118
+ private static void OnFunctionInitialized(IntPtr context) {
119
+ var handle = (GCHandle)context;
120
+ var tcs = handle.Target as TaskCompletionSource<bool>;
121
+ handle.Free();
122
+ tcs?.SetResult(true);
123
+ }
124
+
125
+ [MonoPInvokeCallback(typeof(Action<IntPtr, Status>))]
126
+ private static void OnAddConfigurationResource(IntPtr context, Status status) {
127
+ var handle = (GCHandle)context;
128
+ var tcs = handle.Target as TaskCompletionSource<bool>;
129
+ handle.Free();
130
+ try {
131
+ status.Throw();
132
+ tcs?.SetResult(true);
133
+ } catch (Exception ex) {
134
+ tcs?.SetException(ex);
135
+ }
136
+ }
137
+ #endregion
138
+ }
139
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 448a8ed20ef154d808977a87fe82ee58
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,294 @@
1
+ /*
2
+ * Muna
3
+ * Copyright © 2025 NatML Inc. All rights reserved.
4
+ */
5
+
6
+ #nullable enable
7
+
8
+ namespace Muna.C {
9
+
10
+ using System;
11
+ using System.Runtime.InteropServices;
12
+ using System.Text;
13
+
14
+ internal static unsafe class Muna {
15
+
16
+ public const string Assembly =
17
+ #if (UNITY_IOS || UNITY_VISIONOS || UNITY_WEBGL) && !UNITY_EDITOR
18
+ @"__Internal";
19
+ #else
20
+ @"Function";
21
+ #endif
22
+
23
+
24
+ #region --Enumerations--
25
+ /// <summary>
26
+ /// Status codes.
27
+ /// </summary>
28
+ public enum Status : int {
29
+ Ok = 0,
30
+ InvalidArgument = 1,
31
+ InvalidOperation = 2,
32
+ NotImplemented = 3,
33
+ }
34
+ #endregion
35
+
36
+
37
+ #region --FXNValue--
38
+ [DllImport(Assembly, EntryPoint = @"FXNValueRelease")]
39
+ public static extern Status ReleaseValue(this IntPtr value);
40
+ [DllImport(Assembly, EntryPoint = @"FXNValueGetData")]
41
+ public static extern Status GetValueData(
42
+ this IntPtr value,
43
+ out IntPtr data
44
+ );
45
+ [DllImport(Assembly, EntryPoint = @"FXNValueGetType")]
46
+ public static extern Status GetValueType(
47
+ this IntPtr value,
48
+ out Dtype type
49
+ );
50
+ [DllImport(Assembly, EntryPoint = @"FXNValueGetDimensions")]
51
+ public static extern Status GetValueDimensions(
52
+ this IntPtr value,
53
+ out int dimensions
54
+ );
55
+ [DllImport(Assembly, EntryPoint = @"FXNValueGetShape")]
56
+ public static extern Status GetValueShape(
57
+ this IntPtr value,
58
+ [Out] int[] shape,
59
+ int shapeLen
60
+ );
61
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateArray")]
62
+ public static unsafe extern Status CreateArrayValue(
63
+ void* data,
64
+ [In] int[]? shape,
65
+ int dims,
66
+ Dtype dtype,
67
+ Value.Flags flags,
68
+ out IntPtr value
69
+ );
70
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateString")]
71
+ public static extern Status CreateStringValue(
72
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string data,
73
+ out IntPtr value
74
+ );
75
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateList")]
76
+ public static extern Status CreateListValue(
77
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string data,
78
+ out IntPtr value
79
+ );
80
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateDict")]
81
+ public static extern Status CreateDictValue(
82
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string data,
83
+ out IntPtr value
84
+ );
85
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateImage")]
86
+ public static extern Status CreateImageValue(
87
+ byte* pixelBuffer,
88
+ int width,
89
+ int height,
90
+ int channels,
91
+ Value.Flags flags,
92
+ out IntPtr value
93
+ );
94
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateBinary")]
95
+ public static extern Status CreateBinaryValue(
96
+ [In] byte[] buffer,
97
+ int bufferLen,
98
+ Value.Flags flags,
99
+ out IntPtr value
100
+ );
101
+ [DllImport(Assembly, EntryPoint = @"FXNValueCreateNull")]
102
+ public static extern Status CreateNullValue(out IntPtr value);
103
+ #endregion
104
+
105
+
106
+ #region --FXNValueMap--
107
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapCreate")]
108
+ public static extern Status CreateValueMap(out IntPtr map);
109
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapRelease")]
110
+ public static extern Status ReleaseValueMap(this IntPtr map);
111
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapGetSize")]
112
+ public static extern Status GetValueMapSize(
113
+ this IntPtr map,
114
+ out int size
115
+ );
116
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapGetKey")]
117
+ public static extern Status GetValueMapKey(
118
+ this IntPtr map,
119
+ int index,
120
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder key,
121
+ int size
122
+ );
123
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapGetValue")]
124
+ public static extern Status GetValueMapValue(
125
+ this IntPtr map,
126
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string key,
127
+ out IntPtr value
128
+ );
129
+ [DllImport(Assembly, EntryPoint = @"FXNValueMapSetValue")]
130
+ public static extern Status SetValueMapValue(
131
+ this IntPtr map,
132
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string key,
133
+ IntPtr value
134
+ );
135
+ #endregion
136
+
137
+
138
+ #region --FXNConfiguration--
139
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetUniqueID")]
140
+ public static extern Status GetConfigurationUniqueID(
141
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder identifier,
142
+ int size
143
+ );
144
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetClientID")]
145
+ public static extern Status GetConfigurationClientID(
146
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder identifier,
147
+ int size
148
+ );
149
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationCreate")]
150
+ public static extern Status CreateConfiguration(out IntPtr configuration);
151
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationRelease")]
152
+ public static extern Status ReleaseConfiguration(this IntPtr configuration);
153
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetTag")]
154
+ public static extern Status GetConfigurationTag(
155
+ this IntPtr configuration,
156
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder tag,
157
+ int size
158
+ );
159
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationSetTag")]
160
+ public static extern Status SetConfigurationTag(
161
+ this IntPtr configuration,
162
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string? tag
163
+ );
164
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetToken")]
165
+ public static extern Status GetConfigurationToken(
166
+ this IntPtr configuration,
167
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder token,
168
+ int size
169
+ );
170
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationSetToken")]
171
+ public static extern Status SetConfigurationToken(
172
+ this IntPtr configuration,
173
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string? token
174
+ );
175
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetAcceleration")]
176
+ public static extern Status GetConfigurationAcceleration(
177
+ this IntPtr configuration,
178
+ out Acceleration acceleration
179
+ );
180
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationSetAcceleration")]
181
+ public static extern Status SetConfigurationAcceleration(
182
+ this IntPtr configuration,
183
+ Acceleration acceleration
184
+ );
185
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationSetDevice")]
186
+ public static extern Status SetConfigurationDevice(
187
+ this IntPtr configuration,
188
+ IntPtr device
189
+ );
190
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationGetDevice")]
191
+ public static extern Status GetConfigurationDevice(
192
+ this IntPtr configuration,
193
+ out IntPtr device
194
+ );
195
+ [DllImport(Assembly, EntryPoint = @"FXNConfigurationAddResource")]
196
+ public static extern Status AddConfigurationResource(
197
+ this IntPtr configuration,
198
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string type,
199
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string path
200
+ );
201
+ #endregion
202
+
203
+
204
+ #region --FXNPrediction--
205
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionRelease")]
206
+ public static extern Status ReleasePrediction(this IntPtr prediction);
207
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetID")]
208
+ public static extern Status GetPredictionID(
209
+ this IntPtr prediction,
210
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder id,
211
+ int size
212
+ );
213
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetLatency")]
214
+ public static extern Status GetPredictionLatency(
215
+ this IntPtr prediction,
216
+ out double latency
217
+ );
218
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetResults")]
219
+ public static extern Status GetPredictionResults(
220
+ this IntPtr prediction,
221
+ out IntPtr map
222
+ );
223
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetError")]
224
+ public static extern Status GetPredictionError(
225
+ this IntPtr prediction,
226
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder error,
227
+ int size
228
+ );
229
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetLogs")]
230
+ public static extern Status GetPredictionLogs(
231
+ this IntPtr prediction,
232
+ [MarshalAs(UnmanagedType.LPUTF8Str), Out] StringBuilder logs,
233
+ int size
234
+ );
235
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionGetLogLength")]
236
+ public static extern Status GetPredictionLogLength(
237
+ this IntPtr prediction,
238
+ out int size
239
+ );
240
+ #endregion
241
+
242
+
243
+ #region --FXNPredictionStream--
244
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionStreamRelease")]
245
+ public static extern Status ReleasePredictionStream(this IntPtr stream);
246
+ [DllImport(Assembly, EntryPoint = @"FXNPredictionStreamReadNext")]
247
+ public static extern Status ReadNextPrediction(
248
+ this IntPtr stream,
249
+ out IntPtr prediction
250
+ );
251
+ #endregion
252
+
253
+
254
+ #region --FXNPredictor--
255
+ [DllImport(Assembly, EntryPoint = @"FXNPredictorCreate")]
256
+ public static extern Status CreatePredictor(
257
+ IntPtr configuration,
258
+ out IntPtr predictor
259
+ );
260
+ [DllImport(Assembly, EntryPoint = @"FXNPredictorRelease")]
261
+ public static extern Status ReleasePredictor(this IntPtr predictor);
262
+ [DllImport(Assembly, EntryPoint = @"FXNPredictorCreatePrediction")]
263
+ public static extern Status CreatePrediction(
264
+ this IntPtr predictor,
265
+ IntPtr inputs,
266
+ out IntPtr prediction
267
+ );
268
+ [DllImport(Assembly, EntryPoint = @"FXNPredictorStreamPrediction")]
269
+ public static extern Status StreamPrediction(
270
+ this IntPtr predictor,
271
+ IntPtr inputs,
272
+ out IntPtr stream
273
+ );
274
+ #endregion
275
+
276
+
277
+ #region --FXNVersion--
278
+ [DllImport(Assembly, EntryPoint = @"FXNGetVersion")]
279
+ public static extern IntPtr GetVersion();
280
+ #endregion
281
+
282
+
283
+ #region --Utilities--
284
+
285
+ public static Status Throw(this Status status) => status switch {
286
+ Status.Ok => status,
287
+ Status.InvalidArgument => throw new ArgumentException(),
288
+ Status.InvalidOperation => throw new InvalidOperationException(),
289
+ Status.NotImplemented => throw new NotImplementedException(),
290
+ _ => throw new InvalidOperationException(),
291
+ };
292
+ #endregion
293
+ }
294
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: c9c4393bfa37641d88f2b4cffdd551ca
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Muna
3
+ * Copyright © 2025 NatML Inc. All rights reserved.
4
+ */
5
+
6
+ #nullable enable
7
+
8
+ namespace Muna.C {
9
+
10
+ using System;
11
+ using System.Text;
12
+ using static Muna;
13
+
14
+ public sealed class Prediction : IDisposable {
15
+
16
+ #region --Client API--
17
+
18
+ public string id {
19
+ get {
20
+ var id = new StringBuilder(64);
21
+ prediction.GetPredictionID(id, id.Capacity).Throw();
22
+ return id.ToString();
23
+ }
24
+ }
25
+
26
+ public double latency {
27
+ get {
28
+ prediction.GetPredictionLatency(out var latency).Throw();
29
+ return latency;
30
+ }
31
+ }
32
+
33
+ public ValueMap? results {
34
+ get {
35
+ var map = prediction.GetPredictionResults(out var m).Throw() == Status.Ok ?
36
+ new ValueMap(m) :
37
+ default;
38
+ return map?.size > 0 ? map : default;
39
+ }
40
+ }
41
+
42
+ public string? error {
43
+ get {
44
+ var error = new StringBuilder(2048);
45
+ return prediction.GetPredictionError(error, error.Capacity) == Status.Ok ? error.ToString() : null;
46
+ }
47
+ }
48
+
49
+ public string logs {
50
+ get {
51
+ prediction.GetPredictionLogLength(out var length).Throw();
52
+ var logs = new StringBuilder(length + 1);
53
+ prediction.GetPredictionLogs(logs, logs.Capacity);
54
+ return logs.ToString();
55
+ }
56
+ }
57
+
58
+ public void Dispose() => prediction.ReleasePrediction();
59
+ #endregion
60
+
61
+
62
+ #region --Operations--
63
+ private readonly IntPtr prediction;
64
+
65
+ internal Prediction(IntPtr prediction) => this.prediction = prediction;
66
+
67
+ public static implicit operator IntPtr(Prediction prediction) => prediction.prediction;
68
+ #endregion
69
+ }
70
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 2ce2240486acd47c48cb1e11e63221b7
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Muna
3
+ * Copyright © 2025 NatML Inc. All rights reserved.
4
+ */
5
+
6
+ #nullable enable
7
+
8
+ namespace Muna.C {
9
+
10
+ using System;
11
+ using static Muna;
12
+
13
+ public sealed class PredictionStream : IDisposable {
14
+
15
+ #region --Client API--
16
+
17
+ public Prediction? ReadNext() {
18
+ if (stream.ReadNextPrediction(out var prediction) == Status.Ok)
19
+ return new Prediction(prediction);
20
+ else
21
+ return null;
22
+ }
23
+
24
+ public void Dispose() => stream.ReleasePredictionStream();
25
+ #endregion
26
+
27
+
28
+ #region --Operations--
29
+ private readonly IntPtr stream;
30
+
31
+ internal PredictionStream(IntPtr stream) => this.stream = stream;
32
+
33
+ public static implicit operator IntPtr(PredictionStream stream) => stream.stream;
34
+ #endregion
35
+ }
36
+ }