Add forgetting and personality change

This commit is contained in:
Aslan 2025-12-29 18:52:20 +01:00
parent 6ab8dbd19e
commit 76e496bd38
3 changed files with 103 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "aslobot-matrix", "name": "aslobot-matrix",
"version": "1.1.0", "version": "1.2.0",
"description": "", "description": "",
"license": "ISC", "license": "ISC",
"author": "", "author": "",

View file

@ -1,3 +1,4 @@
import type { MatrixClient } from "matrix-js-sdk";
import { config } from "./config.js"; import { config } from "./config.js";
import { state } from "./store/store.js"; import { state } from "./store/store.js";
import { type IUser, type TRole } from "./store/types.js"; import { type IUser, type TRole } from "./store/types.js";
@ -98,6 +99,28 @@ const getUserFromMention = (mention: string | undefined): IUser | undefined => {
return user; 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 { export {
fixUserData, fixUserData,
getUserById, getUserById,
@ -105,4 +128,5 @@ export {
getLevel, getLevel,
getUserName, getUserName,
getUserFromMention, getUserFromMention,
changePersonality,
}; };

View file

@ -3,6 +3,7 @@ import { config, packageConfig } from "../../config.js";
import type { AIToolFunction } from "./types.js"; import type { AIToolFunction } from "./types.js";
import { save, state } from "../../store/store.js"; import { save, state } from "../../store/store.js";
import { EventType, RelationType } from "matrix-js-sdk"; import { EventType, RelationType } from "matrix-js-sdk";
import { changePersonality } from "../../helpers.js";
const tools: FunctionDeclaration[] = [ const tools: FunctionDeclaration[] = [
{ {
@ -44,7 +45,7 @@ const tools: FunctionDeclaration[] = [
}, },
{ {
name: "remember", name: "remember",
description: "Gets information about this AI bot", description: "Remembers information",
parametersJsonSchema: { parametersJsonSchema: {
type: "object", type: "object",
properties: { properties: {
@ -57,6 +58,21 @@ const tools: FunctionDeclaration[] = [
required: ["knowledge"], 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", name: "changeUsername",
description: "Changes the username of this AI bot", description: "Changes the username of this AI bot",
@ -71,6 +87,20 @@ const tools: FunctionDeclaration[] = [
required: ["username"], 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", name: "getFullUserData",
description: "Gets the full user data about all users", description: "Gets the full user data about all users",
@ -140,10 +170,40 @@ const toolFunctions: AIToolFunction[] = [
if (!state.aiMemory) { if (!state.aiMemory) {
state.aiMemory = []; state.aiMemory = [];
} }
if (args.knowledge) { if (!args.knowledge) {
state.aiMemory.push(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 { return {
message: "success", 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", name: "getFullUserData",
function: (_matrix, _args) => { function: (_matrix, _args) => {