@rhq/rover 0.0.0-stage → 0.1.1

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
Binary file
@@ -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 ADDED
@@ -0,0 +1,204 @@
1
+ export type Category =
2
+ | 'Payment'
3
+ | 'Otp'
4
+ | 'Job'
5
+ | 'Shopping'
6
+ | 'Invoice'
7
+ | 'Subscription'
8
+ | 'Travel'
9
+ | 'Newsletter'
10
+ | 'Social'
11
+ | 'SecurityAlert'
12
+ | 'General';
13
+
14
+ export type GeneralCategory =
15
+ | 'primary'
16
+ | 'social'
17
+ | 'promotions'
18
+ | 'updates'
19
+ | 'forums'
20
+ | 'spam';
21
+
22
+ export type Importance = 'urgent' | 'high' | 'normal' | 'low';
23
+
24
+ export type SecurityClassification =
25
+ | 'authentication'
26
+ | 'password_reset'
27
+ | 'security_alert'
28
+ | 'account_change'
29
+ | 'build_failure'
30
+ | 'action_required'
31
+ | 'none';
32
+
33
+ export interface ConfidenceFactors {
34
+ authenticated_sender: boolean;
35
+ has_structured_entities: boolean;
36
+ pattern_specificity: string;
37
+ subject_body_aligned: boolean;
38
+ }
39
+
40
+ export interface EmailClassification {
41
+ general_category: GeneralCategory;
42
+ purpose: Category;
43
+ importance: Importance;
44
+ is_alert: boolean;
45
+ security: SecurityClassification;
46
+ confidence: number;
47
+ factors: ConfidenceFactors;
48
+ secondary_purposes: Category[];
49
+ }
50
+
51
+ export interface ProcessedEmail<T = any> {
52
+ id: string;
53
+ primary_category: string;
54
+ matched_categories: string[];
55
+ classification?: EmailClassification;
56
+ extraction: {
57
+ category: string;
58
+ data: T;
59
+ };
60
+ preview: string;
61
+ timeline_key?: string;
62
+ cleanBody?: string;
63
+ sender?: string;
64
+ senderName?: string;
65
+ }
66
+
67
+ export interface EmailTimelineGroup {
68
+ timelineKey: string;
69
+ primaryCategory: string;
70
+ events: ProcessedEmail[];
71
+ }
72
+
73
+ export interface TimelineBuildResult {
74
+ timelines: Record<string, EmailTimelineGroup>;
75
+ unlinked: ProcessedEmail[];
76
+ }
77
+
78
+ export declare const RoverIndex: {
79
+ buildTimelines(processedEmails: ProcessedEmail[]): TimelineBuildResult;
80
+ };
81
+
82
+ export interface EmailRecordInput {
83
+ id?: string;
84
+ sender?: string;
85
+ sender_name?: string;
86
+ from?: any;
87
+ subject?: string;
88
+ body?: string;
89
+ textBody?: string;
90
+ htmlBody?: string;
91
+ content?: string;
92
+ date?: string;
93
+ received_at?: string;
94
+ headers?: any;
95
+ }
96
+
97
+ export interface NormalizedEmail {
98
+ id: string;
99
+ sender: string;
100
+ senderName: string;
101
+ subject: string;
102
+ body: string;
103
+ receivedAt: string;
104
+ isHtml: boolean;
105
+ }
106
+
107
+ /**
108
+ * Convert HTML email content to clean, readable plain text.
109
+ * Strips scripts, styles, HTML tags, unescapes entities, and normalizes whitespace.
110
+ */
111
+ export declare function htmlToText(html: string): string;
112
+
113
+ /**
114
+ * Extract clean, readable normal message text from an email object or text string.
115
+ * Handles massive HTML emails, raw multipart text bodies, and synthetic email formats.
116
+ */
117
+ export declare function cleanEmailBody(email: EmailRecordInput | string): string;
118
+
119
+ /**
120
+ * Normalize an email of any format into a standardized structured object.
121
+ */
122
+ export declare function normalizeEmail(email: EmailRecordInput): NormalizedEmail;
123
+
124
+ /**
125
+ * Generate a concise snippet/summary from an email body for inbox listings.
126
+ */
127
+ export declare function extractSummary(email: EmailRecordInput | string, maxLength?: number): string;
128
+
129
+ export declare const RelayRover: {
130
+ /**
131
+ * Explicitly initialize the WebAssembly engine with custom bytes (optional).
132
+ */
133
+ init(customBytes?: ArrayBuffer | Uint8Array): any;
134
+
135
+ /**
136
+ * Fast category detection for any arbitrary email subject and body.
137
+ */
138
+ classify(subject: string, body: string): string;
139
+
140
+ /**
141
+ * Generate concise contextual preview line (< 100 characters).
142
+ */
143
+ generatePreview(subject: string, body: string): string;
144
+
145
+ /**
146
+ * Process email with full category detection, typed extraction, and preview generation.
147
+ */
148
+ processEmail(subject: string, body: string): ProcessedEmail;
149
+
150
+ /**
151
+ * Process a single email record object or string (auto-handles HTML and extracts cleanBody).
152
+ */
153
+ process(email: EmailRecordInput | string): ProcessedEmail;
154
+
155
+ /**
156
+ * Process multiple emails in a SINGLE in-memory WebAssembly call.
157
+ * Accepts an array of email objects (including raw Relay Mail with htmlBody) or a serialized JSON string.
158
+ */
159
+ processBatch(emails: EmailRecordInput[] | string): ProcessedEmail[];
160
+
161
+ /**
162
+ * Alias for processBatch to process an array of JSON email records.
163
+ */
164
+ processEmailsJson(emails: EmailRecordInput[] | string): ProcessedEmail[];
165
+
166
+ /**
167
+ * Convert HTML email content to clean, readable plain text.
168
+ */
169
+ htmlToText(html: string): string;
170
+
171
+ /**
172
+ * Extract clean, readable normal message text from an email object or text.
173
+ */
174
+ cleanEmailBody(email: EmailRecordInput | string): string;
175
+
176
+ /**
177
+ * Normalize an email of any format into a standardized structured object.
178
+ */
179
+ normalizeEmail(email: EmailRecordInput): NormalizedEmail;
180
+
181
+ /**
182
+ * Generate a concise summary snippet from an email body.
183
+ */
184
+ extractSummary(email: EmailRecordInput | string, maxLength?: number): string;
185
+
186
+ /**
187
+ * Rover Intelligence Index timeline grouping engine.
188
+ */
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[]>;
200
+ };
201
+
202
+ export declare function init(customBytes?: any): any;
203
+
204
+ export default RelayRover;