Skip to content

Conversation

@johnagentify
Copy link

@johnagentify johnagentify commented Sep 28, 2024

User description

Project Title: PotLock AI Agent Plugin

Project Description:
The PotLock AI Agent Plugin is designed to enhance the fundraising experience on the PotLock platform. This plugin facilitates seamless interactions for users, allowing them to create fundraising projects, make donations, and manage their profiles effortlessly. With AI assistance, users receive guided prompts that streamline the process of setting up their profiles and engaging with various projects, ultimately fostering community involvement.

Technologies Used:

Node.js: The server-side runtime environment for building the API.
NEAR Blockchain: For secure interactions and management of fundraising activities and user data.
OpenAI: Utilized for generating AI-driven prompts and guidance throughout user interactions.

Working Demo Link:


PR Type

Enhancement, Documentation


Description

  • Implemented project management routes and NEAR blockchain integration for creating and fetching projects.
  • Added utility functions for handling project registrations, donations, and storage management.
  • Set up Express server with routes for project and donation management.
  • Defined constants for NEAR blockchain configuration.
  • Added OpenAPI specification for PotLock API and included metadata for AI assistant integration.
  • Provided detailed README with project introduction, key features, user flow, and deployment instructions.

Changes walkthrough 📝

Relevant files
Enhancement
6 files
project.js
Implement project management routes and NEAR integration 

potlock-ai-agent/routes/project.js

  • Added routes for fetching, creating, and managing projects.
  • Implemented error handling for project-related operations.
  • Integrated NEAR blockchain interactions for project data.
  • +227/-0 
    potlockUtils.js
    Add utility functions for project and donation management

    potlock-ai-agent/utils/potlockUtils.js

  • Added utility functions for fetching project registrations and
    donations.
  • Implemented NEAR blockchain queries for project and donation data.
  • Enhanced error handling for utility functions.
  • +199/-0 
    donation.js
    Implement donation management routes and NEAR integration

    potlock-ai-agent/routes/donation.js

  • Added routes for fetching donations by recipient and donor.
  • Implemented donation creation route with NEAR blockchain interaction.
  • Included error handling for donation-related operations.
  • +113/-0 
    utils.js
    Add utility functions for storage and data management       

    potlock-ai-agent/utils/utils.js

  • Added utility functions for storage management and data size
    estimation.
  • Implemented NEAR blockchain queries for storage data.
  • Enhanced error handling for utility functions.
  • +69/-0   
    nearSocialUtils.js
    Add utility function for fetching social profile data       

    potlock-ai-agent/utils/nearSocialUtils.js

  • Added utility function to fetch social profile data from NEAR
    blockchain.
  • Implemented error handling for profile fetching.
  • +37/-0   
    app.js
    Set up Express server with project and donation routes     

    potlock-ai-agent/app.js

  • Set up Express server with routes for project and donation management.
  • Configured middleware and static file serving.
  • Added basic route for health check.
  • +23/-0   
    Configuration changes
    2 files
    constants.js
    Define constants for NEAR blockchain configuration             

    potlock-ai-agent/utils/constants.js

  • Defined constants for NEAR blockchain contract IDs and network
    configuration.
  • +15/-0   
    package.json
    Initialize package.json with project metadata                       

    potlock-ai-agent/package.json

  • Initialized package.json with project metadata and dependencies.
  • Defined scripts for starting the server.
  • +20/-0   
    Documentation
    2 files
    ai-plugin.json
    Add OpenAPI specification for PotLock API                               

    potlock-ai-agent/public/.well-known/ai-plugin.json

  • Added OpenAPI specification for PotLock API.
  • Defined endpoints for project and donation management.
  • Included metadata for AI assistant integration.
  • +379/-0 
    README.md
    Add README with project details and usage guide                   

    potlock-ai-agent/README.md

  • Added project introduction and key features.
  • Provided user flow and API endpoint details.
  • Included deployment instructions and usage guide.
  • +100/-0 
    Additional files (token-limit)
    1 files
    package-lock.json
    ...                                                                                                           

    potlock-ai-agent/package-lock.json

    ...

    +1572/-0

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @vercel
    Copy link

    vercel bot commented Sep 28, 2024

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    templates ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2024 0:37am
    templates-blogchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2024 0:37am
    templates-coingecko-ai-plugin-simple ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2024 0:37am
    templates-contract-deployer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 28, 2024 0:37am

    @vercel
    Copy link

    vercel bot commented Sep 28, 2024

    @Johnson-8844 is attempting to deploy a commit to the Mintbase Team on Vercel.

    A member of the Team first needs to authorize it.

    @mintbase-codium-pr-agent
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive Information Exposure:
    The application logs sensitive information such as account IDs and transaction details, which could lead to information disclosure if logs are not properly secured.

    ⚡ Key issues to review

    Error Handling
    The error handling in the POST route for creating a project does not provide specific error messages related to the NEAR blockchain interactions. It's recommended to include more detailed error handling to help developers understand the specific blockchain-related issues that might occur.

    Data Validation
    The POST route for creating a project lacks comprehensive validation for input data such as categories, smartContracts, githubRepos, fundingSources, and team. Proper validation should be implemented to ensure data integrity and prevent potential issues.

    Logging Sensitive Data
    The code logs potentially sensitive data, such as account IDs and transaction details. It's advisable to avoid logging sensitive information or to ensure that logs are properly secured and comply with data protection regulations.

    Floating Point Arithmetic
    The function calculateNearAmount uses floating point arithmetic to calculate NEAR amounts, which can lead to precision errors. Consider using a library designed for safe arithmetic operations with cryptocurrencies.

    @mintbase-codium-pr-agent
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Update the deprecated base-x package to the recommended newer version

    Update the base-x dependency to version 3.0.0 as suggested by the deprecation
    message in the existing code. This will ensure compatibility and access to the
    latest features and bug fixes.

    potlock-ai-agent/package-lock.json [227-236]

    -"base-x": "^2.0.6"
    +"base-x": "^3.0.0"
     
    Suggestion importance[1-10]: 9

    Why: Updating to the newer version of base-x addresses the deprecation warning and ensures compatibility with the latest features and bug fixes, which is crucial for maintaining the stability and security of the project.

    9
    Change the data type of the amount field from string to number to ensure proper numeric validation

    Consider using a more specific type than string for the amount field in the donation
    schema. Using a numeric type such as number or integer can help in validating the
    input more accurately and avoid potential issues with numeric operations.

    potlock-ai-agent/public/.well-known/ai-plugin.json [226-227]

     "amount": {
    -    "type": "string",
    +    "type": "number",
         "description": "Donation amount in NEAR tokens"
     }
     
    Suggestion importance[1-10]: 9

    Why: Changing the amount field to number ensures proper numeric validation and prevents potential issues with numeric operations, which is crucial for handling donations accurately.

    9
    Add a regex pattern to validate the recipientId and donorId fields to ensure they adhere to a specific format

    The recipientId and donorId fields are described as account IDs but are of type
    string. For better validation and to ensure the format of these IDs, consider using
    a regex pattern in the schema to validate the format of the account IDs if they have
    a specific structure.

    potlock-ai-agent/public/.well-known/ai-plugin.json [222-223]

     "recipientId": {
         "type": "string",
    +    "pattern": "^[a-zA-Z0-9_.-]*$",
         "description": "The recipient's account Id"
     }
     
    Suggestion importance[1-10]: 8

    Why: Adding a regex pattern for recipientId and donorId fields enhances validation by ensuring the IDs conform to a specific format, improving data integrity and reducing errors.

    8
    Add URI validation for profileImage and bannerImage fields to ensure they contain valid URLs

    The profileImage and bannerImage fields are currently of type string which implies
    any string is acceptable. It's recommended to validate these fields to ensure they
    contain valid URLs by using the format keyword with a value of uri.

    potlock-ai-agent/public/.well-known/ai-plugin.json [120-126]

     "profileImage": {
         "type": "string",
    +    "format": "uri",
         "description": "URL of the profile image for the project."
     },
     "bannerImage": {
         "type": "string",
    +    "format": "uri",
         "description": "URL of the banner image for the project."
     }
     
    Suggestion importance[1-10]: 8

    Why: Adding URI validation for profileImage and bannerImage fields ensures that these fields contain valid URLs, enhancing data quality and preventing potential issues with invalid URLs.

    8
    Simplify conditional assignment using a ternary operator

    Use a ternary operator to simplify the conditional assignment of amount to improve
    code readability and reduce redundancy.

    potlock-ai-agent/routes/project.js [156-159]

    -if (dataSize > availableBytes) {
    -    const extraSize = dataSize - availableBytes;
    -    console.log("Extra Size >> ", extraSize);
    -    amount = calculateNearAmount(extraSize);
    -}
    +const extraSize = dataSize > availableBytes ? dataSize - availableBytes : 0;
    +console.log("Extra Size >> ", extraSize);
    +amount = extraSize > 0 ? calculateNearAmount(extraSize) : 0;
     
    Suggestion importance[1-10]: 7

    Why: The suggestion simplifies the code and improves readability by reducing redundancy. However, the original code is already clear and functional, so the improvement is minor.

    7
    Enhance the error schema for 500 status code responses to include structured error information

    The error handling for the 500 status code in various endpoints only returns a
    string type error message. It would be beneficial to include more structured error
    information, such as an error code or additional details to help in debugging.

    potlock-ai-agent/public/.well-known/ai-plugin.json [191-203]

     "500": {
         "description": "Internal Server Error",
         "content": {
             "application/json": {
                 "schema": {
                     "type": "object",
                     "properties": {
                         "error": {
    -                        "type": "string"
    +                        "type": "object",
    +                        "properties": {
    +                            "code": {
    +                                "type": "integer"
    +                            },
    +                            "message": {
    +                                "type": "string"
    +                            }
    +                        }
                         }
                     }
                 }
             }
         }
     }
     
    Suggestion importance[1-10]: 7

    Why: Including structured error information for 500 status code responses aids in debugging and provides more detailed error context, improving maintainability and support.

    7
    Possible issue
    Improve error handling for parsing integers

    Add error handling for parsing integers from request queries to handle potential NaN
    values gracefully.

    potlock-ai-agent/routes/project.js [18-19]

    -const limit = parseInt(req.query.limit, 10) || 10;
    -const offset = parseInt(req.query.offset, 10) || 0;
    +const limit = Number.isNaN(parseInt(req.query.limit, 10)) ? 10 : parseInt(req.query.limit, 10);
    +const offset = Number.isNaN(parseInt(req.query.offset, 10)) ? 0 : parseInt(req.query.offset, 10);
     
    Suggestion importance[1-10]: 9

    Why: Adding error handling for parsing integers is crucial for preventing potential runtime errors and ensuring the application handles invalid input gracefully. This improves robustness and reliability.

    9
    Maintainability
    Replace hardcoded contract ID with a constant

    Replace the hardcoded string 'potlock.near' with a constant from the 'constants.js'
    file to maintain consistency and ease future changes.

    potlock-ai-agent/routes/project.js [104]

    -key: "potlock.near",
    +key: NEAR_SOCIAL_DB_CONTRACT_ID,
     
    Suggestion importance[1-10]: 8

    Why: Using a constant instead of a hardcoded string improves maintainability and consistency, making future changes easier. This is a good practice for managing configuration values.

    8
    Combine multiple log statements into one

    Combine the multiple console.log statements into a single statement to reduce
    redundancy and improve code cleanliness.

    potlock-ai-agent/routes/project.js [51-162]

    -console.log("body >>", body);
    -console.log(`Amount:${amount}, available:${availableBytes}, dataSize:${dataSize}, demo:${demo}`);
    -console.log("Extra Size >> ", extraSize);
    -console.log(`Amount:${amount}, available:${availableBytes}, dataSize:${dataSize}, demo:${demo}`);
    +console.log("body >>", body, `Amount:${amount}, available:${availableBytes}, dataSize:${dataSize}, demo:${demo}`, "Extra Size >> ", extraSize);
     
    Suggestion importance[1-10]: 6

    Why: Combining log statements can improve code cleanliness and reduce redundancy, but it may also reduce readability if the log message becomes too complex. This is a minor improvement.

    6
    Security
    Update negotiator to the latest version to enhance security and compatibility

    Update the negotiator dependency to the latest version to address potential security
    vulnerabilities and maintain compatibility with the latest standards.

    potlock-ai-agent/package-lock.json [196]

    -"negotiator": "0.6.3"
    +"negotiator": "^0.7.0"
     
    Suggestion importance[1-10]: 8

    Why: Updating the negotiator dependency to the latest version is important for addressing potential security vulnerabilities and maintaining compatibility with the latest standards, which is beneficial for the overall security of the project.

    8
    Best practice
    Update the Node.js engine version requirement to a more recent version for better compatibility and security

    Consider updating the node engine requirement for @noble/hashes to a more recent
    version to ensure compatibility with newer Node.js features and security updates.

    potlock-ai-agent/package-lock.json [178-180]

    -"node": ">= 16"
    +"node": ">= 18"
     
    Suggestion importance[1-10]: 7

    Why: While updating the Node.js engine version can improve compatibility and security, it may also require users to upgrade their Node.js installations, which could be a minor inconvenience.

    7

    @microchipgnu
    Copy link
    Member

    Are you planning to implement making donations to projects?

    @johnagentify
    Copy link
    Author

    Are you planning to implement making donations to projects?

    we can already do donations using this agent. its implemented

    @microchipgnu
    Copy link
    Member

    Are you planning to implement making donations to projects?

    we can already do donations using this agent. its implemented

    I wasn't able to do it. Can you share a chat link where you perform a donation? No need to go through the transaction, just show that a valid transaction is getting generated.

    @johnagentify
    Copy link
    Author

    johnagentify commented Oct 9, 2024

    Are you planning to implement making donations to projects?

    we can already do donations using this agent. its implemented

    I wasn't able to do it. Can you share a chat link where you perform a donation? No need to go through the transaction, just show that a valid transaction is getting generated.

    check this please - https://wallet.bitte.ai/smart-actions/share/ujlf3EqJ_LXR4j7YXsk6-

    @microchipgnu
    Copy link
    Member

    Are you planning to implement making donations to projects?

    we can already do donations using this agent. its implemented

    I wasn't able to do it. Can you share a chat link where you perform a donation? No need to go through the transaction, just show that a valid transaction is getting generated.

    check this please - https://wallet.bitte.ai/smart-actions/share/ujlf3EqJ_LXR4j7YXsk6-

    Can you make this work similarly to how I described in #194 (comment)

    @johnagentify
    Copy link
    Author

    Working Demo Link

    Are you planning to implement making donations to projects?

    we can already do donations using this agent. its implemented

    I wasn't able to do it. Can you share a chat link where you perform a donation? No need to go through the transaction, just show that a valid transaction is getting generated.

    check this please - https://wallet.bitte.ai/smart-actions/share/ujlf3EqJ_LXR4j7YXsk6-

    Can you make this work similarly to how I described in #194 (comment)

    hi @microchipgnu your feedback is incorporated. reference chat link here - https://wallet.bitte.ai/smart-actions/share/dNXFYVULscIcMlXaqQyE1

    @Markeljan Markeljan assigned Markeljan and unassigned Markeljan Nov 5, 2024
    Copy link
    Contributor

    @Markeljan Markeljan left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Fetching works well, listing projects + project details. Transactions generated don't seem to work for me.

    Adding the transaction[] type you can try returning as json that our generate-transaction expects.

    export interface FunctionCallAction { type: "FunctionCall"; params: { methodName: string; args: object; gas: string; deposit: string; }; }

    export interface Transaction { signerId: string; receiverId: string; actions: Array<FunctionCallAction>; }

    @Johnson-8844
    Copy link

    Johnson-8844 commented Nov 7, 2024

    Fetching works well, listing projects + project details. Transactions generated don't seem to work for me.

    Adding the transaction[] type you can try returning as json that our generate-transaction expects.

    export interface FunctionCallAction { type: "FunctionCall"; params: { methodName: string; args: object; gas: string; deposit: string; }; }

    export interface Transaction { signerId: string; receiverId: string; actions: Array<FunctionCallAction>; }

    This works for me, and our API correctly returns an array of transaction data objects. However, sometimes the AI sends requests with incorrect fields, which causes our API to return incorrect calculations or error messages. Could you please suggest any solutions to help address this issue?

    Here’s the working transaction chat link: https://wallet.bitte.ai/smart-actions/share/Co2GaFDxDAinhoi52agOu

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 4

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants