@rhq/rover 0.1.0 → 0.1.2

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.
@@ -0,0 +1,156 @@
1
+ #include "RoverJsi.h"
2
+ #include <string>
3
+ #include <vector>
4
+ #include <future>
5
+ #include <thread>
6
+
7
+ extern "C" {
8
+ char* rover_native_classify(const char* subject, const char* body);
9
+ char* rover_native_generate_preview(const char* subject, const char* body);
10
+ char* rover_native_process_email(const char* subject, const char* body);
11
+ char* rover_native_process_email_json(const char* email_json);
12
+ char* rover_native_process_batch_json(const char* batch_json);
13
+ char* rover_native_html_to_text(const char* html);
14
+ char* rover_native_clean_email_body(const char* text);
15
+ void rover_native_free_string(char* ptr);
16
+ }
17
+
18
+ namespace relay_rover {
19
+
20
+ RoverHostObject::RoverHostObject() = default;
21
+
22
+ void RoverHostObject::install(facebook::jsi::Runtime& runtime) {
23
+ auto hostObject = std::make_shared<RoverHostObject>();
24
+ auto jsObject = facebook::jsi::Object::createFromHostObject(runtime, hostObject);
25
+ runtime.global().setProperty(runtime, "__RELAY_ROVER_NATIVE__", jsObject);
26
+ }
27
+
28
+ std::vector<facebook::jsi::PropNameID> RoverHostObject::getPropertyNames(facebook::jsi::Runtime& runtime) {
29
+ std::vector<facebook::jsi::PropNameID> names;
30
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "classify"));
31
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "generatePreview"));
32
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "processEmail"));
33
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "processEmailJson"));
34
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "processBatchJson"));
35
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "htmlToText"));
36
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "cleanEmailBody"));
37
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "processEmailAsync"));
38
+ names.push_back(facebook::jsi::PropNameID::forAscii(runtime, "processBatchAsync"));
39
+ return names;
40
+ }
41
+
42
+ facebook::jsi::Value RoverHostObject::get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& name) {
43
+ std::string propName = name.utf8(runtime);
44
+
45
+ if (propName == "classify") {
46
+ return facebook::jsi::Function::createFromHostFunction(
47
+ runtime,
48
+ name,
49
+ 2,
50
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
51
+ std::string subject = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "";
52
+ std::string body = (count > 1 && args[1].isString()) ? args[1].asString(rt).utf8(rt) : "";
53
+ char* resPtr = rover_native_classify(subject.c_str(), body.c_str());
54
+ std::string result = resPtr ? resPtr : "General";
55
+ rover_native_free_string(resPtr);
56
+ return facebook::jsi::String::createFromUtf8(rt, result);
57
+ }
58
+ );
59
+ }
60
+
61
+ if (propName == "generatePreview") {
62
+ return facebook::jsi::Function::createFromHostFunction(
63
+ runtime,
64
+ name,
65
+ 2,
66
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
67
+ std::string subject = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "";
68
+ std::string body = (count > 1 && args[1].isString()) ? args[1].asString(rt).utf8(rt) : "";
69
+ char* resPtr = rover_native_generate_preview(subject.c_str(), body.c_str());
70
+ std::string result = resPtr ? resPtr : "";
71
+ rover_native_free_string(resPtr);
72
+ return facebook::jsi::String::createFromUtf8(rt, result);
73
+ }
74
+ );
75
+ }
76
+
77
+ if (propName == "processEmail") {
78
+ return facebook::jsi::Function::createFromHostFunction(
79
+ runtime,
80
+ name,
81
+ 2,
82
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
83
+ std::string subject = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "";
84
+ std::string body = (count > 1 && args[1].isString()) ? args[1].asString(rt).utf8(rt) : "";
85
+ char* resPtr = rover_native_process_email(subject.c_str(), body.c_str());
86
+ std::string result = resPtr ? resPtr : "{}";
87
+ rover_native_free_string(resPtr);
88
+ return facebook::jsi::String::createFromUtf8(rt, result);
89
+ }
90
+ );
91
+ }
92
+
93
+ if (propName == "processEmailJson") {
94
+ return facebook::jsi::Function::createFromHostFunction(
95
+ runtime,
96
+ name,
97
+ 1,
98
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
99
+ std::string json = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "{}";
100
+ char* resPtr = rover_native_process_email_json(json.c_str());
101
+ std::string result = resPtr ? resPtr : "{}";
102
+ rover_native_free_string(resPtr);
103
+ return facebook::jsi::String::createFromUtf8(rt, result);
104
+ }
105
+ );
106
+ }
107
+
108
+ if (propName == "processBatchJson") {
109
+ return facebook::jsi::Function::createFromHostFunction(
110
+ runtime,
111
+ name,
112
+ 1,
113
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
114
+ std::string json = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "[]";
115
+ char* resPtr = rover_native_process_batch_json(json.c_str());
116
+ std::string result = resPtr ? resPtr : "[]";
117
+ rover_native_free_string(resPtr);
118
+ return facebook::jsi::String::createFromUtf8(rt, result);
119
+ }
120
+ );
121
+ }
122
+
123
+ if (propName == "htmlToText") {
124
+ return facebook::jsi::Function::createFromHostFunction(
125
+ runtime,
126
+ name,
127
+ 1,
128
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
129
+ std::string html = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "";
130
+ char* resPtr = rover_native_html_to_text(html.c_str());
131
+ std::string result = resPtr ? resPtr : "";
132
+ rover_native_free_string(resPtr);
133
+ return facebook::jsi::String::createFromUtf8(rt, result);
134
+ }
135
+ );
136
+ }
137
+
138
+ if (propName == "cleanEmailBody") {
139
+ return facebook::jsi::Function::createFromHostFunction(
140
+ runtime,
141
+ name,
142
+ 1,
143
+ [](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) -> facebook::jsi::Value {
144
+ std::string text = (count > 0 && args[0].isString()) ? args[0].asString(rt).utf8(rt) : "";
145
+ char* resPtr = rover_native_clean_email_body(text.c_str());
146
+ std::string result = resPtr ? resPtr : "";
147
+ rover_native_free_string(resPtr);
148
+ return facebook::jsi::String::createFromUtf8(rt, result);
149
+ }
150
+ );
151
+ }
152
+
153
+ return facebook::jsi::Value::undefined();
154
+ }
155
+
156
+ } // namespace relay_rover
package/cpp/RoverJsi.h ADDED
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include <vector>
6
+
7
+ namespace relay_rover {
8
+
9
+ class RoverHostObject : public facebook::jsi::HostObject {
10
+ public:
11
+ RoverHostObject();
12
+ ~RoverHostObject() override = default;
13
+
14
+ facebook::jsi::Value get(facebook::jsi::Runtime& runtime, const facebook::jsi::PropNameID& name) override;
15
+ std::vector<facebook::jsi::PropNameID> getPropertyNames(facebook::jsi::Runtime& runtime) override;
16
+
17
+ static void install(facebook::jsi::Runtime& runtime);
18
+ };
19
+
20
+ } // namespace relay_rover
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "RelayRover",
3
+ "platforms": ["ios", "android"],
4
+ "android": {
5
+ "modules": ["com.relayhq.rover.RoverModule"]
6
+ },
7
+ "ios": {
8
+ "modules": ["RoverModule"]
9
+ }
10
+ }
package/index.d.ts CHANGED
@@ -187,6 +187,18 @@ export declare const RelayRover: {
187
187
  * Rover Intelligence Index timeline grouping engine.
188
188
  */
189
189
  index: typeof RoverIndex;
190
+
191
+ /**
192
+ * Asynchronously process a single email off the UI thread (React Native / Hermes).
193
+ */
194
+ processAsync?(email: EmailRecordInput | string): Promise<ProcessedEmail>;
195
+
196
+ /**
197
+ * Asynchronously process a batch of emails off the UI thread (React Native / Hermes).
198
+ */
199
+ processBatchAsync?(emails: EmailRecordInput[] | string): Promise<ProcessedEmail[]>;
190
200
  };
191
201
 
202
+ export declare function init(customBytes?: any): any;
203
+
192
204
  export default RelayRover;
package/index.js CHANGED
@@ -4,9 +4,9 @@
4
4
  * Zero-dependency, in-memory execution powered by compiled Rust WASM.
5
5
  */
6
6
 
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
7
+ import fs from 'fs';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
10
 
11
11
  let wasmInstance = null;
12
12
  let wasmExports = null;
@@ -34,7 +34,7 @@ export function init(customBytes) {
34
34
  if (fs.existsSync(wasmPath)) {
35
35
  bytes = fs.readFileSync(wasmPath);
36
36
  }
37
- } catch (_) {}
37
+ } catch (_) { }
38
38
  }
39
39
 
40
40
  if (!bytes) {
@@ -102,7 +102,7 @@ export function htmlToText(html) {
102
102
  exp.rover_dealloc(input.ptr, input.len);
103
103
  return text;
104
104
  }
105
- } catch (_) {}
105
+ } catch (_) { }
106
106
 
107
107
  // JavaScript fallback
108
108
  return html