edge-intelligence-sdk 0.3.7
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/android/jniLibs/arm64-v8a/libel_ffi.so +0 -0
- package/ios/libel_ffi.a +0 -0
- package/package.json +18 -0
- package/src/rn/cpp/el_ffi.cpp +2668 -0
- package/src/rn/cpp/el_ffi.hpp +66 -0
- package/src/rn/el_ffi-ffi.ts +119 -0
- package/src/rn/el_ffi.ts +545 -0
- package/src/web/el_ffi.d.ts +68 -0
- package/src/web/el_ffi.js +298 -0
- package/src/web/el_ffi_bg.wasm +0 -0
- package/src/web/el_ffi_bg.wasm.d.ts +13 -0
- package/src/web/package.json +17 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/* @ts-self-types="./el_ffi.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The flat FFI-friendly facade (ADR-001, ADR-009, ADR-010).
|
|
5
|
+
*
|
|
6
|
+
* Annotated for all three binding surfaces:
|
|
7
|
+
* - `uniffi::Object` (native) → opaque UniFFI / React Native handle
|
|
8
|
+
* - `frb(opaque)` (native) → opaque Flutter/Dart handle via FRB v2
|
|
9
|
+
* - `wasm_bindgen` (wasm32) → satisfies `IntoWasmAbi`/`WasmDescribe` so
|
|
10
|
+
* that `#[wasm_bindgen] impl EdgeLlm { ... }` compiles
|
|
11
|
+
*/
|
|
12
|
+
export class EdgeLlm {
|
|
13
|
+
static __wrap(ptr) {
|
|
14
|
+
const obj = Object.create(EdgeLlm.prototype);
|
|
15
|
+
obj.__wbg_ptr = ptr;
|
|
16
|
+
EdgeLlmFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
__destroy_into_raw() {
|
|
20
|
+
const ptr = this.__wbg_ptr;
|
|
21
|
+
this.__wbg_ptr = 0;
|
|
22
|
+
EdgeLlmFinalization.unregister(this);
|
|
23
|
+
return ptr;
|
|
24
|
+
}
|
|
25
|
+
free() {
|
|
26
|
+
const ptr = this.__destroy_into_raw();
|
|
27
|
+
wasm.__wbg_edgellm_free(ptr, 0);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Blocking chat; throws a JS Error on provider failure.
|
|
31
|
+
* @param {string} prompt
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
ask_wasm(prompt) {
|
|
35
|
+
let deferred3_0;
|
|
36
|
+
let deferred3_1;
|
|
37
|
+
try {
|
|
38
|
+
const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
39
|
+
const len0 = WASM_VECTOR_LEN;
|
|
40
|
+
const ret = wasm.edgellm_ask_wasm(this.__wbg_ptr, ptr0, len0);
|
|
41
|
+
var ptr2 = ret[0];
|
|
42
|
+
var len2 = ret[1];
|
|
43
|
+
if (ret[3]) {
|
|
44
|
+
ptr2 = 0; len2 = 0;
|
|
45
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
46
|
+
}
|
|
47
|
+
deferred3_0 = ptr2;
|
|
48
|
+
deferred3_1 = len2;
|
|
49
|
+
return getStringFromWasm0(ptr2, len2);
|
|
50
|
+
} finally {
|
|
51
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Frontier cloud backend is **not yet available on web** (ADR-010):
|
|
56
|
+
* `el-cloud`'s blocking HTTP transport has no wasm implementation, and
|
|
57
|
+
* the synchronous `LlmProvider` trait cannot await the browser's async
|
|
58
|
+
* `fetch`. Always throws so callers fail loudly instead of silently
|
|
59
|
+
* receiving an echo stub. Use a native binding (React Native / Flutter)
|
|
60
|
+
* for cloud access.
|
|
61
|
+
* @param {string} _model
|
|
62
|
+
* @param {string} _api_key
|
|
63
|
+
* @returns {EdgeLlm}
|
|
64
|
+
*/
|
|
65
|
+
static cloud(_model, _api_key) {
|
|
66
|
+
const ptr0 = passStringToWasm0(_model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
67
|
+
const len0 = WASM_VECTOR_LEN;
|
|
68
|
+
const ptr1 = passStringToWasm0(_api_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
69
|
+
const len1 = WASM_VECTOR_LEN;
|
|
70
|
+
const ret = wasm.edgellm_cloud(ptr0, len0, ptr1, len1);
|
|
71
|
+
if (ret[2]) {
|
|
72
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
73
|
+
}
|
|
74
|
+
return EdgeLlm.__wrap(ret[0]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} model_uri
|
|
78
|
+
*/
|
|
79
|
+
constructor(model_uri) {
|
|
80
|
+
const ptr0 = passStringToWasm0(model_uri, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
81
|
+
const len0 = WASM_VECTOR_LEN;
|
|
82
|
+
const ret = wasm.edgellm_new_local(ptr0, len0);
|
|
83
|
+
if (ret[2]) {
|
|
84
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
85
|
+
}
|
|
86
|
+
this.__wbg_ptr = ret[0];
|
|
87
|
+
EdgeLlmFinalization.register(this, this.__wbg_ptr, this);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (Symbol.dispose) EdgeLlm.prototype[Symbol.dispose] = EdgeLlm.prototype.free;
|
|
92
|
+
function __wbg_get_imports() {
|
|
93
|
+
const import0 = {
|
|
94
|
+
__proto__: null,
|
|
95
|
+
__wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
|
|
96
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
97
|
+
},
|
|
98
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
99
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
100
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
101
|
+
return ret;
|
|
102
|
+
},
|
|
103
|
+
__wbindgen_init_externref_table: function() {
|
|
104
|
+
const table = wasm.__wbindgen_externrefs;
|
|
105
|
+
const offset = table.grow(4);
|
|
106
|
+
table.set(0, undefined);
|
|
107
|
+
table.set(offset + 0, undefined);
|
|
108
|
+
table.set(offset + 1, null);
|
|
109
|
+
table.set(offset + 2, true);
|
|
110
|
+
table.set(offset + 3, false);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
__proto__: null,
|
|
115
|
+
"./el_ffi_bg.js": import0,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const EdgeLlmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
120
|
+
? { register: () => {}, unregister: () => {} }
|
|
121
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_edgellm_free(ptr, 1));
|
|
122
|
+
|
|
123
|
+
function getStringFromWasm0(ptr, len) {
|
|
124
|
+
return decodeText(ptr >>> 0, len);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let cachedUint8ArrayMemory0 = null;
|
|
128
|
+
function getUint8ArrayMemory0() {
|
|
129
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
130
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
131
|
+
}
|
|
132
|
+
return cachedUint8ArrayMemory0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
136
|
+
if (realloc === undefined) {
|
|
137
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
138
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
139
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
140
|
+
WASM_VECTOR_LEN = buf.length;
|
|
141
|
+
return ptr;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let len = arg.length;
|
|
145
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
146
|
+
|
|
147
|
+
const mem = getUint8ArrayMemory0();
|
|
148
|
+
|
|
149
|
+
let offset = 0;
|
|
150
|
+
|
|
151
|
+
for (; offset < len; offset++) {
|
|
152
|
+
const code = arg.charCodeAt(offset);
|
|
153
|
+
if (code > 0x7F) break;
|
|
154
|
+
mem[ptr + offset] = code;
|
|
155
|
+
}
|
|
156
|
+
if (offset !== len) {
|
|
157
|
+
if (offset !== 0) {
|
|
158
|
+
arg = arg.slice(offset);
|
|
159
|
+
}
|
|
160
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
161
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
162
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
163
|
+
|
|
164
|
+
offset += ret.written;
|
|
165
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
WASM_VECTOR_LEN = offset;
|
|
169
|
+
return ptr;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function takeFromExternrefTable0(idx) {
|
|
173
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
174
|
+
wasm.__externref_table_dealloc(idx);
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
179
|
+
cachedTextDecoder.decode();
|
|
180
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
181
|
+
let numBytesDecoded = 0;
|
|
182
|
+
function decodeText(ptr, len) {
|
|
183
|
+
numBytesDecoded += len;
|
|
184
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
185
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
186
|
+
cachedTextDecoder.decode();
|
|
187
|
+
numBytesDecoded = len;
|
|
188
|
+
}
|
|
189
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const cachedTextEncoder = new TextEncoder();
|
|
193
|
+
|
|
194
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
195
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
196
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
197
|
+
view.set(buf);
|
|
198
|
+
return {
|
|
199
|
+
read: arg.length,
|
|
200
|
+
written: buf.length
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let WASM_VECTOR_LEN = 0;
|
|
206
|
+
|
|
207
|
+
let wasmModule, wasmInstance, wasm;
|
|
208
|
+
function __wbg_finalize_init(instance, module) {
|
|
209
|
+
wasmInstance = instance;
|
|
210
|
+
wasm = instance.exports;
|
|
211
|
+
wasmModule = module;
|
|
212
|
+
cachedUint8ArrayMemory0 = null;
|
|
213
|
+
wasm.__wbindgen_start();
|
|
214
|
+
return wasm;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function __wbg_load(module, imports) {
|
|
218
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
219
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
220
|
+
try {
|
|
221
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
224
|
+
|
|
225
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
226
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
227
|
+
|
|
228
|
+
} else { throw e; }
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const bytes = await module.arrayBuffer();
|
|
233
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
234
|
+
} else {
|
|
235
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
236
|
+
|
|
237
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
238
|
+
return { instance, module };
|
|
239
|
+
} else {
|
|
240
|
+
return instance;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function expectedResponseType(type) {
|
|
245
|
+
switch (type) {
|
|
246
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function initSync(module) {
|
|
253
|
+
if (wasm !== undefined) return wasm;
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if (module !== undefined) {
|
|
257
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
258
|
+
({module} = module)
|
|
259
|
+
} else {
|
|
260
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const imports = __wbg_get_imports();
|
|
265
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
266
|
+
module = new WebAssembly.Module(module);
|
|
267
|
+
}
|
|
268
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
269
|
+
return __wbg_finalize_init(instance, module);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function __wbg_init(module_or_path) {
|
|
273
|
+
if (wasm !== undefined) return wasm;
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
if (module_or_path !== undefined) {
|
|
277
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
278
|
+
({module_or_path} = module_or_path)
|
|
279
|
+
} else {
|
|
280
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (module_or_path === undefined) {
|
|
285
|
+
module_or_path = new URL('el_ffi_bg.wasm', import.meta.url);
|
|
286
|
+
}
|
|
287
|
+
const imports = __wbg_get_imports();
|
|
288
|
+
|
|
289
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
290
|
+
module_or_path = fetch(module_or_path);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
294
|
+
|
|
295
|
+
return __wbg_finalize_init(instance, module);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_edgellm_free: (a: number, b: number) => void;
|
|
5
|
+
export const edgellm_ask_wasm: (a: number, b: number, c: number) => [number, number, number, number];
|
|
6
|
+
export const edgellm_cloud: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
7
|
+
export const edgellm_new_local: (a: number, b: number) => [number, number, number];
|
|
8
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
9
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
10
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
12
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "el-ffi",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Host bindings: uniffi-bindgen-react-native (RN), flutter_rust_bridge v2 (Flutter), wasm-bindgen (web) — ADR-001/009.",
|
|
5
|
+
"version": "0.3.7",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"files": [
|
|
8
|
+
"el_ffi_bg.wasm",
|
|
9
|
+
"el_ffi.js",
|
|
10
|
+
"el_ffi.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"main": "el_ffi.js",
|
|
13
|
+
"types": "el_ffi.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
]
|
|
17
|
+
}
|