grinning-cat-typescript-client
v1.0.5
Published
Typescript Client for the Grinning Cat API
Readme
Grinning Cat Typescript Client
Grinning Cat Typescript Client is a library to help the implementation of Grinning Cat on a JavaScript / TypeScript (e.g. Node.js, React.js, Vue.js) Project
Installation
To install Grinning Cat Typescript Client, run:
npm install grinning-cat-typescript-clientor, if you are using yarn:
yarn add grinning-cat-typescript-clientUsage
Initialization and usage:
import { GrinningCatClient, HttpClient, WSClient } from 'grinning-cat-typescript-client';
const catClient = new GrinningCatClient(
new WSClient('grinning_cat_core', 1865, null),
new HttpClient('grinning_cat_core', 1865, null)
);Authenticate with a username and password (the client keeps the returned access token for the following calls), refresh it before it expires, and log out to revoke the session:
const token = await catClient.auth().token("username", "password");
// token.accessToken, token.expiresIn, token.refreshToken, token.refreshExpiresIn
// before the access token expires, exchange the (single-use) refresh token for a new pair
const refreshed = await catClient.auth().refresh(token.refreshToken);
// revoke the session; already-issued access tokens stay valid until they expire
await catClient.auth().logout(refreshed.refreshToken);Send a message to the websocket:
import { Message } from 'grinning-cat-typescript-client';
const notificationClosure = (message: string) => {
// handle websocket notification, like chat token stream
}
// result is the result of the message
const result = catClient.message().sendWebsocketMessage(
new Message("Hello world!"), // message body
"agent", // agent name
"user", // user name
notificationClosure // websocket notification closure handle
);
Load data to the rabbit hole:
//file
const result = await catClient.rabbitHole().postFile(file, "agent");
//url
const result = await catClient.rabbitHole().postWeb(url, "agent");Memory management utilities:
catClient.memory().getMemoryCollections("agent"); // get number of vectors in the working memory
catClient.memory().getMemoryRecall("HELLO", "agent", "user"); // recall memories by text
//delete memory points by metadata, like this example delete by source
catClient.memory().deleteMemoryPointsByMetadata("declarative", "agent", {"source": url});