I have a new ability to manage what I learn, which will help me better assist you.
This commit is contained in:
parent
76b07f76cd
commit
7920b3fa1f
7 changed files with 97 additions and 4 deletions
|
|
@ -83,6 +83,7 @@ ${parsedThread}`,
|
||||||
|
|
||||||
const functionResponse = await tools.handler(
|
const functionResponse = await tools.handler(
|
||||||
call as typeof call & { name: SupportedFunctionCall },
|
call as typeof call & { name: SupportedFunctionCall },
|
||||||
|
post.author.did,
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.log("Function response:", functionResponse);
|
logger.log("Function response:", functionResponse);
|
||||||
|
|
|
||||||
65
src/tools/add_to_memory.ts
Normal file
65
src/tools/add_to_memory.ts
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
import { Type } from "@google/genai";
|
||||||
|
import { MemoryHandler } from "../utils/memory";
|
||||||
|
import z from "zod";
|
||||||
|
|
||||||
|
export const definition = {
|
||||||
|
name: "add_to_memory",
|
||||||
|
description: "Adds or updates an entry in a user's memory block.",
|
||||||
|
parameters: {
|
||||||
|
type: Type.OBJECT,
|
||||||
|
properties: {
|
||||||
|
label: {
|
||||||
|
type: Type.STRING,
|
||||||
|
description: "The key or label for the memory entry.",
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Type.STRING,
|
||||||
|
description: "The value to be stored.",
|
||||||
|
},
|
||||||
|
block: {
|
||||||
|
type: Type.STRING,
|
||||||
|
description: "The name of the memory block to add to. Defaults to 'memory'.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["label", "value"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validator = z.object({
|
||||||
|
label: z.string(),
|
||||||
|
value: z.string(),
|
||||||
|
block: z.string().optional().default("memory"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function handler(
|
||||||
|
args: z.infer<typeof validator>,
|
||||||
|
did: string,
|
||||||
|
) {
|
||||||
|
const userMemory = new MemoryHandler(
|
||||||
|
did,
|
||||||
|
await MemoryHandler.getBlocks(did),
|
||||||
|
);
|
||||||
|
|
||||||
|
const blockHandler = userMemory.getBlockByName(args.block);
|
||||||
|
|
||||||
|
if (!blockHandler) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `Memory block with name '${args.block}' not found.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!blockHandler.block.mutable) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: `Memory block '${args.block}' is not mutable.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
await blockHandler.createEntry(args.label, args.value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `Entry with label '${args.label}' has been added to the '${args.block}' memory block.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -28,7 +28,10 @@ export const validator = z.object({
|
||||||
content: z.string(),
|
content: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function handler(args: z.infer<typeof validator>) {
|
export async function handler(
|
||||||
|
args: z.infer<typeof validator>,
|
||||||
|
did: string,
|
||||||
|
) {
|
||||||
//@ts-ignore: NSID is valid
|
//@ts-ignore: NSID is valid
|
||||||
const entry = await bot.createRecord("com.whtwnd.blog.entry", {
|
const entry = await bot.createRecord("com.whtwnd.blog.entry", {
|
||||||
$type: "com.whtwnd.blog.entry",
|
$type: "com.whtwnd.blog.entry",
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ export const validator = z.object({
|
||||||
text: z.string(),
|
text: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function handler(args: z.infer<typeof validator>) {
|
export async function handler(
|
||||||
|
args: z.infer<typeof validator>,
|
||||||
|
did: string,
|
||||||
|
) {
|
||||||
let uri: string | null = null;
|
let uri: string | null = null;
|
||||||
if (exceedsGraphemes(args.text)) {
|
if (exceedsGraphemes(args.text)) {
|
||||||
uri = await multipartResponse(args.text);
|
uri = await multipartResponse(args.text);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import type { FunctionCall, GenerateContentConfig } from "@google/genai";
|
import type { FunctionCall, GenerateContentConfig } from "@google/genai";
|
||||||
|
import * as add_to_memory from "./add_to_memory";
|
||||||
import * as create_blog_post from "./create_blog_post";
|
import * as create_blog_post from "./create_blog_post";
|
||||||
import * as create_post from "./create_post";
|
import * as create_post from "./create_post";
|
||||||
import * as mute_thread from "./mute_thread";
|
import * as mute_thread from "./mute_thread";
|
||||||
|
|
@ -8,6 +9,7 @@ const validation_mappings = {
|
||||||
"create_post": create_post.validator,
|
"create_post": create_post.validator,
|
||||||
"create_blog_post": create_blog_post.validator,
|
"create_blog_post": create_blog_post.validator,
|
||||||
"mute_thread": mute_thread.validator,
|
"mute_thread": mute_thread.validator,
|
||||||
|
"add_to_memory": add_to_memory.validator,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const declarations = [
|
export const declarations = [
|
||||||
|
|
@ -16,26 +18,38 @@ export const declarations = [
|
||||||
create_post.definition,
|
create_post.definition,
|
||||||
create_blog_post.definition,
|
create_blog_post.definition,
|
||||||
mute_thread.definition,
|
mute_thread.definition,
|
||||||
|
add_to_memory.definition,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
type ToolName = keyof typeof validation_mappings;
|
type ToolName = keyof typeof validation_mappings;
|
||||||
export async function handler(call: FunctionCall & { name: ToolName }) {
|
export async function handler(
|
||||||
|
call: FunctionCall & { name: ToolName },
|
||||||
|
did: string,
|
||||||
|
) {
|
||||||
const parsedArgs = validation_mappings[call.name].parse(call.args);
|
const parsedArgs = validation_mappings[call.name].parse(call.args);
|
||||||
|
|
||||||
switch (call.name) {
|
switch (call.name) {
|
||||||
case "create_post":
|
case "create_post":
|
||||||
return await create_post.handler(
|
return await create_post.handler(
|
||||||
parsedArgs as z_infer<typeof create_post.validator>,
|
parsedArgs as z_infer<typeof create_post.validator>,
|
||||||
|
did,
|
||||||
);
|
);
|
||||||
case "create_blog_post":
|
case "create_blog_post":
|
||||||
return await create_blog_post.handler(
|
return await create_blog_post.handler(
|
||||||
parsedArgs as z_infer<typeof create_blog_post.validator>,
|
parsedArgs as z_infer<typeof create_blog_post.validator>,
|
||||||
|
did,
|
||||||
);
|
);
|
||||||
case "mute_thread":
|
case "mute_thread":
|
||||||
return await mute_thread.handler(
|
return await mute_thread.handler(
|
||||||
parsedArgs as z_infer<typeof mute_thread.validator>,
|
parsedArgs as z_infer<typeof mute_thread.validator>,
|
||||||
|
did,
|
||||||
|
);
|
||||||
|
case "add_to_memory":
|
||||||
|
return await add_to_memory.handler(
|
||||||
|
parsedArgs as z_infer<typeof add_to_memory.validator>,
|
||||||
|
did,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ export const validator = z.object({
|
||||||
uri: z.string(),
|
uri: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function handler(args: z.infer<typeof validator>) {
|
export async function handler(
|
||||||
|
args: z.infer<typeof validator>,
|
||||||
|
did: string,
|
||||||
|
) {
|
||||||
//@ts-ignore: NSID is valid
|
//@ts-ignore: NSID is valid
|
||||||
const record = await bot.createRecord("dev.indexx.echo.threadmute", {
|
const record = await bot.createRecord("dev.indexx.echo.threadmute", {
|
||||||
$type: "dev.indexx.echo.threadmute",
|
$type: "dev.indexx.echo.threadmute",
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ export class MemoryHandler {
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getBlockByName(name: string) {
|
||||||
|
return this.blocks.find((handler) => handler.block.name === name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MemoryBlockHandler {
|
export class MemoryBlockHandler {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue