@runloop/runloop
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Runloop

The Runloop Library is a powerful tool for managing asynchronous operations in TypeScript or JavaScript. It provides a simple and intuitive way to declare and execute Runloop lambda functions and developer boxes, allowing you to control the flow of your asynchronous AI agents.

Installation

To install the Runloop Library, simply run the following command:

npm install @runloop/runloop

Getting started

To use the Runloop Library in your project, first import the package and use RLFunc providing an async function to execute and a function ID which will also be used to execute against your function.

import { RLFunc } from '@runloop/runloop';

export const lintCode = RLFunc({
    id: "add",
    run: async function ({ a: number, b: number }) {
        return a + b;
    },
});

Make sure to install the Runloop github app Once you've installed the app and selected your project you can run your add function above with the following cURL:

curl -X 'POST' 'https://api.runloop.pro/v1/projects/<project_id>/functions/lintCode/invoke_blocking' -H 'accept: application/json' -H "Authorization: Bearer <api_key>" --data '{"request": {"a": 2, "b": 2 }}'
> '{ "result": 4 }'

Create a Devbox

Now that you've made a basic function, let's create a devbox and run some commands on it.

import { RLFunc } from '@runloop/runloop';

export const useDevbox = RLFunc({
    id: "useDevbox",
    run: async function ({}, { systemCoordinator }) {
        let devbox = await systemCoordinator.createDevbox();
        let result = await devbox.execTool.exec("echo 'Hello, World!'");
        return result.stdout;
    },
});

Devboxes allow you to interact with them through the FileTool and ExecTool interfaces.

/**
 * A Runloop devbox allowing for remote development. This is a virtual machine that can be used for development.
 */
export type IDevbox = {
    /**
     * Tools that can be used with the Devbox
     */
    id: string;

    /**
     * This allows for reading and writing files on the remote machine.
     */
    fileTool: IFileTool;

    /**
     * This allows for executing commands on the remote machine.
     */
    execTool: IExecTool;
};

export type FileTool = {
    /**
     * Write content to a file on the remote machine.
     * @param path the path to the file to write on the remote machine
     * @param content the content to write to the file
     * @returns when the file has been written
     */
    writeFile: (path: string, content: string) => Promise<void>;

    /**
     * Read the contents of a file on the remote machine.
     * @param path the path to the file to read on the remote machine
     * @returns the contents of the file in utf-8 encoding
     */
    readFile: (path: string) => Promise<string>;

    /**
     * Delete a file on the remote machine.
     * @param path the path to the file to delete on the remote machine
     * @returns when the file has been deleted
     */
    deleteFile: (path: string) => Promise<void>;

    /**
     * Create a file on the remote machine with the given content
     * @param path the path to the file to create on the remote machine
     * @param content the content to write to the file
     * @returns
     */
    createFile: (path: string, content: string) => Promise<void>;
};

/**
 * A tool for executing commands on a remote machine.
 */
export type ExecTool = {
    /**
     * Execute a command on the remote machine.
     * @param command the command to execute on the remote machine
     * @returns the result of executing the command
     */
    exec: (command: string) => Promise<ExecResult>;
};

Readme

Keywords

none

Package Sidebar

Install

npm i @runloop/runloop

Weekly Downloads

0

Version

0.0.5

License

GPL-3.0-or-later

Unpacked Size

12.5 kB

Total Files

6

Last publish

Collaborators

  • runloopnpmuser