solomdev-chatbot
Version:
Tigerbase Chatbot Client for Product Management
41 lines (40 loc) • 1.49 kB
JavaScript
let config = null;
let validatedData = null;
export const tigerbaseConfig = async (options) => {
config = options;
// Validate serial and tools via backend API
try {
const response = await fetch(`${options.apiURL.replace("/mcp", "")}/validate-serial`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
serialNum: options.serialNum,
enabledTools: options.enabledTools || [], // Send user-specified tools
}),
});
if (!response.ok) {
throw new Error("Invalid serial or tools");
}
const data = await response.json();
if (Date.now() > data.expiration) {
throw new Error("Serial expired");
}
if (data.errors && data.errors.length > 0) {
throw new Error(`Tool validation errors: ${data.errors.join(", ")}`);
}
validatedData = {
tools: data.tools, // Only valid tools from backend
expiration: data.expiration,
errors: data.errors || [],
};
console.log("Validated tools:", validatedData.tools);
}
catch (error) {
throw new Error(`Validation failed: ${error.message}`);
}
};
export const getConfig = () => {
if (!config || !validatedData)
throw new Error("Tigerbase not configured or validated");
return { ...config, validatedTools: validatedData.tools };
};