rebase final

This commit is contained in:
Arpit Singh Bhatia
2024-12-26 14:05:40 +05:30
parent 8d299244fc
commit a80fb0f1e0
4 changed files with 180 additions and 0 deletions

View File

@@ -1229,6 +1229,52 @@ export class SolanaCreateGibworkTask extends Tool {
}
}
export class SolanaRockPaperScissorsTool extends Tool {
name = "rock_paper_scissors_blink";
description = `Play rock paper scissors to win the SEND coin.
Inputs(convert the input to a json string):
choice: string, either "rock", "paper", or "scissors" (required)
amount: number, amount of SOL to play the game with, either 0.1, 0.01, or 0.005 SOL (required)`;
constructor(private solanaKit: SolanaAgentKit) {
super();
}
private validateInput(input: any): void {
if (input.choice !== undefined) {
throw new Error('choice is required.');
}
if (
input.amount !== undefined &&
(typeof input.spaceKB !== "number" || input.spaceKB <= 0)
) {
throw new Error("amount must be a positive number when provided");
}
}
protected async _call(input: string): Promise<string> {
try {
const parsedInput = toJSON(input);
this.validateInput(parsedInput);
const result = await this.solanaKit.rockPaperScissors(
Number(parsedInput['"amount"']),
parsedInput['"choice"'].replace(/^"|"$/g, '') as "rock" | "paper" | "scissors"
);
return JSON.stringify({
status: "success",
message: result,
});
} catch (error: any) {
return JSON.stringify({
status: "error",
message: error.message,
code: error.code || "UNKNOWN_ERROR",
});
}
}
}
export function createSolanaTools(solanaKit: SolanaAgentKit) {
return [
new SolanaBalanceTool(solanaKit),
@@ -1263,5 +1309,6 @@ export function createSolanaTools(solanaKit: SolanaAgentKit) {
new SolanaGetMainDomain(solanaKit),
new SolanaResolveAllDomainsTool(solanaKit),
new SolanaCreateGibworkTask(solanaKit),
new SolanaRockPaperScissorsTool(solanaKit),
];
}