@rnet-ai/rnet-caller
v1.0.2
Published
Frontend library for the rNet Protocol — forwards requests through the local rNet Client so AI calls use the user's token, not the developer's.
Maintainers
Readme
@rnet-ai/rnet-caller
Official Website: rnetai.org GitHub: rNetAi
A browser-only JavaScript library for the rNet Protocol.
Connects a developer's frontend to a locally-installed rNet Client, which attaches an AI pass using the end user's token before forwarding requests to the developer's backend. Developers do not pay upfront AI token costs.
This library does not call any AI model directly. It only communicates with the local rNet Client over
localhost.
Flow
Developer's Frontend → Local rNet Client → Developer's Backend
Installation
npm install @rnet-ai/rnet-callerQuick Start
import rnetCaller from "@rnet-ai/rnet-caller";
// 1. Initialize to find the local rNet Client
await rnetCaller.init();
// 2. Send a request through the local client to the developer backend
const response = await rnetCaller.send({
url: "https://<develoepr backend path>/please-dont-break",
method: "POST",
headers: {"Authorization:" , "Bearer eyJhbGciOiJ.....IUzVT7Ib5"}
body: JSON.stringify({
username: "rNet Ai",
password: "KSKE9cC9MIR3QSq8OAk59FklDBM4Cg1K9MTfYYiP1wXjFczTbFTWYlz1ePAg2oCw",
command: "delete everything",
}),
});
if(!response.ok) {
throw new Error(`from rNet Client error: ${response.status}`);
}
const data = await response.json();
console.log(data);
// 3. (Optional) Clear cache during development
await rnetCaller.clearCache();API Reference
await rnetCaller.init()
Scans for the local rNet Client on localhost and checks its version. Alerts the user and redirects to the download page if the client is missing or outdated. Returns true if successful. Safe to call multiple times.
await rnetCaller.send(descriptor, options?)
Sends a request through the local rNet Client to the target backend. The client automatically attaches an AI pass before forwarding.
Important: Only use the
send()function for endpoints where the backend requires an AI pass. For all other regular API calls, use standardfetch()directly.
Descriptor fields:
url(string, required): The target backend URL.method(string, required): The HTTP method (e.g.,POST).headers(object, optional): Custom headers.Content-Typeis always enforced asapplication/json.query(object, optional): Query parameters.body(string, optional): Request body (JSON string).
Options:
debug(boolean, optional): Set totrueto log the payload to the console.
Returns: The parsed JSON response from the backend.
await rnetCaller.clearCache()
Clears the cached responses in the local rNet Client, including the URL mapping with the AI model. This is a developer utility to skip cache timeouts so any changes to the AI model take effect immediately during development.
Error Handling
Errors are thrown as RNetError instances with a code property.
import rnetCaller, { RNetError } from "@rnet-ai/rnet-caller";
try {
const response = await rnetCaller.send({ url: "https://<developer backend>/api/v1/data", method: "GET" });
if (!response.ok) {
throw new Error(`From rNet Client error: ${response.status}`);
}
const data = await response.json();
return data;
} catch (err) {
if (err instanceof RNetError) {
console.error(`Error code: ${err.code}`, err.message);
}
}