Simple TypeScript wrapper for the Rivalz SDK with file size validation and type safety.
- Install dependencies:
npm install rivalz-client dotenv
- Create a
.env
file:
RIVALZ_SECRET_TOKEN=your_secret_token_here
import { RivalzClientSdk } from "./RivalzClient";
import * as dotenv from "dotenv";
dotenv.config();
async function example() {
const client = new RivalzClientSdk(process.env.RIVALZ_SECRET_TOKEN);
// Upload a file
const result = await client.uploadFile("path/to/file.pdf", "document.pdf");
console.log(result.ipfs_hash);
// Create a knowledge base
const kb = await client.createRagKnowledgeBase("path/to/doc.pdf", "My KB");
// Chat with the knowledge base
const response = await client.createChatSession(kb.id, "What is this about?");
console.log(response);
}
example().catch(console.error);
uploadFile(filePath: string, fileName: string): Promise<{ ipfs_hash: string }>
uploadPassport(passportPath: string, fileName: string): Promise<{ ipfs_hash: string }>
downloadFile(ipfsHash: string, saveDirectory: string): Promise<string>
download(ipfsHash: string): Promise<string>
deleteFile(ipfsHash: string): Promise<string>
createRagKnowledgeBase(documentPath: string, knowledgeBaseName: string): Promise<KnowledgeBase>
addDocumentToKnowledgeBase(documentPath: string, knowledgeBaseId: string): Promise<Document>
deleteDocumentFromKnowledgeBase(documentId: string, knowledgeBaseId: string): Promise<string>
getKnowledgeBases(): Promise<KnowledgeBase[]>
getKnowledgeBase(knowledgeBaseId: string): Promise<KnowledgeBase>
createChatSession(knowledgeBaseId: string, message: string, chatSessionId?: string): Promise<ChatResponse>
getChatSessions(): Promise<ChatSession[]>
getChatSession(chatSessionId: string): Promise<ChatSession>
getUploadedDocuments(): Promise<Document[]>
getUploadedHistory(page: number, pageSize: number): Promise<{ totalFilesUploaded: number; uploadHistories: UploadHistory[] }>
- TypeScript support
- File size validation (10MB limit)
- Async/await support
- Error handling
- Environment variable configuration
try {
await client.uploadFile("large-file.pdf", "large.pdf");
} catch (error) {
if (error instanceof Error) {
console.error("Upload failed:", error.message); // File size or SDK error
}
}