mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-08 23:26:51 +00:00
rebase final
This commit is contained in:
@@ -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),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user