generated from ztimson/template
Home screen update
All checks were successful
Build and publish / Build Container (push) Successful in 1m28s
All checks were successful
Build and publish / Build Container (push) Successful in 1m28s
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
class Navi {
|
||||
api;
|
||||
connected = false;
|
||||
avatar;
|
||||
icon;
|
||||
info;
|
||||
theme;
|
||||
world;
|
||||
|
||||
#animations;
|
||||
#init;
|
||||
#listeners = new Map();
|
||||
#socket;
|
||||
@@ -14,10 +16,24 @@ class Navi {
|
||||
|
||||
constructor(api = window.location.origin, secret = '') {
|
||||
this.api = api.replace(/\/$/, '');
|
||||
this.icon = `${this.api}/favicon.png`;
|
||||
this.avatar = `${this.api}/avatar`;
|
||||
this.icon = `${this.api}/favicon`;
|
||||
this.#secret = secret;
|
||||
}
|
||||
|
||||
async animations() {
|
||||
if(this.#animations) return this.#animations;
|
||||
await this.init();
|
||||
this.#animations = await fetch(`${this.api}/api/animations`, {
|
||||
headers: this.#secret ? {'Authorization': `Bearer ${this.#secret}`} : {}
|
||||
}).then(resp => {
|
||||
if(!resp.ok) throw new Error(`Invalid Navi API: ${this.api}`);
|
||||
return resp.json();
|
||||
});
|
||||
this.emit('animations', this.#animations);
|
||||
return this.#animations;
|
||||
}
|
||||
|
||||
async init() {
|
||||
if(this.#init) return this.#init;
|
||||
this.#init = new Promise(async (res, rej) => {
|
||||
@@ -229,7 +245,11 @@ class Navi {
|
||||
// ============================================
|
||||
|
||||
ask(message, stream) {
|
||||
this.llmCallback = stream;
|
||||
this.llmCallback = (chunk) => {
|
||||
if(chunk['emote']) this.emit('emote', chunk['emote']);
|
||||
stream(chunk);
|
||||
};
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.llmResolve = resolve;
|
||||
this.llmReject = reject;
|
||||
@@ -260,7 +280,7 @@ class Navi {
|
||||
|
||||
disconnect() {
|
||||
this.connected = false;
|
||||
this.icon = this.info = this.theme = this.world = this.#init = this.#secret = null;
|
||||
this.avatar = this.icon = this.info = this.theme = this.world = this.#animations = this.#init = this.#secret = null;
|
||||
if(this.#world) {
|
||||
this.#world.disconnect();
|
||||
this.#world = null;
|
||||
|
||||
Reference in New Issue
Block a user