diff --git a/packages/plugin-b2/package.json b/packages/plugin-b2/package.json index 84727b1ac1d79..90c41a65080a7 100644 --- a/packages/plugin-b2/package.json +++ b/packages/plugin-b2/package.json @@ -5,7 +5,8 @@ "type": "module", "types": "dist/index.d.ts", "dependencies": { - "@elizaos/core": "workspace:*" + "@elizaos/core": "workspace:*", + "tsup": "8.3.5" }, "devDependencies": { "tsup": "8.3.5", diff --git a/packages/plugin-b2/src/actions/sampleAction.ts b/packages/plugin-b2/src/actions/sampleAction.ts deleted file mode 100644 index 7f835dac0a5aa..0000000000000 --- a/packages/plugin-b2/src/actions/sampleAction.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { - Action, - IAgentRuntime, - Memory, - HandlerCallback, - State, - composeContext, - generateObject, - ModelClass, - elizaLogger, -} from "@elizaos/core"; - -import { CreateResourceSchema, isCreateResourceContent } from "../types"; - -import { createResourceTemplate } from "../templates"; - -export const createResourceAction: Action = { - name: "CREATE_RESOURCE", - description: "Create a new resource with the specified details", - validate: async (runtime: IAgentRuntime, _message: Memory) => { - return !!runtime.character.settings.secrets?.API_KEY; - }, - handler: async ( - runtime: IAgentRuntime, - _message: Memory, - state: State, - _options: any, - callback: HandlerCallback - ) => { - try { - const context = composeContext({ - state, - template: createResourceTemplate, - }); - - const resourceDetails = await generateObject({ - runtime, - context, - modelClass: ModelClass.SMALL, - schema: CreateResourceSchema, - }); - - if (!isCreateResourceContent(resourceDetails.object)) { - callback({ text: "Invalid resource details provided." }, []); - return; - } - - // persist relevant data if needed to memory/knowledge - // const memory = { - // type: "resource", - // content: resourceDetails.object, - // timestamp: new Date().toISOString() - // }; - - // await runtime.storeMemory(memory); - - callback( - { - text: `Resource created successfully: -- Name: ${resourceDetails.object.name} -- Type: ${resourceDetails.object.type} -- Description: ${resourceDetails.object.description} -- Tags: ${resourceDetails.object.tags.join(", ")} - -Resource has been stored in memory.`, - }, - [] - ); - } catch (error) { - elizaLogger.error("Error creating resource:", error); - callback( - { text: "Failed to create resource. Please check the logs." }, - [] - ); - } - }, - examples: [ - [ - { - user: "{{user1}}", - content: { - text: "Create a new resource with the name 'Resource1' and type 'TypeA'", - }, - }, - { - user: "{{agentName}}", - content: { - text: `Resource created successfully: -- Name: Resource1 -- Type: TypeA`, - }, - }, - ], - [ - { - user: "{{user1}}", - content: { - text: "Create a new resource with the name 'Resource2' and type 'TypeB'", - }, - }, - { - user: "{{agentName}}", - content: { - text: `Resource created successfully: -- Name: Resource2 -- Type: TypeB`, - }, - }, - ], - ], -}; diff --git a/packages/plugin-b2/src/actions/transfer.ts b/packages/plugin-b2/src/actions/transfer.ts new file mode 100644 index 0000000000000..9d14bfde12f16 --- /dev/null +++ b/packages/plugin-b2/src/actions/transfer.ts @@ -0,0 +1,20 @@ +import { Action , type IAgentRuntime, type Memory, type State, type HandlerCallback } from "@elizaos/core"; + +export const transferAction: Action = { + name: "B2_TRANSFER", + description: "Transfer B2 gas token between addresses on the B2 network", + handler: async ( + runtime: IAgentRuntime, + message: Memory, + state?: State, + option?: any, + callback?: HandlerCallback + ) => { + return true; + }, + validate: async (runtime: IAgentRuntime) => { + return true; + }, + examples: [], + similes: ["SEND_B2_TOKEN", "TRANSFER_B2_TOKEN", "MOVE_B2_TOKEN"], +}; \ No newline at end of file diff --git a/packages/plugin-b2/src/evaluators/sampleEvalutor.ts b/packages/plugin-b2/src/evaluators/sampleEvalutor.ts deleted file mode 100644 index c6d48b071532f..0000000000000 --- a/packages/plugin-b2/src/evaluators/sampleEvalutor.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - Evaluator, - IAgentRuntime, - Memory, - State, - elizaLogger, -} from "@elizaos/core"; - -export const sampleEvaluator: Evaluator = { - alwaysRun: false, - description: "Sample evaluator for checking important content in memory", - similes: ["content checker", "memory evaluator"], - examples: [ - { - context: "Checking if memory contains important content", - messages: [ - { - action: "evaluate", - input: "This is an important message", - output: { - score: 1, - reason: "Memory contains important content.", - }, - }, - ], - outcome: "Memory should be evaluated as important", - }, - ], - handler: async (runtime: IAgentRuntime, memory: Memory, state: State) => { - // Evaluation logic for the evaluator - elizaLogger.log("Evaluating data in sampleEvaluator..."); - - // Example evaluation logic - if (memory.content && memory.content.includes("important")) { - elizaLogger.log("Important content found in memory."); - return { - score: 1, - reason: "Memory contains important content.", - }; - } else { - elizaLogger.log("No important content found in memory."); - return { - score: 0, - reason: "Memory does not contain important content.", - }; - } - }, - name: "sampleEvaluator", - validate: async (runtime: IAgentRuntime, memory: Memory, state: State) => { - // Validation logic for the evaluator - return true; - }, -}; diff --git a/packages/plugin-b2/src/index.ts b/packages/plugin-b2/src/index.ts index b16dd06142745..d23cc0d95337e 100644 --- a/packages/plugin-b2/src/index.ts +++ b/packages/plugin-b2/src/index.ts @@ -1,5 +1,13 @@ -import { samplePlugin } from "./plugins/samplePlugin"; +import { Plugin } from "@elizaos/core"; +import { transferAction } from "./actions/transfer"; +import { walletProvider } from "./providers/walletProvider"; -export * from "./plugins/samplePlugin"; - -export default samplePlugin; +export const b2Plugin: Plugin = { + name: "b2", + description: "B2 network plugin for Eliza", + actions: [transferAction], + providers: [walletProvider], + evaluators: [], + services: [], + clients: [], +}; diff --git a/packages/plugin-b2/src/plugins/samplePlugin.ts b/packages/plugin-b2/src/plugins/samplePlugin.ts deleted file mode 100644 index 90fd2898a16b5..0000000000000 --- a/packages/plugin-b2/src/plugins/samplePlugin.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Plugin } from "@elizaos/core"; -import { createResourceAction } from "../actions/sampleAction"; -import { sampleProvider } from "../providers/sampleProvider"; -import { sampleEvaluator } from "../evaluators/sampleEvalutor"; - -export const samplePlugin: Plugin = { - name: "sample", - description: "Enables creation and management of generic resources", - actions: [createResourceAction], - providers: [sampleProvider], - evaluators: [sampleEvaluator], - // separate examples will be added for services and clients - services: [], - clients: [], -}; diff --git a/packages/plugin-b2/src/providers/sampleProvider.ts b/packages/plugin-b2/src/providers/walletProvider.ts similarity index 55% rename from packages/plugin-b2/src/providers/sampleProvider.ts rename to packages/plugin-b2/src/providers/walletProvider.ts index d16f3ba6ddf27..ee9ec03574885 100644 --- a/packages/plugin-b2/src/providers/sampleProvider.ts +++ b/packages/plugin-b2/src/providers/walletProvider.ts @@ -6,9 +6,8 @@ import { elizaLogger, } from "@elizaos/core"; -export const sampleProvider: Provider = { +export const walletProvider: Provider = { get: async (runtime: IAgentRuntime, message: Memory, state: State) => { - // Data retrieval logic for the provider - elizaLogger.log("Retrieving data in sampleProvider..."); + elizaLogger.log("Retrieving data in walletProvider..."); }, }; diff --git a/packages/plugin-b2/src/templates.ts b/packages/plugin-b2/src/templates.ts deleted file mode 100644 index f9c0d965917a9..0000000000000 --- a/packages/plugin-b2/src/templates.ts +++ /dev/null @@ -1,60 +0,0 @@ -export const createResourceTemplate = ` -Extract the following details to create a new resource: -- **name** (string): Name of the resource -- **type** (string): Type of resource (document, image, video) -- **description** (string): Description of the resource -- **tags** (array): Array of tags to categorize the resource - -Provide the values in the following JSON format: - -\`\`\`json -{ - "name": "", - "type": "", - "description": "", - "tags": ["", ""] -} -\`\`\` - -Here are the recent user messages for context: -{{recentMessages}} -`; - -export const readResourceTemplate = ` -Extract the following details to read a resource: -- **id** (string): Unique identifier of the resource -- **fields** (array): Specific fields to retrieve (optional) - -Provide the values in the following JSON format: - -\`\`\`json -{ - "id": "", - "fields": ["", ""] -} -\`\`\` - -Here are the recent user messages for context: -{{recentMessages}} -`; - -export const updateResourceTemplate = ` -Extract the following details to update a resource: -- **id** (string): Unique identifier of the resource -- **updates** (object): Key-value pairs of fields to update - -Provide the values in the following JSON format: - -\`\`\`json -{ - "id": "", - "updates": { - "": "", - "": "" - } -} -\`\`\` - -Here are the recent user messages for context: -{{recentMessages}} -`; diff --git a/packages/plugin-b2/src/types.ts b/packages/plugin-b2/src/types.ts deleted file mode 100644 index ef7d49396317d..0000000000000 --- a/packages/plugin-b2/src/types.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { z } from "zod"; - -// Base resource schema -export const ResourceSchema = z.object({ - id: z.string().optional(), - name: z.string().min(1), - type: z.enum(["document", "image", "video"]), - description: z.string(), - tags: z.array(z.string()), -}); - -// Create resource schema -export const CreateResourceSchema = ResourceSchema.omit({ id: true }); - -// Read resource schema -export const ReadResourceSchema = z.object({ - id: z.string(), - fields: z.array(z.string()).optional(), -}); - -// Update resource schema -export const UpdateResourceSchema = z.object({ - id: z.string(), - updates: z.record(z.string(), z.any()), -}); - -// Type definitions -export type Resource = z.infer; -export type CreateResourceContent = z.infer; -export type ReadResourceContent = z.infer; -export type UpdateResourceContent = z.infer; - -// Type guards -export const isCreateResourceContent = ( - obj: any -): obj is CreateResourceContent => { - return CreateResourceSchema.safeParse(obj).success; -}; - -export const isReadResourceContent = (obj: any): obj is ReadResourceContent => { - return ReadResourceSchema.safeParse(obj).success; -}; - -export const isUpdateResourceContent = ( - obj: any -): obj is UpdateResourceContent => { - return UpdateResourceSchema.safeParse(obj).success; -}; - -// Plugin configuration type -export interface ExamplePluginConfig { - apiKey: string; - apiSecret: string; - endpoint?: string; -}