diff --git a/package.json b/package.json index e9c31da..64c45d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aslobot-matrix", - "version": "1.1.0", + "version": "1.2.0", "description": "", "license": "ISC", "author": "", diff --git a/src/helpers.ts b/src/helpers.ts index 9aa72a9..73b6733 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,3 +1,4 @@ +import type { MatrixClient } from "matrix-js-sdk"; import { config } from "./config.js"; import { state } from "./store/store.js"; import { type IUser, type TRole } from "./store/types.js"; @@ -98,6 +99,28 @@ const getUserFromMention = (mention: string | undefined): IUser | undefined => { return user; }; +const changePersonality = ( + client: MatrixClient, + personalityName: string, +): boolean => { + const personalityIndex = config.app.ai.personalities.findIndex( + (personality) => personality.personalityName === personalityName, + ); + if (personalityIndex === -1) { + return false; + } + + state.personality = { + index: personalityIndex, + startTime: Date.now(), + }; + client.setDisplayName( + `AsloBot (${config.app.ai.personalities[state.personality.index]?.personalityName})`, + ); + + return true; +}; + export { fixUserData, getUserById, @@ -105,4 +128,5 @@ export { getLevel, getUserName, getUserFromMention, + changePersonality, }; diff --git a/src/services/ai/tools.ts b/src/services/ai/tools.ts index c871026..636b021 100644 --- a/src/services/ai/tools.ts +++ b/src/services/ai/tools.ts @@ -3,6 +3,7 @@ import { config, packageConfig } from "../../config.js"; import type { AIToolFunction } from "./types.js"; import { save, state } from "../../store/store.js"; import { EventType, RelationType } from "matrix-js-sdk"; +import { changePersonality } from "../../helpers.js"; const tools: FunctionDeclaration[] = [ { @@ -44,7 +45,7 @@ const tools: FunctionDeclaration[] = [ }, { name: "remember", - description: "Gets information about this AI bot", + description: "Remembers information", parametersJsonSchema: { type: "object", properties: { @@ -57,6 +58,21 @@ const tools: FunctionDeclaration[] = [ required: ["knowledge"], }, }, + { + name: "forget", + description: "Forgets information", + parametersJsonSchema: { + type: "object", + properties: { + knowledge: { + type: "string", + description: + "knowledge to forget (has to be exactly word for word, every character)", + }, + }, + required: ["knowledge"], + }, + }, { name: "changeUsername", description: "Changes the username of this AI bot", @@ -71,6 +87,20 @@ const tools: FunctionDeclaration[] = [ required: ["username"], }, }, + { + name: "changePersonality", + description: "Changes the personality of this AI bot", + parametersJsonSchema: { + type: "object", + properties: { + personalityName: { + type: "string", + description: "name of the personality to switch to", + }, + }, + required: ["personalityName"], + }, + }, { name: "getFullUserData", description: "Gets the full user data about all users", @@ -140,10 +170,40 @@ const toolFunctions: AIToolFunction[] = [ if (!state.aiMemory) { state.aiMemory = []; } - if (args.knowledge) { - state.aiMemory.push(args.knowledge); + if (!args.knowledge) { + return { + message: "failed", + }; } + state.aiMemory.push(args.knowledge); + + return { + message: "success", + }; + }, + }, + { + name: "forget", + function: (_matrix, args) => { + if (!state.aiMemory) { + state.aiMemory = []; + } + if (!args.knowledge) { + return { + message: "failed", + }; + } + + const index = state.aiMemory.indexOf(args.knowledge); + if (index === -1) { + return { + message: "cannot find that memory", + }; + } + + state.aiMemory.splice(index, 1); + return { message: "success", }; @@ -163,6 +223,21 @@ const toolFunctions: AIToolFunction[] = [ }; }, }, + { + name: "changePersonality", + function: (matrix, args) => { + const result = changePersonality( + matrix.client, + args.personalityName, + ); + + return { + message: result + ? "success" + : "personality with that name does not exist", + }; + }, + }, { name: "getFullUserData", function: (_matrix, _args) => {