capacitor-wasm-agent-tools 0.1.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.
- package/CapacitorWasmAgentTools.podspec +25 -0
- package/Package.swift +35 -0
- package/android/build.gradle +26 -0
- package/android/src/main/java/com/t6x/plugins/wasmagenttools/WasmAgentToolsPlugin.kt +229 -0
- package/android/src/main/java/uniffi/wasm_agent_tools_ffi/wasm_agent_tools_ffi.kt +2268 -0
- package/android/src/main/jniLibs/arm64-v8a/libwasm_agent_tools_ffi.so +0 -0
- package/dist/esm/definitions.d.ts +56 -0
- package/dist/esm/definitions.d.ts.map +1 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.d.ts.map +1 -0
- package/dist/esm/web.js +28 -0
- package/dist/esm/web.js.map +1 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/Info.plist +47 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64/Headers/module.modulemap +4 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64/Headers/wasm_agent_tools_ffiFFI.h +650 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64/Headers/wasm_agent_tools_ffiFFI.modulemap +4 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64/libwasm_agent_tools_ffi.a +0 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64-simulator/Headers/module.modulemap +4 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64-simulator/Headers/wasm_agent_tools_ffiFFI.h +650 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64-simulator/Headers/wasm_agent_tools_ffiFFI.modulemap +4 -0
- package/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64-simulator/libwasm_agent_tools_ffi.a +0 -0
- package/ios/Sources/WasmAgentToolsPlugin/Generated/wasm_agent_tools_ffi.swift +1484 -0
- package/ios/Sources/WasmAgentToolsPlugin/Generated/wasm_agent_tools_ffiFFI.h +650 -0
- package/ios/Sources/WasmAgentToolsPlugin/Generated/wasm_agent_tools_ffiFFI.modulemap +4 -0
- package/ios/Sources/WasmAgentToolsPlugin/WasmAgentToolsPlugin.swift +234 -0
- package/package.json +52 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorWasmAgentTools'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = 'https://github.com/techxagon/capacitor-wasm-agent-tools'
|
|
11
|
+
s.author = 'Techxagon'
|
|
12
|
+
s.source = { :git => 'https://github.com/techxagon/capacitor-wasm-agent-tools.git', :tag => s.version.to_s }
|
|
13
|
+
|
|
14
|
+
s.source_files = 'ios/Sources/**/*.swift'
|
|
15
|
+
s.ios.deployment_target = '14.0'
|
|
16
|
+
|
|
17
|
+
s.dependency 'Capacitor'
|
|
18
|
+
s.swift_version = '5.9'
|
|
19
|
+
s.vendored_frameworks = 'ios/Frameworks/WasmAgentToolsFFI.xcframework'
|
|
20
|
+
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
'OTHER_SWIFT_FLAGS[sdk=iphoneos*]' => '$(inherited) -Xcc -fmodule-map-file=${PODS_TARGET_SRCROOT}/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64/Headers/wasm_agent_tools_ffiFFI.modulemap',
|
|
23
|
+
'OTHER_SWIFT_FLAGS[sdk=iphonesimulator*]' => '$(inherited) -Xcc -fmodule-map-file=${PODS_TARGET_SRCROOT}/ios/Frameworks/WasmAgentToolsFFI.xcframework/ios-arm64-simulator/Headers/wasm_agent_tools_ffiFFI.modulemap',
|
|
24
|
+
}
|
|
25
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapacitorWasmAgentTools",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapacitorWasmAgentTools",
|
|
10
|
+
targets: ["WasmAgentToolsPlugin"]
|
|
11
|
+
)
|
|
12
|
+
],
|
|
13
|
+
dependencies: [
|
|
14
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
15
|
+
],
|
|
16
|
+
targets: [
|
|
17
|
+
.binaryTarget(
|
|
18
|
+
name: "WasmAgentToolsFFI",
|
|
19
|
+
path: "ios/Frameworks/WasmAgentToolsFFI.xcframework"
|
|
20
|
+
),
|
|
21
|
+
.target(
|
|
22
|
+
name: "WasmAgentToolsPlugin",
|
|
23
|
+
dependencies: [
|
|
24
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
25
|
+
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
26
|
+
"WasmAgentToolsFFI"
|
|
27
|
+
],
|
|
28
|
+
path: "ios/Sources/WasmAgentToolsPlugin",
|
|
29
|
+
exclude: [
|
|
30
|
+
"Generated/wasm_agent_tools_ffiFFI.h",
|
|
31
|
+
"Generated/wasm_agent_tools_ffiFFI.modulemap"
|
|
32
|
+
]
|
|
33
|
+
)
|
|
34
|
+
]
|
|
35
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
|
|
4
|
+
android {
|
|
5
|
+
namespace 'com.t6x.plugins.wasmagenttools'
|
|
6
|
+
compileSdk 36
|
|
7
|
+
defaultConfig {
|
|
8
|
+
minSdkVersion 23
|
|
9
|
+
targetSdkVersion 36
|
|
10
|
+
}
|
|
11
|
+
compileOptions {
|
|
12
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
13
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
kotlin {
|
|
18
|
+
compilerOptions {
|
|
19
|
+
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
dependencies {
|
|
24
|
+
implementation project(':capacitor-android')
|
|
25
|
+
implementation 'net.java.dev.jna:jna:5.14.0@aar'
|
|
26
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
package com.t6x.plugins.wasmagenttools
|
|
2
|
+
|
|
3
|
+
import android.util.Base64
|
|
4
|
+
import com.getcapacitor.JSObject
|
|
5
|
+
import com.getcapacitor.Plugin
|
|
6
|
+
import com.getcapacitor.PluginCall
|
|
7
|
+
import com.getcapacitor.PluginMethod
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
9
|
+
import uniffi.wasm_agent_tools_ffi.JsConfig
|
|
10
|
+
import uniffi.wasm_agent_tools_ffi.JsResult
|
|
11
|
+
import uniffi.wasm_agent_tools_ffi.JsRuntime
|
|
12
|
+
import uniffi.wasm_agent_tools_ffi.PythonConfig
|
|
13
|
+
import uniffi.wasm_agent_tools_ffi.PythonResult
|
|
14
|
+
import uniffi.wasm_agent_tools_ffi.PythonRuntime
|
|
15
|
+
import uniffi.wasm_agent_tools_ffi.SandboxConfig
|
|
16
|
+
import uniffi.wasm_agent_tools_ffi.SandboxResult
|
|
17
|
+
import uniffi.wasm_agent_tools_ffi.WasmSandbox
|
|
18
|
+
|
|
19
|
+
private const val DEFAULT_FUEL_LIMIT = 1_000_000UL
|
|
20
|
+
private const val DEFAULT_MAX_MEMORY_BYTES = 16_777_216UL
|
|
21
|
+
private const val DEFAULT_TIMEOUT_SECS = 30UL
|
|
22
|
+
private const val DEFAULT_JS_FUEL_LIMIT = 1_000_000_000UL
|
|
23
|
+
private const val DEFAULT_JS_MAX_MEMORY_BYTES = 33_554_432UL
|
|
24
|
+
private const val DEFAULT_JS_TIMEOUT_SECS = 5UL
|
|
25
|
+
private const val DEFAULT_PYTHON_FUEL_LIMIT = 1_000_000_000UL
|
|
26
|
+
private const val DEFAULT_PYTHON_MAX_MEMORY_BYTES = 33_554_432UL
|
|
27
|
+
private const val DEFAULT_PYTHON_TIMEOUT_SECS = 5UL
|
|
28
|
+
|
|
29
|
+
@CapacitorPlugin(name = "WasmAgentTools")
|
|
30
|
+
class WasmAgentToolsPlugin : Plugin() {
|
|
31
|
+
private var wasmSandbox: WasmSandbox? = null
|
|
32
|
+
private var jsRuntime: JsRuntime? = null
|
|
33
|
+
private var pythonRuntime: PythonRuntime? = null
|
|
34
|
+
|
|
35
|
+
@PluginMethod
|
|
36
|
+
fun createWasmSandbox(call: PluginCall) {
|
|
37
|
+
try {
|
|
38
|
+
wasmSandbox?.close()
|
|
39
|
+
wasmSandbox = WasmSandbox.create()
|
|
40
|
+
call.resolve()
|
|
41
|
+
} catch (e: Exception) {
|
|
42
|
+
call.reject("createWasmSandbox failed: ${e.message}", e)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@PluginMethod
|
|
47
|
+
fun executeSandbox(call: PluginCall) {
|
|
48
|
+
val sandbox = requireWasmSandbox(call) ?: return
|
|
49
|
+
val wasmBase64 = call.getString("wasmBase64") ?: return call.reject("wasmBase64 is required")
|
|
50
|
+
val inputJson = call.getString("inputJson") ?: return call.reject("inputJson is required")
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
val wasmBytes = Base64.decode(wasmBase64, Base64.DEFAULT)
|
|
54
|
+
val config = toSandboxConfig(call.getObject("config"))
|
|
55
|
+
val result = sandbox.`execute`(wasmBytes, inputJson, config)
|
|
56
|
+
call.resolve(sandboxResultToJs(result))
|
|
57
|
+
} catch (e: Exception) {
|
|
58
|
+
call.reject("executeSandbox failed: ${e.message}", e)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@PluginMethod
|
|
63
|
+
fun executeWatSandbox(call: PluginCall) {
|
|
64
|
+
val sandbox = requireWasmSandbox(call) ?: return
|
|
65
|
+
val watText = call.getString("watText") ?: return call.reject("watText is required")
|
|
66
|
+
val inputJson = call.getString("inputJson") ?: return call.reject("inputJson is required")
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
val config = toSandboxConfig(call.getObject("config"))
|
|
70
|
+
val result = sandbox.`executeWat`(watText, inputJson, config)
|
|
71
|
+
call.resolve(sandboxResultToJs(result))
|
|
72
|
+
} catch (e: Exception) {
|
|
73
|
+
call.reject("executeWatSandbox failed: ${e.message}", e)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@PluginMethod
|
|
78
|
+
fun createJsRuntime(call: PluginCall) {
|
|
79
|
+
try {
|
|
80
|
+
jsRuntime?.close()
|
|
81
|
+
jsRuntime = JsRuntime.create()
|
|
82
|
+
call.resolve()
|
|
83
|
+
} catch (e: Exception) {
|
|
84
|
+
call.reject("createJsRuntime failed: ${e.message}", e)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@PluginMethod
|
|
89
|
+
fun executeJs(call: PluginCall) {
|
|
90
|
+
val runtime = requireJsRuntime(call) ?: return
|
|
91
|
+
val code = call.getString("code") ?: return call.reject("code is required")
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
val config = toJsConfig(call.getObject("config"))
|
|
95
|
+
val result = runtime.`execute`(code, config)
|
|
96
|
+
call.resolve(jsResultToJs(result))
|
|
97
|
+
} catch (e: Exception) {
|
|
98
|
+
call.reject("executeJs failed: ${e.message}", e)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@PluginMethod
|
|
103
|
+
fun createPythonRuntime(call: PluginCall) {
|
|
104
|
+
try {
|
|
105
|
+
pythonRuntime?.close()
|
|
106
|
+
pythonRuntime = PythonRuntime.create()
|
|
107
|
+
call.resolve()
|
|
108
|
+
} catch (e: Exception) {
|
|
109
|
+
call.reject("createPythonRuntime failed: ${e.message}", e)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@PluginMethod
|
|
114
|
+
fun executePython(call: PluginCall) {
|
|
115
|
+
val runtime = requirePythonRuntime(call) ?: return
|
|
116
|
+
val code = call.getString("code") ?: return call.reject("code is required")
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
val config = toPythonConfig(call.getObject("config"))
|
|
120
|
+
val result = runtime.`execute`(code, config)
|
|
121
|
+
call.resolve(pythonResultToJs(result))
|
|
122
|
+
} catch (e: Exception) {
|
|
123
|
+
call.reject("executePython failed: ${e.message}", e)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private fun requireWasmSandbox(call: PluginCall): WasmSandbox? {
|
|
128
|
+
val sandbox = wasmSandbox
|
|
129
|
+
if (sandbox == null) {
|
|
130
|
+
call.reject("WasmSandbox not initialized — call createWasmSandbox() first")
|
|
131
|
+
}
|
|
132
|
+
return sandbox
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private fun requireJsRuntime(call: PluginCall): JsRuntime? {
|
|
136
|
+
val runtime = jsRuntime
|
|
137
|
+
if (runtime == null) {
|
|
138
|
+
call.reject("JsRuntime not initialized - call createJsRuntime() first")
|
|
139
|
+
}
|
|
140
|
+
return runtime
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private fun requirePythonRuntime(call: PluginCall): PythonRuntime? {
|
|
144
|
+
val runtime = pythonRuntime
|
|
145
|
+
if (runtime == null) {
|
|
146
|
+
call.reject("PythonRuntime not initialized - call createPythonRuntime() first")
|
|
147
|
+
}
|
|
148
|
+
return runtime
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private fun toSandboxConfig(config: JSObject?): SandboxConfig {
|
|
152
|
+
val fuelLimit = config?.optLong("fuelLimit", DEFAULT_FUEL_LIMIT.toLong())?.toULong()
|
|
153
|
+
?: DEFAULT_FUEL_LIMIT
|
|
154
|
+
val maxMemoryBytes =
|
|
155
|
+
config?.optLong("maxMemoryBytes", DEFAULT_MAX_MEMORY_BYTES.toLong())?.toULong()
|
|
156
|
+
?: DEFAULT_MAX_MEMORY_BYTES
|
|
157
|
+
val timeoutSecs = config?.optLong("timeoutSecs", DEFAULT_TIMEOUT_SECS.toLong())?.toULong()
|
|
158
|
+
?: DEFAULT_TIMEOUT_SECS
|
|
159
|
+
return SandboxConfig(
|
|
160
|
+
fuelLimit = fuelLimit,
|
|
161
|
+
maxMemoryBytes = maxMemoryBytes,
|
|
162
|
+
timeoutSecs = timeoutSecs,
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private fun toJsConfig(config: JSObject?): JsConfig {
|
|
167
|
+
val fuelLimit =
|
|
168
|
+
config?.optLong("fuelLimit", DEFAULT_JS_FUEL_LIMIT.toLong())?.toULong()
|
|
169
|
+
?: DEFAULT_JS_FUEL_LIMIT
|
|
170
|
+
val maxMemoryBytes =
|
|
171
|
+
config?.optLong("maxMemoryBytes", DEFAULT_JS_MAX_MEMORY_BYTES.toLong())?.toULong()
|
|
172
|
+
?: DEFAULT_JS_MAX_MEMORY_BYTES
|
|
173
|
+
val timeoutSecs =
|
|
174
|
+
config?.optLong("timeoutSecs", DEFAULT_JS_TIMEOUT_SECS.toLong())?.toULong()
|
|
175
|
+
?: DEFAULT_JS_TIMEOUT_SECS
|
|
176
|
+
return JsConfig(
|
|
177
|
+
timeoutSecs = timeoutSecs,
|
|
178
|
+
fuelLimit = fuelLimit,
|
|
179
|
+
maxMemoryBytes = maxMemoryBytes,
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private fun toPythonConfig(config: JSObject?): PythonConfig {
|
|
184
|
+
val fuelLimit =
|
|
185
|
+
config?.optLong("fuelLimit", DEFAULT_PYTHON_FUEL_LIMIT.toLong())?.toULong()
|
|
186
|
+
?: DEFAULT_PYTHON_FUEL_LIMIT
|
|
187
|
+
val maxMemoryBytes =
|
|
188
|
+
config?.optLong("maxMemoryBytes", DEFAULT_PYTHON_MAX_MEMORY_BYTES.toLong())?.toULong()
|
|
189
|
+
?: DEFAULT_PYTHON_MAX_MEMORY_BYTES
|
|
190
|
+
val timeoutSecs =
|
|
191
|
+
config?.optLong("timeoutSecs", DEFAULT_PYTHON_TIMEOUT_SECS.toLong())?.toULong()
|
|
192
|
+
?: DEFAULT_PYTHON_TIMEOUT_SECS
|
|
193
|
+
return PythonConfig(
|
|
194
|
+
timeoutSecs = timeoutSecs,
|
|
195
|
+
fuelLimit = fuelLimit,
|
|
196
|
+
maxMemoryBytes = maxMemoryBytes,
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private fun sandboxResultToJs(result: SandboxResult): JSObject {
|
|
201
|
+
val payload = JSObject()
|
|
202
|
+
payload.put("output", result.output)
|
|
203
|
+
payload.put("fuelConsumed", result.fuelConsumed.toLong())
|
|
204
|
+
payload.put("durationMs", result.durationMs.toLong())
|
|
205
|
+
return payload
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private fun jsResultToJs(result: JsResult): JSObject {
|
|
209
|
+
val payload = JSObject()
|
|
210
|
+
payload.put("output", result.output)
|
|
211
|
+
if (result.error != null) {
|
|
212
|
+
payload.put("error", result.error)
|
|
213
|
+
}
|
|
214
|
+
payload.put("fuelConsumed", result.fuelConsumed.toLong())
|
|
215
|
+
payload.put("durationMs", result.durationMs.toLong())
|
|
216
|
+
return payload
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private fun pythonResultToJs(result: PythonResult): JSObject {
|
|
220
|
+
val payload = JSObject()
|
|
221
|
+
payload.put("output", result.output)
|
|
222
|
+
if (result.error != null) {
|
|
223
|
+
payload.put("error", result.error)
|
|
224
|
+
}
|
|
225
|
+
payload.put("fuelConsumed", result.fuelConsumed.toLong())
|
|
226
|
+
payload.put("durationMs", result.durationMs.toLong())
|
|
227
|
+
return payload
|
|
228
|
+
}
|
|
229
|
+
}
|