Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This repository is a learning-friendly scaffold for building Hedera Agent Kit pl
```bash
git clone https://github.com/hedera-dev/tutorial-create-hedera-agent-kit-plugin.git
cd tutorial-create-hedera-agent-kit-plugin
npm install
npm ci
```

Expand Down
11 changes: 11 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as hedera_agent_kit from 'hedera-agent-kit';
import { Context } from 'hedera-agent-kit';

declare const _default: {
name: string;
version: string;
description: string;
tools: (context: Context) => hedera_agent_kit.Tool[];
};

export { _default as default };
11 changes: 11 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as hedera_agent_kit from 'hedera-agent-kit';
import { Context } from 'hedera-agent-kit';

declare const _default: {
name: string;
version: string;
description: string;
tools: (context: Context) => hedera_agent_kit.Tool[];
};

export { _default as default };
138 changes: 138 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// src/schemas/hello-world.schema.ts
import z from "zod";
var helloWorldParameters = (_context = {}) => z.object({
name: z.string().describe("Name")
});

// src/tools/hello-world.ts
var helloWorldPrompt = (_context = {}) => {
return `
This tool say hello to the inputted name.

Parameters:
- name (string): the user's name
`;
};
var helloWorldExecute = async (_client, _context, params) => {
return `Hello, ${params.name}`;
};
var HELLO_WORLD_TOOL = "hello_world_tool";
var tool = (context) => ({
method: HELLO_WORLD_TOOL,
name: "Simple Hello World Tool",
description: helloWorldPrompt(context),
parameters: helloWorldParameters(context),
execute: helloWorldExecute
});
var hello_world_default = tool;

// src/tools/simple-transfer-hbar.ts
import { handleTransaction } from "hedera-agent-kit";
import { AccountId, Hbar, TransferTransaction, Status } from "@hashgraph/sdk";

// src/schemas/simple-transfer-hbar.schema.ts
import z2 from "zod";
var simpleTransferHbarParameters = (_context = {}) => z2.object({
recipientId: z2.string().describe("The recipient's account ID"),
amount: z2.number().describe("The amount of HBAR to transfer")
});

// src/tools/simple-transfer-hbar.ts
var simpleHbarTransferPrompt = (context = {}) => {
return `
This tool transfers hbar to a Hedera account, giving that account address and the amount of the transaction in HBAR.

Parameters:
- recipientId (string): the account id of the recipient of the transaction.
- amount (number): the amount of HBAR to transfer.
`;
};
var SIMPLE_HBAR_TRANSFER_TOOL = "simple_hbar_transfer_tool";
var simpleHbarTransferExecute = async (client, context, params) => {
const { recipientId, amount } = params;
const senderId = context.accountId ?? client.operatorAccountId?.toString();
if (!senderId) {
const humanMessage = "Missing sender account: set context.accountId or configure a Client operator.";
return {
raw: { status: Status.InvalidTransaction, error: humanMessage },
humanMessage
};
}
if (!Number.isFinite(amount) || amount <= 0) {
const humanMessage = "Amount must be a positive number of HBAR.";
return {
raw: { status: Status.InvalidTransaction, error: humanMessage },
humanMessage
};
}
try {
const sender = AccountId.fromString(senderId);
const recipient = AccountId.fromString(recipientId);
const tx = new TransferTransaction().addHbarTransfer(sender, new Hbar(-amount)).addHbarTransfer(recipient, new Hbar(amount));
return await handleTransaction(tx, client, context, ({ transactionId, status }) => {
return `Transferred ${amount} HBAR from ${senderId} to ${recipientId}. Status: ${status}. (txId: ${transactionId})`;
});
} catch (err) {
console.error("[transfer_hbar_tool]", err);
const humanMessage = `HBAR transfer failed: ${err instanceof Error ? err.message : String(err)}`;
return {
raw: { status: Status.InvalidTransaction, error: humanMessage },
humanMessage
};
}
};
var tool2 = (context) => ({
method: SIMPLE_HBAR_TRANSFER_TOOL,
name: "Simple HBAR Transfer",
description: simpleHbarTransferPrompt(context),
parameters: simpleTransferHbarParameters(context),
execute: simpleHbarTransferExecute
});
var simple_transfer_hbar_default = tool2;

// src/index.ts
var index_default = {
name: "example-plugin",
version: "1.0.0",
description: "An example plugin for the Hedera Agent Kit",
tools: (context) => {
return [hello_world_default(context), simple_transfer_hbar_default(context)];
}
};
export {
index_default as default
};
//# sourceMappingURL=index.mjs.map
Loading