Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

blueragesoftware/mini-apps-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

mini-apps-runtime

A JavaScript library for seamlessly integrating MiniApps with the Bluerage client platform.

License: MIT

Quick Start

Add the script to your HTML file's <head> section before any other scripts:

<script src="https://blueragesoftware.github.io/mini-apps-runtime/script.js"></script>

API Reference

The library provides two main interfaces: Bluerage.WebApp and Bluerage.WebView

Chat Completions

Send messages and receive responses:

// Send a message
Bluerage.WebApp.chatCompletions({
  role: 'user',
  message: 'Hello, how are you?'
});

// Listen for responses
Bluerage.WebView.onEvent('chat_completions_response', (eventType, eventData) => {
  if (eventData.error) {
    console.error('Error:', eventData.error);
    return;
  }
  console.log('Response:', eventData.response);
});

React Hook Example

Here's how to use the API with React:

import { useEffect, useState } from 'react';

export const useBluerage = () => {
  const [responses, setResponses] = useState<string[]>([]);
  const [isLoading, setIsLoading] = useState(false);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    if (!window.Bluerage?.WebView) {
      setError('Bluerage WebView is not initialized');
      return;
    }

    window.Bluerage.WebView.onEvent('chat_completions_response', (eventType, eventData) => {
      setIsLoading(false);
      if (eventData.error) {
        setError(eventData.error);
        return;
      }
      if (eventData.response) {
        setResponses(prev => [...prev, eventData.response]);
      }
    });
  }, []);

  const sendMessage = async (message: string, role: string = 'user') => {
    if (!window.Bluerage?.WebApp) {
      setError('Bluerage WebApp is not initialized');
      return;
    }

    setIsLoading(true);
    try {
      window.Bluerage.WebApp.chatCompletions({ role, message });
    } catch (error) {
      setError('Error sending message');
      setIsLoading(false);
    }
  };

  return { 
    sendMessage, 
    responses,
    latestResponse: responses[responses.length - 1] || '', 
    isLoading, 
    error 
  };
};

TypeScript Support

Add these type definitions to your project:

declare global {
  interface Window {
    Bluerage: {
      WebApp: {
        chatCompletions: (params: { role: string; message: string }) => void;
      };
      WebView: {
        onEvent: (event: string, callback: (eventType: string, eventData: any) => void) => void;
      };
    };
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Security

Found a security issue? Please report it privately to security@bluerage.software


Made with ❤️ by Bluerage Software Team

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published