Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache for repo configs #111

Open
Keyrxng opened this issue Sep 11, 2024 · 3 comments
Open

Cache for repo configs #111

Keyrxng opened this issue Sep 11, 2024 · 3 comments

Comments

@Keyrxng
Copy link
Contributor

Keyrxng commented Sep 11, 2024

It's kinda annoying that the kernel must fetch from both config locations on every request and more often than not only one is needed.

Cons:

  • unnecessary use of rate limit
  • clogs up the terminal

Solution:

  • Could be solved with a KV or in memory cache
  • After n requests we re-fetch from the repo just in case
  • clean terminal and less rate limit used

Do you think this would be a good thing to implement @whilefoo?

@0x4007
Copy link
Member

0x4007 commented Sep 11, 2024

We need to minimize the use of KV and rely more on the GitHub API because we have tighter limits on the Cloudflare side.

@Keyrxng
Copy link
Contributor Author

Keyrxng commented Oct 27, 2024

@UbiquityOS Explain how to install and run the kernel, and install text-conversation-rewards plugin

Copy link

Sure! Here's a step-by-step guide to installing and running the UbiquityOS kernel, as well as installing the text-conversation-rewards plugin.

1. Clone the UbiquityOS Kernel Repository

Begin by cloning the UbiquityOS kernel repository to your local machine:

git clone https://github.com/ubiquity-os/ubiquity-os-kernel.git
cd ubiquity-os-kernel

2. Install Dependencies

Ensure you have Bun installed, as it's required for managing dependencies and running the project.

bun install

3. Create and Configure a GitHub App

  1. Generate a GitHub App:

    • Navigate to your GitHub settings and create a new GitHub App.
    • Configure the necessary permissions:
      • Repository Permissions:
        • Actions: Read & Write
        • Contents: Read & Write
        • Issues: Read & Write
        • Pull Requests: Read & Write
      • Organization Permissions:
        • Members: Read-only
    • Subscribe to all relevant events your kernel will handle.
  2. Obtain Credentials:

    • App ID: Retrieve this from your GitHub App settings.

    • Private Key: Generate a private key in PKCS8 format. Use the following command to convert your PEM file:

      openssl pkcs8 -topk8 -inform pem -outform pem -nocrypt -in yourappprivatekey.pem -out appprivatekey.pem
    • Webhook Secret: Set this value in both your GitHub App settings and your kernel configuration.

4. Set Up Cloudflare Account and KV Namespace

  1. Create a Cloudflare Account: If you don't have one, sign up at Cloudflare.

  2. Install Wrangler CLI: Wrangler is Cloudflare's command-line tool for managing Workers.

    npm install -g wrangler
  3. Login to Cloudflare:

    wrangler login
  4. Create a KV Namespace:

    wrangler kvnamespace create pluginchainstate
    • Note the generated Namespace ID and add it to your wrangler.toml under the [env.dev] section:

      [env.dev]
      kv_namespaces = [{ binding = "PLUGINCHAINSTATE", id = "your-generated-id" }]

5. Manage Environment Secrets

Add the necessary environment variables and secrets required by the kernel:

  1. App Private Key:

    wrangler secret put appprivatekey --env dev < path/to/appprivatekey.pem
  2. Other Secrets:

    • appwebhooksecret: Your GitHub App's webhook secret.
    • appid: Your GitHub App ID.
    • webhookproxyurl: Only required for development purposes.

    Add these using:

    wrangler secret put appwebhooksecret --env dev
    wrangler secret put appid --env dev
    wrangler secret put webhookproxyurl --env dev

    You'll be prompted to enter the values for each secret.

6. Deploy the Kernel to Cloudflare Workers

Deploy your kernel using the following command:

bun run deploy-dev

This command will build and deploy your kernel to the Cloudflare Workers environment.

7. Install the text-conversation-rewards Plugin

  1. Clone or Fork the Plugin:

    • Ensure the text-conversation-rewards plugin is available within the ubiquity-os-marketplace organization. If it's an official plugin, transfer it there; otherwise, fork it.
  2. Fetch Plugin Manifests:

    • The kernel will fetch the manifest.json from each plugin repository to understand its configuration and dependencies.
  3. Update Kernel Configuration:

    • Edit the ubiquity-osconfig.yml file in your kernel repository to include the text-conversation-rewards plugin:

      plugins:
        - text-conversation-rewards
  4. Deploy Updated Configuration:

    bun run deploy-dev

8. Running the Kernel and Plugin

  1. Start the Kernel in Development Mode:

    bun dev
  2. Trigger Plugin Functionality:

    • For example, if the text-conversation-rewards plugin responds to issue comments, post a relevant comment in your GitHub repository to trigger the plugin.
  3. Verify Plugin Response:

    • Ensure that the plugin processes the event and responds as expected, such as posting a rewards summary.

9. Additional Configuration and Testing

  • Caching Mechanism:

    • Implement caching similar to work.ubq.fi to minimize GitHub API rate limits and reduce terminal clutter.
  • Testing with Jest:

    • Run tests to ensure everything is functioning correctly:

      bun test
  • Handling Permits:

    • The kernel manages permits similarly to comments, ensuring that each plugin's output includes necessary metadata like the run ID from Cloudflare KV.

10. Quick Start Example

Here’s a brief example to get you started with a "hello-world" plugin, which follows similar steps to the text-conversation-rewards plugin:

  1. Run the Kernel:

    bun dev
  2. Run the Hello-World Plugin:

    bun plugin hello-world
  3. Update Configuration:

    • Add the hello-world plugin to ubiquity-osconfig.yml:

      plugins:
        - hello-world-plugin
  4. Trigger the Plugin:

    • Post a /hello comment in any issue. The bot should respond with a "world" message.

Resources and References

Summary

By following the steps outlined above, you will set up the UbiquityOS kernel, configure necessary secrets and environment variables, deploy the kernel to Cloudflare Workers, and install the text-conversation-rewards plugin. Ensure you replace placeholder URLs and file paths with your actual configuration details. For any issues or further customization, refer to the linked resources and repository documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants