@oryksa/react-native 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ * First release.
6
+ * `OryksaClient`: in-app client with short-lived session tokens (agent, send, sendAndWait, messages), refreshes the token when it expires.
7
+ * `OryksaChatButton`, `OryksaChatModal` and `OryksaChat`: ready chat with the look of the ORYKSA website chat, name and photo of the AI from the ORYKSA account, in English, Portuguese (Portugal and Brazil) and Spanish.
8
+ * No native code, works in Expo Go. TypeScript types included.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 W8 Atlantic Unipessoal Lda (ORYKSA AI Employees)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ <p align="center"><img src="https://app.oryksa.com/static/oryksa_logo.png" width="300" alt="ORYKSA"></p>
2
+
3
+ # @oryksa/react-native
4
+
5
+ Official React Native SDK for **ORYKSA AI Employees**. Put an AI employee that already knows your business inside your iOS and Android app (React Native or Expo): a ready chat with the same look as the ORYKSA website chat, the name and photo of your AI from your ORYKSA account, in English, Portuguese (Portugal and Brazil) and Spanish.
6
+
7
+ * Docs: https://developer.oryksa.com/en/sdks
8
+ * API: `https://api.oryksa.com/v1`
9
+ * No native code: works in Expo Go.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @oryksa/react-native
15
+ ```
16
+
17
+ ## How it works (and why the key stays safe)
18
+
19
+ 1. Your **server** keeps the secret API key (`oryk_live_...`, created at developer.oryksa.com) and creates a short-lived **session token** for each signed-in user with `POST /v1/sessions` (with `@oryksa/sdk` on Node: `oryksa.createSession(...)`).
20
+ 2. Your **app** receives only that session token (`oryk_cs_...`). The secret key never goes into the app.
21
+ 3. Every AI reply counts as one interaction of your ORYKSA plan, the same as on WhatsApp.
22
+
23
+ ## In the app
24
+
25
+ ```jsx
26
+ import { OryksaClient, OryksaChatButton } from "@oryksa/react-native";
27
+
28
+ const client = new OryksaClient({
29
+ getToken: async () => (await fetch("https://your-server.example/oryksa-token").then((r) => r.json())).token,
30
+ });
31
+
32
+ export default function App() {
33
+ return (
34
+ <View style={{ flex: 1 }}>
35
+ <MyScreens />
36
+ <OryksaChatButton client={client} lang="en" /> {/* en, pt, br, es */}
37
+ </View>
38
+ );
39
+ }
40
+ ```
41
+
42
+ Other pieces:
43
+
44
+ * `<OryksaChatModal client={client} visible={open} onClose={() => setOpen(false)} />`: open the chat from your own button.
45
+ * `<OryksaChat client={client} />`: the panel inside any screen.
46
+ * `theme={{ accent: "#5B57E0" }}`: colors.
47
+ * Without the UI: `await client.agent()`, `await client.sendAndWait("Are you open on Saturday?")`, `await client.messages()`.
48
+
49
+ ## Keep the AI in sync with your app
50
+
51
+ On your server, with `@oryksa/sdk`:
52
+
53
+ ```js
54
+ await oryksa.learnApp({ name: "FitTrack", description: "...", screens: [...], faq: [...] });
55
+ ```
56
+
57
+ ## Errors
58
+
59
+ Failed calls throw `OryksaError` with `status`, `code` (for example `interaction_limit_reached`, `rate_limited`, `plan_required`) and `message`.
60
+
61
+ ---
62
+
63
+ ## Português (Portugal)
64
+
65
+ SDK oficial de React Native da **ORYKSA AI Employees**: põe na tua app iOS e Android um colaborador de IA que já conhece o teu negócio, com um chat pronto igual ao chat do site da ORYKSA, com o nome e a foto da tua IA.
66
+
67
+ 1. O teu **servidor** guarda a chave secreta e cria um token de sessão para cada utilizador (`POST /v1/sessions`).
68
+ 2. A **app** usa só esse token: `new OryksaClient({ getToken })` e `<OryksaChatButton client={client} lang="pt" />`.
69
+ 3. Cada resposta da IA conta como uma interação do teu plano.
70
+
71
+ ## Português (Brasil)
72
+
73
+ SDK oficial de React Native da **ORYKSA AI Employees**: coloque no seu app iOS e Android um colaborador de IA que já conhece o seu negócio, com um chat pronto igual ao chat do site da ORYKSA, com o nome e a foto da sua IA.
74
+
75
+ 1. Seu **servidor** guarda a chave secreta e cria um token de sessão para cada usuário (`POST /v1/sessions`).
76
+ 2. O **app** usa só esse token: `new OryksaClient({ getToken })` e `<OryksaChatButton client={client} lang="br" />`.
77
+ 3. Cada resposta da IA conta como uma interação do seu plano.
78
+
79
+ ## Español
80
+
81
+ SDK oficial de React Native de **ORYKSA AI Employees**: pon en tu app iOS y Android un empleado de IA que ya conoce tu negocio, con un chat listo igual al chat de la web de ORYKSA, con el nombre y la foto de tu IA.
82
+
83
+ 1. Tu **servidor** guarda la clave secreta y crea un token de sesión para cada usuario (`POST /v1/sessions`).
84
+ 2. La **app** usa solo ese token: `new OryksaClient({ getToken })` y `<OryksaChatButton client={client} lang="es" />`.
85
+ 3. Cada respuesta de la IA cuenta como una interacción de tu plan.
86
+
87
+ ## About the author
88
+
89
+ **Weslley Harakawa** - Founder of ORYKSA AI and Chief Innovation Officer at Harakawa Tech. Based in Lisbon, Portugal. Specialties: artificial intelligence, web and mobile development, blockchain tokenization. Education: University of the People.
90
+
91
+ - Website: https://harakawa.tech
92
+ - LinkedIn: https://www.linkedin.com/in/weslleyharakawa/
93
+ - Instagram: https://www.instagram.com/weslley.harakawa
94
+ - ORYKSA AI Employees: https://oryksa.com (X: https://x.com/oryksa, Instagram: https://www.instagram.com/oryksaai, YouTube: https://www.youtube.com/@ORYKSAAI)
95
+
96
+ ---
97
+
98
+ MIT License · ORYKSA AI Employees · W8 Atlantic Unipessoal Lda
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@oryksa/react-native",
3
+ "version": "1.0.0",
4
+ "description": "Official React Native SDK for ORYKSA AI Employees: a ready in-app AI chat with the look of the ORYKSA website chat, and a client for the ORYKSA API v1.",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "react-native": "src/index.js",
8
+ "files": ["src", "README.md", "LICENSE", "CHANGELOG.md"],
9
+ "sideEffects": false,
10
+ "scripts": { "test": "node test/client.test.js" },
11
+ "peerDependencies": {
12
+ "react": ">=17.0.0",
13
+ "react-native": ">=0.68.0"
14
+ },
15
+ "keywords": ["oryksa", "react-native", "ai", "chatbot", "customer-support", "chat", "sdk", "expo"],
16
+ "homepage": "https://developer.oryksa.com/en/sdks",
17
+ "repository": { "type": "git", "url": "https://github.com/oryksa/oryksa-react-native" },
18
+ "bugs": { "url": "https://github.com/oryksa/oryksa-react-native/issues" },
19
+ "author": "ORYKSA AI Employees (https://oryksa.com)",
20
+ "license": "MIT"
21
+ }
package/src/chat.js ADDED
@@ -0,0 +1,163 @@
1
+ /*!
2
+ * @oryksa/react-native - the ORYKSA chat for React Native, with the look of the
3
+ * ORYKSA website chat (name and photo of the AI come from the ORYKSA account).
4
+ * License: MIT
5
+ */
6
+ "use strict";
7
+
8
+ const React = require("react");
9
+ const RN = require("react-native");
10
+ const { pick } = require("./client");
11
+
12
+ const h = React.createElement;
13
+ const { View, Text, TextInput, Image, Pressable, FlatList, Modal, KeyboardAvoidingView, Platform, StyleSheet, SafeAreaView, useWindowDimensions } = RN;
14
+
15
+ const TX = {
16
+ en: { talk: "Talk to", ph: "Type your question", send: "Send", err: "Sorry, something went wrong. Try again." },
17
+ pt: { talk: "Falar com", ph: "Escreve a tua pergunta", send: "Enviar", err: "Desculpa, algo correu mal. Tenta de novo." },
18
+ br: { talk: "Falar com", ph: "Digite sua pergunta", send: "Enviar", err: "Desculpe, algo deu errado. Tente de novo." },
19
+ es: { talk: "Hablar con", ph: "Escribe tu pregunta", send: "Enviar", err: "Lo siento, algo salió mal. Inténtalo de nuevo." },
20
+ };
21
+ const DEFAULT_THEME = { accent: "#5B57E0", ink: "#161B3D", soft: "#EEEBFB", background: "#FFFFFF", muted: "#6B7280" };
22
+ const FALLBACK_AVATAR = "https://oryksa.com/assets/img/avatar_official_oryksa.png";
23
+ const L = (lang) => (TX[lang] ? lang : "en");
24
+
25
+ /** The chat panel: header with the photo and name of the AI, messages, suggestions and the input. */
26
+ function OryksaChat(props) {
27
+ const { client, lang = "en", theme, onClose } = props;
28
+ const th = Object.assign({}, DEFAULT_THEME, theme || {});
29
+ const tx = TX[L(lang)];
30
+ const [agent, setAgent] = React.useState(null);
31
+ const [msgs, setMsgs] = React.useState([]);
32
+ const [sug, setSug] = React.useState([]);
33
+ const [text, setText] = React.useState("");
34
+ const [busy, setBusy] = React.useState(false);
35
+ const listRef = React.useRef(null);
36
+
37
+ React.useEffect(() => {
38
+ let alive = true;
39
+ (async () => {
40
+ try {
41
+ const a = await client.agent();
42
+ const hist = await client.messages().catch(() => ({ messages: [] }));
43
+ if (!alive) return;
44
+ setAgent(a);
45
+ const past = (hist && hist.messages) || [];
46
+ if (past.length) {
47
+ setMsgs(past.map((m, i) => ({ id: "h" + i, role: m.role === "user" ? "user" : "assistant", text: m.content })));
48
+ } else {
49
+ const g = pick(a.greeting, L(lang));
50
+ if (g) setMsgs([{ id: "g", role: "assistant", text: g }]);
51
+ setSug((pick(a.suggestions, L(lang)) || []).slice(0, 4));
52
+ }
53
+ } catch (_) {
54
+ if (alive) setAgent({ name: "ORYKSA", avatar: FALLBACK_AVATAR });
55
+ }
56
+ })();
57
+ return () => { alive = false; };
58
+ }, [client, lang]);
59
+
60
+ const send = React.useCallback(async (value) => {
61
+ const q = String(value || "").trim();
62
+ if (!q || busy) return;
63
+ setBusy(true); setSug([]); setText("");
64
+ const id = String(Date.now());
65
+ setMsgs((m) => m.concat([{ id: id + "u", role: "user", text: q }, { id: id + "t", role: "typing", text: "..." }]));
66
+ let reply = null;
67
+ try { reply = await client.sendAndWait(q); } catch (_) { reply = null; }
68
+ setMsgs((m) => m.filter((x) => x.role !== "typing").concat([{ id: id + "a", role: "assistant", text: reply || tx.err }]));
69
+ setBusy(false);
70
+ }, [busy, client, tx]);
71
+
72
+ const name = (agent && agent.name) || "";
73
+ const sub = agent ? (pick(agent.subtitle, L(lang)) || agent.business || "") : "";
74
+
75
+ return h(View, { style: [s.panel, { backgroundColor: th.background }] },
76
+ h(View, { style: s.hd },
77
+ h(Image, { source: { uri: (agent && agent.avatar) || FALLBACK_AVATAR }, style: s.hdImg }),
78
+ h(View, { style: { flex: 1 } },
79
+ h(Text, { style: [s.hdName, { color: th.ink }], numberOfLines: 1 }, name.toUpperCase()),
80
+ sub ? h(Text, { style: [s.hdSub, { color: th.muted }], numberOfLines: 1 }, sub) : null),
81
+ onClose ? h(Pressable, { onPress: onClose, accessibilityRole: "button", accessibilityLabel: "close", hitSlop: 10 },
82
+ h(Text, { style: [s.close, { color: th.muted }] }, "×")) : null),
83
+ h(FlatList, {
84
+ ref: listRef,
85
+ data: msgs,
86
+ keyExtractor: (m) => m.id,
87
+ contentContainerStyle: { padding: 16 },
88
+ onContentSizeChange: () => listRef.current && listRef.current.scrollToEnd({ animated: true }),
89
+ renderItem: ({ item }) => {
90
+ const mine = item.role === "user";
91
+ return h(View, { style: [s.bubble, mine ? [s.me, { backgroundColor: th.accent }] : [s.ai, { backgroundColor: th.soft }], item.role === "typing" ? { opacity: 0.6 } : null] },
92
+ h(Text, { selectable: true, style: { color: mine ? "#fff" : th.ink, fontSize: 14, lineHeight: 21 } }, item.text));
93
+ },
94
+ }),
95
+ sug.length ? h(View, { style: s.sug }, sug.map((q) =>
96
+ h(Pressable, { key: q, onPress: () => send(q), style: s.chip }, h(Text, { style: { color: th.accent, fontSize: 12.5 } }, q)))) : null,
97
+ h(View, { style: s.form },
98
+ h(TextInput, {
99
+ value: text, onChangeText: setText, placeholder: tx.ph, placeholderTextColor: "#9CA3AF", maxLength: 2000,
100
+ style: [s.input, { color: th.ink }], returnKeyType: "send", onSubmitEditing: () => send(text),
101
+ }),
102
+ h(Pressable, { onPress: () => send(text), disabled: busy, style: [s.sendBtn, { backgroundColor: th.accent, opacity: busy ? 0.6 : 1 }] },
103
+ h(Text, { style: s.sendTxt }, tx.send.toUpperCase()))),
104
+ h(Text, { style: s.pw }, "POWERED BY ", h(Text, { style: { color: th.accent, fontWeight: "800" } }, "ORYKSA")));
105
+ }
106
+
107
+ /** Full-screen (phone) or floating (tablet) modal with the chat. */
108
+ function OryksaChatModal(props) {
109
+ const { visible, onClose } = props;
110
+ const { width } = useWindowDimensions();
111
+ const wide = width >= 600;
112
+ return h(Modal, { visible: !!visible, animationType: "slide", transparent: wide, onRequestClose: onClose },
113
+ h(KeyboardAvoidingView, { style: wide ? s.wideWrap : { flex: 1 }, behavior: Platform.OS === "ios" ? "padding" : undefined },
114
+ h(SafeAreaView, { style: wide ? s.wideCard : { flex: 1 } }, h(OryksaChat, Object.assign({}, props, { onClose })))));
115
+ }
116
+
117
+ /** Floating "Talk to name" button with the photo of the AI. Opens the chat. */
118
+ function OryksaChatButton(props) {
119
+ const { client, lang = "en", theme, position = "right", style } = props;
120
+ const th = Object.assign({}, DEFAULT_THEME, theme || {});
121
+ const [agent, setAgent] = React.useState(null);
122
+ const [open, setOpen] = React.useState(false);
123
+ React.useEffect(() => {
124
+ let alive = true;
125
+ client.agent().then((a) => { if (alive) setAgent(a); }).catch(() => {});
126
+ return () => { alive = false; };
127
+ }, [client]);
128
+ const tx = TX[L(lang)];
129
+ return h(React.Fragment, null,
130
+ h(Pressable, {
131
+ onPress: () => setOpen(true), accessibilityRole: "button",
132
+ style: [s.fab, position === "left" ? { left: 18 } : { right: 18 }, { backgroundColor: th.accent }, style],
133
+ },
134
+ h(Image, { source: { uri: (agent && agent.avatar) || FALLBACK_AVATAR }, style: s.fabImg }),
135
+ h(Text, { style: s.fabTxt }, (tx.talk + " " + ((agent && agent.name) || "ORYKSA")).toUpperCase())),
136
+ h(OryksaChatModal, { client, lang, theme, visible: open, onClose: () => setOpen(false) }));
137
+ }
138
+
139
+ const s = StyleSheet.create({
140
+ panel: { flex: 1 },
141
+ hd: { flexDirection: "row", alignItems: "center", gap: 12, paddingHorizontal: 16, paddingVertical: 14, borderBottomWidth: 1, borderBottomColor: "#ECEEF6" },
142
+ hdImg: { width: 46, height: 46, borderRadius: 23 },
143
+ hdName: { fontSize: 14, fontWeight: "800", letterSpacing: 2 },
144
+ hdSub: { fontSize: 12 },
145
+ close: { fontSize: 26, paddingHorizontal: 6 },
146
+ bubble: { maxWidth: "82%", paddingHorizontal: 14, paddingVertical: 10, borderRadius: 16, marginBottom: 10 },
147
+ ai: { alignSelf: "flex-start", borderBottomLeftRadius: 6 },
148
+ me: { alignSelf: "flex-end", borderBottomRightRadius: 6 },
149
+ sug: { flexDirection: "row", flexWrap: "wrap", gap: 8, paddingHorizontal: 16, paddingBottom: 10 },
150
+ chip: { borderWidth: 1, borderColor: "#DCDCF5", borderRadius: 999, paddingHorizontal: 12, paddingVertical: 7, backgroundColor: "#fff" },
151
+ form: { flexDirection: "row", borderTopWidth: 1, borderTopColor: "#ECEEF6" },
152
+ input: { flex: 1, paddingHorizontal: 16, paddingVertical: 14, fontSize: 14 },
153
+ sendBtn: { justifyContent: "center", paddingHorizontal: 18 },
154
+ sendTxt: { color: "#fff", fontWeight: "800", letterSpacing: 1.2 },
155
+ pw: { textAlign: "center", fontSize: 10.5, letterSpacing: 1.3, color: "#9CA3AF", paddingTop: 6, paddingBottom: 8 },
156
+ wideWrap: { flex: 1, alignItems: "flex-end", justifyContent: "flex-end", padding: 22, paddingBottom: 92 },
157
+ wideCard: { width: 380, height: 560, borderRadius: 20, overflow: "hidden", backgroundColor: "#fff", elevation: 16, shadowColor: "#161B3D", shadowOpacity: 0.25, shadowRadius: 30, shadowOffset: { width: 0, height: 12 } },
158
+ fab: { position: "absolute", bottom: 22, flexDirection: "row", alignItems: "center", gap: 10, borderRadius: 999, paddingLeft: 8, paddingRight: 18, paddingVertical: 8, elevation: 8, shadowColor: "#161B3D", shadowOpacity: 0.28, shadowRadius: 15, shadowOffset: { width: 0, height: 6 } },
159
+ fabImg: { width: 42, height: 42, borderRadius: 21, borderWidth: 2, borderColor: "#fff" },
160
+ fabTxt: { color: "#fff", fontWeight: "800", fontSize: 13, letterSpacing: 1 },
161
+ });
162
+
163
+ module.exports = { OryksaChat, OryksaChatModal, OryksaChatButton, DEFAULT_THEME };
package/src/client.js ADDED
@@ -0,0 +1,114 @@
1
+ /*!
2
+ * @oryksa/react-native - in-app client. Uses a short-lived session token (oryk_cs_...)
3
+ * created by YOUR server with POST /v1/sessions. The secret API key never goes into the app.
4
+ * Docs: https://developer.oryksa.com License: MIT
5
+ */
6
+ "use strict";
7
+
8
+ const DEFAULT_BASE = "https://api.oryksa.com/v1";
9
+ const VERSION = "1.0.0";
10
+
11
+ class OryksaError extends Error {
12
+ constructor(status, code, message, extra) {
13
+ super(message);
14
+ this.name = "OryksaError";
15
+ this.status = status;
16
+ this.code = code;
17
+ Object.assign(this, extra || {});
18
+ }
19
+ }
20
+
21
+ async function request(base, token, method, path, body, fetchImpl, timeoutMs) {
22
+ const f = fetchImpl || globalThis.fetch;
23
+ const ctrl = typeof AbortController !== "undefined" ? new AbortController() : null;
24
+ const timer = ctrl ? setTimeout(() => ctrl.abort(), timeoutMs) : null;
25
+ let res;
26
+ try {
27
+ res = await f(base + path, {
28
+ method,
29
+ headers: Object.assign(
30
+ { Authorization: "Bearer " + token, Accept: "application/json", "X-ORYKSA-SDK": "react-native/" + VERSION },
31
+ body !== undefined ? { "Content-Type": "application/json" } : {}
32
+ ),
33
+ body: body !== undefined ? JSON.stringify(body) : undefined,
34
+ signal: ctrl ? ctrl.signal : undefined,
35
+ });
36
+ } catch (e) {
37
+ throw new OryksaError(0, "network_error", "Could not reach ORYKSA: " + (e && e.message));
38
+ } finally {
39
+ if (timer) clearTimeout(timer);
40
+ }
41
+ let data = null;
42
+ try { data = await res.json(); } catch (_) { data = null; }
43
+ if (!res.ok && res.status !== 202) {
44
+ const e = (data && data.error) || {};
45
+ const extra = Object.assign({}, e);
46
+ delete extra.code; delete extra.message;
47
+ throw new OryksaError(res.status, e.code || "http_" + res.status, e.message || "Request failed with HTTP " + res.status, extra);
48
+ }
49
+ return data || {};
50
+ }
51
+
52
+ class OryksaClient {
53
+ /**
54
+ * @param {{token?: string, getToken?: () => Promise<string>, baseUrl?: string, fetch?: Function, timeoutMs?: number}} opts
55
+ */
56
+ constructor(opts) {
57
+ const o = opts || {};
58
+ if (!o.token && !o.getToken) throw new Error("OryksaClient needs { token } or { getToken }.");
59
+ if (o.token && String(o.token).startsWith("oryk_live_")) throw new Error("Never use the secret API key in an app. Use a session token (oryk_cs_...).");
60
+ this._token = o.token || null;
61
+ this._getToken = o.getToken || null;
62
+ this._base = String(o.baseUrl || DEFAULT_BASE).replace(/\/$/, "");
63
+ this._fetch = o.fetch;
64
+ this._timeout = o.timeoutMs || 60000;
65
+ }
66
+
67
+ async _tok(force) {
68
+ if ((!this._token || force) && this._getToken) this._token = await this._getToken();
69
+ if (!this._token) throw new OryksaError(401, "no_token", "No session token.");
70
+ return this._token;
71
+ }
72
+
73
+ async _req(method, path, body) {
74
+ try {
75
+ return await request(this._base, await this._tok(false), method, path, body, this._fetch, this._timeout);
76
+ } catch (e) {
77
+ if (e instanceof OryksaError && (e.code === "session_expired" || e.status === 401) && this._getToken) {
78
+ return request(this._base, await this._tok(true), method, path, body, this._fetch, this._timeout);
79
+ }
80
+ throw e;
81
+ }
82
+ }
83
+
84
+ /** Name, photo, greeting and suggestions of the AI employee. */
85
+ agent() { return this._req("GET", "/client/agent"); }
86
+
87
+ /** Sends a message. status is "pending" when the AI needs a few more seconds: use sendAndWait. */
88
+ send(message) { return this._req("POST", "/client/chat", { message }); }
89
+
90
+ /** Messages of this conversation: { messages: [{ role, content }] }. */
91
+ messages() { return this._req("GET", "/client/messages"); }
92
+
93
+ /** Sends a message and waits for the reply text. */
94
+ async sendAndWait(message, maxWaitMs) {
95
+ const r = await this.send(message);
96
+ if (!r || r.status !== "pending") return (r && r.reply) || null;
97
+ const end = Date.now() + (maxWaitMs || 40000);
98
+ while (Date.now() < end) {
99
+ await new Promise((ok) => setTimeout(ok, 1500));
100
+ const h = await this.messages();
101
+ const last = ((h && h.messages) || []).slice(-1)[0];
102
+ if (last && last.role === "assistant") return last.content;
103
+ }
104
+ return null;
105
+ }
106
+ }
107
+
108
+ /** Picks the text for a language with fallbacks (br uses pt, then en). */
109
+ function pick(map, lang) {
110
+ if (!map || typeof map !== "object") return undefined;
111
+ return map[lang] || (lang === "br" ? map.pt : undefined) || map.en || Object.values(map)[0];
112
+ }
113
+
114
+ module.exports = { OryksaClient, OryksaError, pick, VERSION, DEFAULT_BASE };
package/src/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ import * as React from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+
4
+ export declare const VERSION: string;
5
+
6
+ export declare class OryksaError extends Error {
7
+ status: number;
8
+ code: string;
9
+ [key: string]: unknown;
10
+ }
11
+
12
+ export interface OryksaAgent {
13
+ name: string;
14
+ avatar: string;
15
+ business?: string | null;
16
+ gender?: "female" | "male";
17
+ greeting?: Record<string, string>;
18
+ subtitle?: Record<string, string>;
19
+ suggestions?: Record<string, string[]>;
20
+ voice_replies?: boolean;
21
+ conversation_id?: string;
22
+ }
23
+
24
+ export interface OryksaReply {
25
+ object: "chat_reply";
26
+ conversation_id: string;
27
+ status: "replied" | "pending";
28
+ reply: string | null;
29
+ }
30
+
31
+ export declare class OryksaClient {
32
+ constructor(opts: { token?: string; getToken?: () => Promise<string>; baseUrl?: string; fetch?: typeof fetch; timeoutMs?: number });
33
+ agent(): Promise<OryksaAgent>;
34
+ send(message: string): Promise<OryksaReply>;
35
+ sendAndWait(message: string, maxWaitMs?: number): Promise<string | null>;
36
+ messages(): Promise<{ messages: { role: "user" | "assistant"; content: string }[] }>;
37
+ }
38
+
39
+ export type OryksaLang = "en" | "pt" | "br" | "es";
40
+
41
+ export interface OryksaTheme {
42
+ accent?: string;
43
+ ink?: string;
44
+ soft?: string;
45
+ background?: string;
46
+ muted?: string;
47
+ }
48
+
49
+ export declare const DEFAULT_THEME: Required<OryksaTheme>;
50
+
51
+ export declare function OryksaChat(props: { client: OryksaClient; lang?: OryksaLang; theme?: OryksaTheme; onClose?: () => void }): React.ReactElement;
52
+ export declare function OryksaChatModal(props: { client: OryksaClient; lang?: OryksaLang; theme?: OryksaTheme; visible: boolean; onClose: () => void }): React.ReactElement;
53
+ export declare function OryksaChatButton(props: { client: OryksaClient; lang?: OryksaLang; theme?: OryksaTheme; position?: "left" | "right"; style?: StyleProp<ViewStyle> }): React.ReactElement;
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * @oryksa/react-native - Official React Native SDK for ORYKSA AI Employees.
3
+ * Docs: https://developer.oryksa.com License: MIT
4
+ */
5
+ "use strict";
6
+
7
+ const client = require("./client");
8
+ const chat = require("./chat");
9
+
10
+ module.exports = {
11
+ OryksaClient: client.OryksaClient,
12
+ OryksaError: client.OryksaError,
13
+ VERSION: client.VERSION,
14
+ OryksaChat: chat.OryksaChat,
15
+ OryksaChatModal: chat.OryksaChatModal,
16
+ OryksaChatButton: chat.OryksaChatButton,
17
+ DEFAULT_THEME: chat.DEFAULT_THEME,
18
+ };