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

- feature: execute from code files #69

Merged
merged 3 commits into from
Nov 25, 2024
Merged

Conversation

agallardol
Copy link
Contributor

@agallardol agallardol commented Nov 25, 2024

Refactor code from string with CodeFiles struct

  1. Added a new CodeFiles struct to represent the code files for a tool, including a map of file paths to contents and an entrypoint file path. This replaces passing around a single code string.

  2. Updated the DenoExecutionStorage struct to take a CodeFiles instead of a code string in its constructor. It now writes out all the files in CodeFiles when initializing the storage directories.

  3. Updated the DenoRunner to take a CodeFiles instead of a code string when running. It passes this through to the DenoExecutionStorage.

  4. Updated tests to construct CodeFiles structs instead of passing code strings directly. For example:

Example

    let main_code = r#"
        import { helper } from "./helper.ts";
        import { data } from "./data.ts";
        
        function run() {
            return helper(data);
        }
    "#;

    let helper_code = r#"
        export function helper(input: string) {
            return `processed ${input}`;
        }
    "#;

    let data_code = r#"
        export const data = "test data";
    "#;

    let code_files = CodeFiles {
        files: HashMap::from([
            ("main.ts".to_string(), main_code.to_string()),
            ("helper.ts".to_string(), helper_code.to_string()),
            ("data.ts".to_string(), data_code.to_string()),
        ]),
        entrypoint: "main.ts".to_string(),
    };

    let tool = Tool::new(code_files, Value::Null, None);
    let result = tool.run(None, Value::Null, None).await;
    
    assert!(result.is_ok());
    assert_eq!(result.unwrap().data, "processed test data");

@agallardol agallardol merged commit f9f1b79 into main Nov 25, 2024
1 check failed
@agallardol agallardol deleted the agallardol/feature-code-files branch November 25, 2024 15:48
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

Successfully merging this pull request may close these issues.

1 participant