vectorvault
Advanced tools
Comparing version 1.3.6 to 1.3.7
@@ -1,483 +0,2 @@ | ||
var VectorVault = (() => { | ||
// index.js | ||
var VectorVault = class { | ||
constructor(embeddingsModel = null) { | ||
this.embeddingsModel = embeddingsModel; | ||
this.accessToken = null; | ||
this.refreshToken = null; | ||
this.tokenExpiresAt = null; | ||
this.baseUrl = "https://api.vectorvault.io"; | ||
} | ||
// Method to log in the user and obtain JWT tokens | ||
async login(email, password) { | ||
const url = `${this.baseUrl}/login`; | ||
const data = { | ||
email, | ||
password | ||
}; | ||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
if (response.ok) { | ||
const json = await response.json(); | ||
this.accessToken = json.access_token; | ||
this.refreshToken = json.refresh_token; | ||
const payload = JSON.parse(atob(this.accessToken.split(".")[1])); | ||
this.tokenExpiresAt = payload.exp * 1e3; | ||
} else { | ||
const error = await response.json(); | ||
throw new Error("Login failed: " + error.error); | ||
} | ||
} | ||
// Method to refresh the access token using the refresh token | ||
async refreshAccessToken() { | ||
const url = `${this.baseUrl}/refresh`; | ||
const data = { | ||
refresh_token: this.refreshToken | ||
}; | ||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
if (response.ok) { | ||
const json = await response.json(); | ||
this.accessToken = json.access_token; | ||
const payload = JSON.parse(atob(this.accessToken.split(".")[1])); | ||
this.tokenExpiresAt = payload.exp * 1e3; | ||
return true; | ||
} else { | ||
this.accessToken = null; | ||
this.refreshToken = null; | ||
this.tokenExpiresAt = null; | ||
return false; | ||
} | ||
} | ||
// Helper method to make authenticated API requests | ||
async makeAuthenticatedRequest(url, options = {}) { | ||
const now = Date.now(); | ||
if (this.tokenExpiresAt - now < 6e4) { | ||
const refreshed = await this.refreshAccessToken(); | ||
if (!refreshed) { | ||
throw new Error("Session expired. Please log in again."); | ||
} | ||
} | ||
options.headers = options.headers || {}; | ||
options.headers["Authorization"] = `Bearer ${this.accessToken}`; | ||
options.headers["Content-Type"] = "application/json"; | ||
const response = await fetch(url, options); | ||
if (response.ok) { | ||
return response; | ||
} else if (response.status === 401) { | ||
const refreshed = await this.refreshAccessToken(); | ||
if (refreshed) { | ||
options.headers["Authorization"] = `Bearer ${this.accessToken}`; | ||
const retryResponse = await fetch(url, options); | ||
if (retryResponse.ok) { | ||
return retryResponse; | ||
} else { | ||
const error = await retryResponse.json(); | ||
throw new Error(`Request failed: ${error.error}`); | ||
} | ||
} else { | ||
throw new Error("Session expired. Please log in again."); | ||
} | ||
} else { | ||
const error = await response.json(); | ||
throw new Error(`Request failed: ${error.error}`); | ||
} | ||
} | ||
// Method to get chat response | ||
async getChat(params) { | ||
const url = `${this.baseUrl}/get_chat`; | ||
const data = { | ||
vault: "", | ||
embeddings_model: this.embeddingsModel, | ||
text: "", | ||
history: null, | ||
summary: false, | ||
get_context: false, | ||
n_context: 4, | ||
return_context: false, | ||
smart_history_search: false, | ||
model: "gpt-4o", | ||
include_context_meta: false, | ||
custom_prompt: false, | ||
temperature: 0, | ||
timeout: 45, | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get chat response with streaming | ||
async getChatStream(params, callback) { | ||
const url = `${this.baseUrl}/stream`; | ||
const data = { | ||
vault: "", | ||
embeddings_model: this.embeddingsModel, | ||
text: "", | ||
history: null, | ||
summary: false, | ||
get_context: false, | ||
n_context: 4, | ||
return_context: false, | ||
smart_history_search: false, | ||
model: "gpt-4o", | ||
include_context_meta: false, | ||
metatag: [], | ||
metatag_prefixes: [], | ||
metatag_suffixes: [], | ||
custom_prompt: false, | ||
temperature: 0, | ||
timeout: 45, | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
const reader = response.body.getReader(); | ||
const decoder = new TextDecoder("utf-8"); | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
const textChunk = decoder.decode(value, { stream: true }); | ||
const lines = textChunk.split("\n"); | ||
for (let line of lines) { | ||
if (line.startsWith("data:")) { | ||
const jsonData = JSON.parse(line.substring("data: ".length)); | ||
const word = jsonData["data"]; | ||
if (word !== "!END") { | ||
callback(word); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// Method to download data to JSON | ||
async downloadToJson(params) { | ||
const url = `${this.baseUrl}/download_to_json`; | ||
const data = { | ||
vault: "", | ||
return_meta: false, | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to upload data from JSON | ||
async uploadFromJson(vault, jsonData) { | ||
const url = `${this.baseUrl}/upload_from_json`; | ||
const data = { | ||
embeddings_model: this.embeddingsModel, | ||
vault, | ||
json: jsonData | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to edit an item | ||
async editItem(vault, itemId, newText) { | ||
const url = `${this.baseUrl}/edit_item`; | ||
const data = { | ||
embeddings_model: this.embeddingsModel, | ||
vault, | ||
item_id: itemId, | ||
text: newText | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get total items | ||
async getTotalItems(vault) { | ||
const url = `${this.baseUrl}/get_total_items`; | ||
const data = { | ||
vault | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to delete the entire vault | ||
async deleteVault(vault) { | ||
const url = `${this.baseUrl}/delete_vault`; | ||
const data = { | ||
vault | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to delete specific items | ||
async deleteItems(vault, itemIds) { | ||
const url = `${this.baseUrl}/delete_items`; | ||
const data = { | ||
vault, | ||
item_ids: itemIds | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to add cloud data | ||
async addCloud(params) { | ||
const url = `${this.baseUrl}/add_cloud`; | ||
const data = { | ||
vault: "", | ||
embeddings_model: this.embeddingsModel, | ||
text: "", | ||
meta: null, | ||
name: null, | ||
split: false, | ||
split_size: 1e3, | ||
gen_sum: false, | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to add website content by URL | ||
async addSite(params) { | ||
const url = `${this.baseUrl}/add_site`; | ||
const data = { | ||
vault: "", | ||
embeddings_model: this.embeddingsModel, | ||
site: "", | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get list of vaults | ||
async getVaults(searchVault = null) { | ||
const url = `${this.baseUrl}/get_vaults`; | ||
const data = { | ||
search_vault: searchVault | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get account data | ||
async getAccountData() { | ||
const url = `${this.baseUrl}/get_vault_data`; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify({}) | ||
}); | ||
const res = await response.json(); | ||
return res.vault_data; | ||
} | ||
// Method to get distance between two items | ||
async getDistance(vault, id1, id2) { | ||
const url = `${this.baseUrl}/get_distance`; | ||
const data = { | ||
vault, | ||
id1, | ||
id2 | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get similar items | ||
async getSimilar(params) { | ||
const url = `${this.baseUrl}/get_similar`; | ||
const data = { | ||
embeddings_model: this.embeddingsModel, | ||
vault: "", | ||
text: "", | ||
num_items: 4, | ||
include_distances: false, | ||
...params | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to save personality message | ||
async savePersonalityMessage(vault, personalityMessage) { | ||
const url = `${this.baseUrl}/save_personality_message`; | ||
const data = { | ||
vault, | ||
personality_message: personalityMessage | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to save custom prompt | ||
async saveCustomPrompt(vault, customPrompt) { | ||
const url = `${this.baseUrl}/save_custom_prompt`; | ||
const data = { | ||
vault, | ||
prompt: customPrompt | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to fetch personality message | ||
async fetchPersonalityMessage(vault) { | ||
const url = `${this.baseUrl}/fetch_personality_message`; | ||
const data = { | ||
vault | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to fetch custom prompt | ||
async fetchCustomPrompt(vault) { | ||
const url = `${this.baseUrl}/fetch_custom_prompt`; | ||
const data = { | ||
vault | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to fetch 3D map data | ||
async fetch3DMap(vault, highlightId = null) { | ||
const url = `${this.baseUrl}/get_map`; | ||
const data = { | ||
vault, | ||
highlight_id: highlightId | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to get items by IDs | ||
async getItems(vault, itemIds) { | ||
const url = `${this.baseUrl}/get_items`; | ||
const data = { | ||
vault, | ||
item_ids: itemIds | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
return response.json(); | ||
} | ||
// Method to run a flow with streaming response | ||
async runFlowStream(flowName, message, history = "", callbacks = {}) { | ||
const url = `${this.baseUrl}/flow-stream`; | ||
const data = { | ||
email: this.email, | ||
flow_id: flowName, | ||
message, | ||
history | ||
}; | ||
const response = await this.makeAuthenticatedRequest(url, { | ||
method: "POST", | ||
body: JSON.stringify(data) | ||
}); | ||
const reader = response.body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let fullResponse = ""; | ||
let logs = []; | ||
let currentEventType = null; | ||
let currentData = ""; | ||
while (true) { | ||
const { value, done } = await reader.read(); | ||
if (done) break; | ||
const chunk = decoder.decode(value); | ||
const lines = chunk.split("\n"); | ||
for (const line of lines) { | ||
if (line.startsWith("event: ")) { | ||
if (currentData) { | ||
processEventData(currentEventType, currentData, callbacks); | ||
} | ||
currentEventType = line.slice(7).trim(); | ||
currentData = ""; | ||
} else if (line.startsWith("data: ")) { | ||
currentData += line.slice(6); | ||
} | ||
} | ||
} | ||
if (currentData) { | ||
processEventData(currentEventType, currentData, callbacks); | ||
} | ||
return { response: fullResponse, logs }; | ||
function processEventData(eventType, data2, callbacks2) { | ||
try { | ||
const parsedData = JSON.parse(data2); | ||
if (eventType === "log") { | ||
logs.push(parsedData); | ||
if (callbacks2.onLog) callbacks2.onLog(parsedData); | ||
} else if (eventType === "message") { | ||
fullResponse += parsedData; | ||
if (callbacks2.onMessage) callbacks2.onMessage(parsedData); | ||
} | ||
} catch (e) { | ||
console.error("Error parsing data:", e); | ||
if (eventType === "log") { | ||
logs.push(data2); | ||
if (callbacks2.onLog) callbacks2.onLog(data2); | ||
} else if (eventType === "message") { | ||
fullResponse += data2; | ||
if (callbacks2.onMessage) callbacks2.onMessage(data2); | ||
} | ||
} | ||
} | ||
} | ||
// Method to log out the user | ||
logout() { | ||
this.accessToken = null; | ||
this.refreshToken = null; | ||
this.tokenExpiresAt = null; | ||
} | ||
}; | ||
// vectorvault-wrapper.js | ||
window.VectorVault = VectorVault; | ||
})(); | ||
/*! For license information please see vectorvault.bundle.js.LICENSE.txt */ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("VectorVault",[],e):"object"==typeof exports?exports.VectorVault=e():t.VectorVault=e()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function n(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return o(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,a=function(){};return{s:a,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,u=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return i=t.done,t},e:function(t){u=!0,s=t},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw s}}}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function s(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?a(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function i(t,e,r){return(e=f(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(){u=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},s="function"==typeof Symbol?Symbol:{},i=s.iterator||"@@iterator",c=s.asyncIterator||"@@asyncIterator",l=s.toStringTag||"@@toStringTag";function h(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{h({},"")}catch(t){h=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,s=Object.create(o.prototype),i=new L(n||[]);return a(s,"_invoke",{value:P(t,r,i)}),s}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var d="suspendedStart",y="suspendedYield",m="executing",v="completed",b={};function g(){}function k(){}function x(){}var w={};h(w,i,(function(){return this}));var O=Object.getPrototypeOf,_=O&&O(O(J([])));_&&_!==n&&o.call(_,i)&&(w=_);var S=x.prototype=g.prototype=Object.create(w);function j(t){["next","throw","return"].forEach((function(e){h(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){function n(a,s,i,u){var c=p(t[a],t,s);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==r(h)&&o.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):e.resolve(h).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}var s;a(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return s=s?s.then(o,o):o()}})}function P(e,r,n){var o=d;return function(a,s){if(o===m)throw Error("Generator is already running");if(o===v){if("throw"===a)throw s;return{value:t,done:!0}}for(n.method=a,n.arg=s;;){var i=n.delegate;if(i){var u=A(i,n);if(u){if(u===b)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=m;var c=p(e,r,n);if("normal"===c.type){if(o=n.done?v:y,c.arg===b)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=v,n.method="throw",n.arg=c.arg)}}}function A(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,A(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),b;var a=p(o,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,b;var s=a.arg;return s?s.done?(r[e.resultName]=s.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,b):s:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,b)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function J(e){if(e||""===e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var a=-1,s=function r(){for(;++a<e.length;)if(o.call(e,a))return r.value=e[a],r.done=!1,r;return r.value=t,r.done=!0,r};return s.next=s}}throw new TypeError(r(e)+" is not iterable")}return k.prototype=x,a(S,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:k,configurable:!0}),k.displayName=h(x,l,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===k||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,h(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},e.awrap=function(t){return{__await:t}},j(T.prototype),h(T.prototype,c,(function(){return this})),e.AsyncIterator=T,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var s=new T(f(t,r,n,o),a);return e.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},j(S),h(S,l,"Generator"),h(S,i,(function(){return this})),h(S,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=J,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(N),!e)for(var r in this)"t"===r.charAt(0)&&o.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return i.type="throw",i.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var s=this.tryEntries[a],i=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var u=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var s=a?a.completion:{};return s.type=t,s.arg=e,a?(this.method="next",this.next=a.finallyLoc,b):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),b},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),b}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:J(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),b}},e}function c(t,e,r,n,o,a,s){try{var i=t[a](s),u=i.value}catch(t){return void r(t)}i.done?e(u):Promise.resolve(u).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function s(t){c(a,n,o,s,i,"next",t)}function i(t){c(a,n,o,s,i,"throw",t)}s(void 0)}))}}function h(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,f(n.key),n)}}function f(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}t.r(e),t.d(e,{default:()=>p});var p=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.embeddingsModel=e,this.accessToken=null,this.refreshToken=null,this.tokenExpiresAt=null,this.baseUrl="https://api.vectorvault.io"},e=[{key:"login",value:(E=l(u().mark((function t(e,r){var n,o,a,s,i,c;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/login"),o={email:e,password:r},t.next=4,fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 4:if(!(a=t.sent).ok){t.next=15;break}return t.next=8,a.json();case 8:s=t.sent,this.accessToken=s.access_token,this.refreshToken=s.refresh_token,i=JSON.parse(atob(this.accessToken.split(".")[1])),this.tokenExpiresAt=1e3*i.exp,t.next=19;break;case 15:return t.next=17,a.json();case 17:throw c=t.sent,new Error("Login failed: "+c.error);case 19:case"end":return t.stop()}}),t,this)}))),function(t,e){return E.apply(this,arguments)})},{key:"refreshAccessToken",value:(A=l(u().mark((function t(){var e,r,n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e="".concat(this.baseUrl,"/refresh"),r={refresh_token:this.refreshToken},t.next=4,fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});case 4:if(!(n=t.sent).ok){t.next=15;break}return t.next=8,n.json();case 8:return o=t.sent,this.accessToken=o.access_token,a=JSON.parse(atob(this.accessToken.split(".")[1])),this.tokenExpiresAt=1e3*a.exp,t.abrupt("return",!0);case 15:return this.accessToken=null,this.refreshToken=null,this.tokenExpiresAt=null,t.abrupt("return",!1);case 19:case"end":return t.stop()}}),t,this)}))),function(){return A.apply(this,arguments)})},{key:"makeAuthenticatedRequest",value:(P=l(u().mark((function t(e){var r,n,o,a,s,i,c=arguments;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=c.length>1&&void 0!==c[1]?c[1]:{},n=Date.now(),!(this.tokenExpiresAt-n<6e4)){t.next=8;break}return t.next=5,this.refreshAccessToken();case 5:if(t.sent){t.next=8;break}throw new Error("Session expired. Please log in again.");case 8:return r.headers=r.headers||{},r.headers.Authorization="Bearer ".concat(this.accessToken),r.headers["Content-Type"]="application/json",t.next=13,fetch(e,r);case 13:if(!(o=t.sent).ok){t.next=18;break}return t.abrupt("return",o);case 18:if(401!==o.status){t.next=40;break}return t.next=21,this.refreshAccessToken();case 21:if(!t.sent){t.next=37;break}return r.headers.Authorization="Bearer ".concat(this.accessToken),t.next=26,fetch(e,r);case 26:if(!(a=t.sent).ok){t.next=31;break}return t.abrupt("return",a);case 31:return t.next=33,a.json();case 33:throw s=t.sent,new Error("Request failed: ".concat(s.error));case 35:t.next=38;break;case 37:throw new Error("Session expired. Please log in again.");case 38:t.next=44;break;case 40:return t.next=42,o.json();case 42:throw i=t.sent,new Error("Request failed: ".concat(i.error));case 44:case"end":return t.stop()}}),t,this)}))),function(t){return P.apply(this,arguments)})},{key:"getAccessToken",value:function(){return this.accessToken}},{key:"getRefreshToken",value:function(){return this.refreshToken}},{key:"setAccessToken",value:function(t){this.accessToken=t;var e=JSON.parse(atob(t.split(".")[1]));this.tokenExpiresAt=1e3*e.exp}},{key:"setRefreshToken",value:function(t){this.refreshToken=t}},{key:"getChat",value:(T=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/get_chat"),n=s({vault:"",embeddings_model:this.embeddingsModel,text:"",history:null,summary:!1,get_context:!1,n_context:4,return_context:!1,smart_history_search:!1,model:"gpt-4o",include_context_meta:!1,custom_prompt:!1,temperature:0,timeout:45},e),t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return T.apply(this,arguments)})},{key:"getChatStream",value:(j=l(u().mark((function t(e,r){var o,a,i,c,l,h,f,p,d,y,m,v,b,g,k;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="".concat(this.baseUrl,"/stream"),a=s({vault:"",embeddings_model:this.embeddingsModel,text:"",history:null,summary:!1,get_context:!1,n_context:4,return_context:!1,smart_history_search:!1,model:"gpt-4o",include_context_meta:!1,metatag:[],metatag_prefixes:[],metatag_suffixes:[],custom_prompt:!1,temperature:0,timeout:45},e),t.next=4,this.makeAuthenticatedRequest(o,{method:"POST",body:JSON.stringify(a)});case 4:i=t.sent,c=i.body.getReader(),l=new TextDecoder("utf-8");case 7:return t.next=10,c.read();case 10:if(h=t.sent,f=h.done,p=h.value,!f){t.next=15;break}return t.abrupt("break",21);case 15:d=l.decode(p,{stream:!0}),y=d.split("\n"),m=n(y);try{for(m.s();!(v=m.n()).done;)(b=v.value).startsWith("data:")&&(g=JSON.parse(b.substring(6)),"!END"!==(k=g.data)&&r(k))}catch(t){m.e(t)}finally{m.f()}t.next=7;break;case 21:case"end":return t.stop()}}),t,this)}))),function(t,e){return j.apply(this,arguments)})},{key:"downloadToJson",value:(S=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/download_to_json"),n=s({vault:"",return_meta:!1},e),t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return S.apply(this,arguments)})},{key:"uploadFromJson",value:(_=l(u().mark((function t(e,r){var n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/upload_from_json"),o={embeddings_model:this.embeddingsModel,vault:e,json:r},t.next=4,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return _.apply(this,arguments)})},{key:"editItem",value:(O=l(u().mark((function t(e,r,n){var o,a,s;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="".concat(this.baseUrl,"/edit_item"),a={embeddings_model:this.embeddingsModel,vault:e,item_id:r,text:n},t.next=4,this.makeAuthenticatedRequest(o,{method:"POST",body:JSON.stringify(a)});case 4:return s=t.sent,t.abrupt("return",s.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e,r){return O.apply(this,arguments)})},{key:"getTotalItems",value:(w=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/get_total_items"),n={vault:e},t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return w.apply(this,arguments)})},{key:"deleteVault",value:(x=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/delete_vault"),n={vault:e},t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return x.apply(this,arguments)})},{key:"deleteItems",value:(k=l(u().mark((function t(e,r){var n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/delete_items"),o={vault:e,item_ids:r},t.next=4,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return k.apply(this,arguments)})},{key:"addCloud",value:(g=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/add_cloud"),n=s({vault:"",embeddings_model:this.embeddingsModel,text:"",meta:null,name:null,split:!1,split_size:1e3,gen_sum:!1},e),t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return g.apply(this,arguments)})},{key:"addSite",value:(b=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/add_site"),n=s({vault:"",embeddings_model:this.embeddingsModel,site:""},e),t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return b.apply(this,arguments)})},{key:"getVaults",value:(v=l(u().mark((function t(){var e,r,n,o,a=arguments;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=a.length>0&&void 0!==a[0]?a[0]:null,r="".concat(this.baseUrl,"/get_vaults"),n={search_vault:e},t.next=5,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 5:return o=t.sent,t.abrupt("return",o.json());case 7:case"end":return t.stop()}}),t,this)}))),function(){return v.apply(this,arguments)})},{key:"getAccountData",value:(m=l(u().mark((function t(){var e,r,n;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e="".concat(this.baseUrl,"/get_vault_data"),t.next=3,this.makeAuthenticatedRequest(e,{method:"POST",body:JSON.stringify({})});case 3:return r=t.sent,t.next=6,r.json();case 6:return n=t.sent,t.abrupt("return",n.vault_data);case 8:case"end":return t.stop()}}),t,this)}))),function(){return m.apply(this,arguments)})},{key:"getDistance",value:(y=l(u().mark((function t(e,r,n){var o,a,s;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o="".concat(this.baseUrl,"/get_distance"),a={vault:e,id1:r,id2:n},t.next=4,this.makeAuthenticatedRequest(o,{method:"POST",body:JSON.stringify(a)});case 4:return s=t.sent,t.abrupt("return",s.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e,r){return y.apply(this,arguments)})},{key:"getSimilar",value:(d=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/get_similar"),n=s({embeddings_model:this.embeddingsModel,vault:"",text:"",num_items:4,include_distances:!1},e),t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return d.apply(this,arguments)})},{key:"savePersonalityMessage",value:(p=l(u().mark((function t(e,r){var n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/save_personality_message"),o={vault:e,personality_message:r},t.next=4,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return p.apply(this,arguments)})},{key:"saveCustomPrompt",value:(f=l(u().mark((function t(e,r){var n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/save_custom_prompt"),o={vault:e,prompt:r},t.next=4,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return f.apply(this,arguments)})},{key:"fetchPersonalityMessage",value:(c=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/fetch_personality_message"),n={vault:e},t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return c.apply(this,arguments)})},{key:"fetchCustomPrompt",value:(i=l(u().mark((function t(e){var r,n,o;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="".concat(this.baseUrl,"/fetch_custom_prompt"),n={vault:e},t.next=4,this.makeAuthenticatedRequest(r,{method:"POST",body:JSON.stringify(n)});case 4:return o=t.sent,t.abrupt("return",o.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"fetch3DMap",value:(a=l(u().mark((function t(e){var r,n,o,a,s=arguments;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=s.length>1&&void 0!==s[1]?s[1]:null,n="".concat(this.baseUrl,"/get_map"),o={vault:e,highlight_id:r},t.next=5,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 5:return a=t.sent,t.abrupt("return",a.json());case 7:case"end":return t.stop()}}),t,this)}))),function(t){return a.apply(this,arguments)})},{key:"getItems",value:(o=l(u().mark((function t(e,r){var n,o,a;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n="".concat(this.baseUrl,"/get_items"),o={vault:e,item_ids:r},t.next=4,this.makeAuthenticatedRequest(n,{method:"POST",body:JSON.stringify(o)});case 4:return a=t.sent,t.abrupt("return",a.json());case 6:case"end":return t.stop()}}),t,this)}))),function(t,e){return o.apply(this,arguments)})},{key:"runFlowStream",value:(r=l(u().mark((function t(e,r){var o,a,s,i,c,l,h,f,p,d,y,m,v,b,g,k,x,w,O,_=arguments;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return O=function(t,e,r){try{var n=JSON.parse(e);"log"===t?(p.push(n),r.onLog&&r.onLog(n)):"message"===t&&(f+=n,r.onMessage&&r.onMessage(n))}catch(n){console.error("Error parsing data:",n),"log"===t?(p.push(e),r.onLog&&r.onLog(e)):"message"===t&&(f+=e,r.onMessage&&r.onMessage(e))}},o=_.length>2&&void 0!==_[2]?_[2]:"",a=_.length>3&&void 0!==_[3]?_[3]:{},s="".concat(this.baseUrl,"/flow-stream"),i={email:this.email,flow_id:e,message:r,history:o},t.next=7,this.makeAuthenticatedRequest(s,{method:"POST",body:JSON.stringify(i)});case 7:c=t.sent,l=c.body.getReader(),h=new TextDecoder,f="",p=[],d=null,y="";case 14:return t.next=17,l.read();case 17:if(m=t.sent,v=m.value,!m.done){t.next=22;break}return t.abrupt("break",28);case 22:b=h.decode(v),g=b.split("\n"),k=n(g);try{for(k.s();!(x=k.n()).done;)(w=x.value).startsWith("event: ")?(y&&O(d,y,a),d=w.slice(7).trim(),y=""):w.startsWith("data: ")&&(y+=w.slice(6))}catch(t){k.e(t)}finally{k.f()}t.next=14;break;case 28:return y&&O(d,y,a),t.abrupt("return",{response:f,logs:p});case 30:case"end":return t.stop()}}),t,this)}))),function(t,e){return r.apply(this,arguments)})},{key:"logout",value:function(){this.accessToken=null,this.refreshToken=null,this.tokenExpiresAt=null}}],e&&h(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r,o,a,i,c,f,p,d,y,m,v,b,g,k,x,w,O,_,S,j,T,P,A,E}();return e})())); |
31
index.js
@@ -42,2 +42,33 @@ export default class VectorVault { | ||
// Method to log in the user and obtain JWT tokens via API | ||
async loginWithApiKey(apiKey) { | ||
const url = `${this.baseUrl}/login_api_key`; | ||
const data = { | ||
api_key: apiKey | ||
}; | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
if (response.ok) { | ||
const json = await response.json(); | ||
this.accessToken = json.access_token; | ||
this.refreshToken = json.refresh_token; | ||
// Decode the JWT to get the expiration time | ||
const payload = JSON.parse(atob(this.accessToken.split('.')[1])); | ||
// JWT 'exp' claim is in seconds, convert to milliseconds | ||
this.tokenExpiresAt = payload.exp * 1000; | ||
} else { | ||
const error = await response.json(); | ||
throw new Error("API Key Login failed: " + error.error); | ||
} | ||
} | ||
// Method to refresh the access token using the refresh token | ||
@@ -44,0 +75,0 @@ async refreshAccessToken() { |
{ | ||
"name": "vectorvault", | ||
"version": "1.3.6", | ||
"version": "1.3.7", | ||
"description": "VectorVault API - JavaScript Client: Streamline your front-end development with the powerful combination of OpenAI's API and VectorVault's Cloud Vector Database. This JavaScript client provides seamless integration for building advanced RAG (Retrieve and Generate) applications. Whether you're working with JavaScript, HTML, or other web technologies, our API simplifies the process of fetching RAG responses through API POST requests. This package is the key to unlocking quick and efficient development for AI-powered web applications, ensuring a secure and robust connection to the VectorVault ecosystem. Start crafting exceptional RAG apps with minimal effort and maximum efficiency.", | ||
@@ -8,2 +8,3 @@ "type": "module", | ||
"scripts": { | ||
"build": "webpack --config webpack.config.cjs", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -36,4 +37,7 @@ }, | ||
"@babel/preset-env": "^7.26.0", | ||
"babelify": "^10.0.0" | ||
"babel-loader": "^9.2.1", | ||
"babelify": "^10.0.0", | ||
"webpack": "^5.95.0", | ||
"webpack-cli": "^5.1.4" | ||
} | ||
} |
@@ -135,3 +135,3 @@ # VectorVault | ||
- **Logout** | ||
- **Logout** | ||
@@ -138,0 +138,0 @@ ```javascript |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56752
8
6
1
80
562
9