ComposioHQ / composio

Composio equip's your AI agents & LLMs with 100+ high-quality integrations via function calling
https://docs.composio.dev
Other
7.47k stars 2.33k forks source link

fix: types for cloudflare framework #358

Closed utkarsh-dixit closed 1 month ago

utkarsh-dixit commented 1 month ago

PR Type

Enhancement, Bug fix


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
workspace.ts
Refactor DockerWorkspace to use dynamic module loading and type
annotations

js/src/env/docker/workspace.ts
  • Replaced direct imports with nodeExternalRequire for dynamic module
    loading.
  • Changed Docker.Container type to any for container property.
  • Added type annotations for cli-progress.
  • Moved path and os imports inside the setup method.
  • +18/-15 
    workspace.ts
    Use dynamic module loading and null checks in E2BWorkspace

    js/src/env/e2b/workspace.ts
  • Replaced direct imports with nodeExternalRequire for dynamic module
    loading.
  • Added null checks with ! operator for sandbox property.
  • +9/-8     
    base.ts
    Simplify Shell class by removing EventEmitter inheritance

    js/src/env/base.ts - Removed `EventEmitter` inheritance from `Shell` class.
    +1/-3     
    shared.ts
    Add utility function for dynamic module loading                   

    js/src/utils/shared.ts - Added `nodeExternalRequire` function for dynamic module loading.
    +12/-0   
    Configuration changes
    wrangler.toml
    Enable Node.js compatibility in Wrangler configuration     

    js/wrangler.toml - Added `node_compat = true` to enable Node.js compatibility.
    +1/-0     
    Additional files (token-limit)
    pnpm-lock.yaml
    ...                                                                                                           

    js/examples/ai-playground-main/pnpm-lock.yaml ...
    +524/-1118

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

    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 3 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšชโšช
    ๐Ÿงช No relevant tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Type Safety
    The `container` property in `DockerWorkspace` class is typed as `any | null`. It's better to use a more specific type instead of `any` to improve type safety and maintainability. Dynamic Module Loading
    The use of `nodeExternalRequire` for dynamic module loading could lead to issues if not handled properly. Ensure that error handling and module availability are adequately addressed. Dynamic Import
    Dynamic importing of `Sandbox` from `@e2b/sdk` using `nodeExternalRequire` might introduce runtime errors if the module or its exports are not available. Consider adding checks to ensure the module is correctly loaded.
    codiumai-pr-agent-pro[bot] commented 1 month ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Maintainability
    Use consistent module import strategy across the project ___ **Replace the use of require("node:net") with nodeExternalRequire("node:net") to
    maintain consistency with the modular import strategy used elsewhere in the project.** [js/src/env/docker/workspace.ts [14]](https://github.com/ComposioHQ/composio/pull/358/files#diff-32ee46b296bb6f8b6057a91d605dddb67bf44959fd07877e17e416e0dae339edR14-R14) ```diff -const server = require("node:net").createServer(); +const server = nodeExternalRequire("node:net").createServer(); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This suggestion improves code consistency and maintainability by using the same import strategy throughout the project. It aligns with the modular import strategy used elsewhere in the code.
    9
    Improve type safety by specifying a more accurate type ___ **Use a more specific type for container property in DockerWorkspace class instead of
    any | null to improve type safety and code maintainability.** [js/src/env/docker/workspace.ts [26]](https://github.com/ComposioHQ/composio/pull/358/files#diff-32ee46b296bb6f8b6057a91d605dddb67bf44959fd07877e17e416e0dae339edR26-R26) ```diff -public container: any | null = null; +public container: Docker.Container | null = null; ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Specifying a more accurate type for the `container` property enhances type safety and code maintainability, reducing potential runtime errors.
    8
    Reduce redundancy and improve code clarity by centralizing command execution ___ **Replace the repeated calls to this.sandbox!.process.start with a single function
    that handles command execution to reduce redundancy and improve code clarity.** [js/src/env/e2b/workspace.ts [41-61]](https://github.com/ComposioHQ/composio/pull/358/files#diff-cce7e4a1da429213dd54779e75908f66b0ba1d55a1a6019114b770ff9f4e96e6R41-R61) ```diff -await this.sandbox!.process.start({ - cmd: "composio apps update", -}); -await this.sandbox!.process.start({ - cmd: `sudo useradd -rm -d /home/${_ssh_username} -s /bin/bash -g root -G sudo ${_ssh_username}`, -}); -await this.sandbox!.process.start({ - cmd: `echo ${_ssh_username}:${_ssh_password} | sudo chpasswd`, -}); -await this.sandbox!.process.start({ - cmd: "sudo service ssh restart", -}); -await this.sandbox!.process.start({ - cmd: `_SSH_USERNAME=${_ssh_username} _SSH_PASSWORD=${_ssh_password} COMPOSIO_LOGGING_LEVEL=debug composio serve -h '0.0.0.0' -p ${this.port}`, -}); +const executeCommand = async (cmd) => { + await this.sandbox!.process.start({ cmd }); +}; +await executeCommand("composio apps update"); +await executeCommand(`sudo useradd -rm -d /home/${_ssh_username} -s /bin/bash -g root -G sudo ${_ssh_username}`); +await executeCommand(`echo ${_ssh_username}:${_ssh_password} | sudo chpasswd`); +await executeCommand("sudo service ssh restart"); +await executeCommand(`_SSH_USERNAME=${_ssh_username} _SSH_PASSWORD=${_ssh_password} COMPOSIO_LOGGING_LEVEL=debug composio serve -h '0.0.0.0' -p ${this.port}`); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Centralizing command execution reduces redundancy and improves code clarity, making the code easier to maintain and understand. However, the improvement is more about code style than a critical fix.
    7
    Verify Node.js code compatibility with the node_compat setting to prevent runtime issues ___ **The node_compat setting is enabled in the wrangler.toml file. It's important to
    ensure that all Node.js code and dependencies are compatible with this setting to
    avoid runtime issues. Review and test all Node.js code to confirm compatibility.** [js/wrangler.toml [4]](https://github.com/ComposioHQ/composio/pull/358/files#diff-6fe115677ad41d7fa3c7a7df18b7530d24d361f2026ec28050465adb8bc415c4R4-R4) ```diff -node_compat = true +node_compat = true # Ensure all Node.js code is reviewed and tested for compatibility ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: Ensuring that all Node.js code is compatible with the `node_compat` setting is important for maintainability, but the suggestion is more of a reminder than a direct code improvement.
    6
    Best practice
    Ensure consistent module loading and better environment handling ___ **Replace the dynamic import of path and os modules with nodeExternalRequire to ensure
    consistency and potentially handle non-node environments better.** [js/src/env/docker/workspace.ts [97-98]](https://github.com/ComposioHQ/composio/pull/358/files#diff-32ee46b296bb6f8b6057a91d605dddb67bf44959fd07877e17e416e0dae339edR97-R98) ```diff -const path = require("node:path"); -const os = require("node:os"); +const path = nodeExternalRequire("node:path"); +const os = nodeExternalRequire("node:os"); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: This suggestion ensures consistency in module loading and potentially improves handling in non-node environments, which is a good practice for maintainability and robustness.
    9
    Update the Node.js version requirement to a supported version for better security and compatibility ___ **The engines field for @jridgewell/resolve-uri specifies a minimum Node.js version of
    6.0.0, which is outdated and no longer supported. It's recommended to update this to
    a more recent version to ensure security and compatibility with newer Node.js
    features.** [js/examples/ai-playground-main/pnpm-lock.yaml [218-219]](https://github.com/ComposioHQ/composio/pull/358/files#diff-52d637854db874e21b04c1a0b124cd991857ebf396920dbe5be4e0a5c965afeaR218-R219) ```diff '@jridgewell/resolve-uri@3.1.2': resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} - engines: {node: '>=6.0.0'} + engines: {node: '>=12.0.0'} # Updated to a supported version ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: Updating the Node.js version requirement to a more recent, supported version enhances security and compatibility, which is crucial for maintaining a secure and stable environment.
    9
    Ensure consistent and predictable dependency management by using exact versions ___ **It's recommended to use consistent versioning for dependencies to avoid potential
    conflicts and ensure compatibility. The @cloudflare/workers-types dependency is
    specified with a caret (^) which allows minor updates. However, the version
    installed is a specific version without allowing minor updates. This could lead to
    inconsistencies or unexpected behavior if the dependencies are not fully compatible.** [js/examples/ai-playground-main/pnpm-lock.yaml [18-20]](https://github.com/ComposioHQ/composio/pull/358/files#diff-52d637854db874e21b04c1a0b124cd991857ebf396920dbe5be4e0a5c965afeaR18-R20) ```diff '@cloudflare/workers-types': - specifier: ^4.20230419.0 + specifier: 4.20240620.0 version: 4.20240620.0 ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Using exact versions for dependencies helps in maintaining consistency and avoiding potential conflicts. This suggestion addresses a best practice for dependency management.
    8
    Specify compatible versions in peerDependencies to prevent potential compatibility issues ___ **The engines field specifies a minimum Node.js version of 12 for
    @esbuild-plugins/node-globals-polyfill, but the peerDependencies field specifies any
    version of esbuild. This could lead to compatibility issues if esbuild versions not
    compatible with Node.js 12 are used. It's safer to specify a compatible esbuild
    version range.** [js/examples/ai-playground-main/pnpm-lock.yaml [71-74]](https://github.com/ComposioHQ/composio/pull/358/files#diff-52d637854db874e21b04c1a0b124cd991857ebf396920dbe5be4e0a5c965afeaR71-R74) ```diff '@esbuild-plugins/node-globals-polyfill@0.2.3': resolution: {integrity: sha512-r3MIryXDeXDOZh7ih1l/yE9ZLORCd5e8vWg02azWRGj5SPTuoh69A2AIyn0Z31V/kHBfZ4HgWJ+OK3GTTwLmnw==} peerDependencies: - esbuild: '*' + esbuild: '>=0.8.0' # Assuming 0.8.0 is compatible with Node.js 12 ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Specifying a compatible version range for `peerDependencies` can prevent compatibility issues, especially with older Node.js versions. This is a good practice but not critical.
    7
    codiumai-pr-agent-pro[bot] commented 1 month ago

    CI Failure Feedback ๐Ÿง

    (Checks updated until commit https://github.com/ComposioHQ/composio/commit/1e628b5d137c3c06ccb89bd4615c14a0dc401ed0)

    **Action:** test (ubuntu-latest, 3.11)
    **Failed stage:** [Unittests](https://github.com/ComposioHQ/composio/actions/runs/10040486262/job/27746701391) [โŒ]
    **Failed test name:** test_action_enum
    **Failure summary:** The action failed because the test test_action_enum in the file tests/test_client/test_enum.py
    encountered a ValueError.
  • The error message was: "Invalid value GITHUB_ISSUES_LIST for Action".
  • This indicates that the value GITHUB_ISSUES_LIST is not a valid entry for the Action enum.
  • Relevant error logs: ```yaml 1: ##[group]Operating System 2: Ubuntu ... 504: * [new branch] fix/rag-agent -> origin/fix/rag-agent 505: * [new branch] fix/readme -> origin/fix/readme 506: * [new branch] fix/readme-logo -> origin/fix/readme-logo 507: * [new branch] fix/swe-agent -> origin/fix/swe-agent 508: * [new branch] ft-add-better-help-text -> origin/ft-add-better-help-text 509: * [new branch] ft-apps-id -> origin/ft-apps-id 510: * [new branch] ft-bring-back-core-sdk -> origin/ft-bring-back-core-sdk 511: * [new branch] ft-did-you-mean -> origin/ft-did-you-mean 512: * [new branch] ft-error-tracking -> origin/ft-error-tracking ... 928: tests/test_cli/test_actions.py::TestListActions::test_list_all[arguments3-exptected_outputs3-unexptected_outputs3] PASSED [ 17%] 929: tests/test_cli/test_actions.py::TestListActions::test_tag_not_found PASSED [ 19%] 930: tests/test_cli/test_actions.py::TestListActions::test_limit SKIPPED [ 21%] 931: tests/test_cli/test_actions.py::TestListActions::test_copy PASSED [ 23%] 932: tests/test_cli/test_add.py::TestComposioAdd::test_no_auth PASSED [ 25%] 933: tests/test_cli/test_apps.py::TestList::test_list PASSED [ 27%] 934: tests/test_cli/test_apps.py::TestUpdate::test_update_not_required PASSED [ 29%] 935: tests/test_cli/test_apps.py::TestUpdate::test_update SKIPPED (Needs 936: investigation, this test fails in CI) [ 31%] ... 944: tests/test_client/test_client.py::test_raise_invalid_api_key PASSED [ 48%] 945: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_trigger_objects_to_comma_separated_string PASSED [ 51%] 946: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_trigger_strings_to_comma_separated_string PASSED [ 53%] 947: tests/test_client/test_collections.py::TestTriggerNamesSerialization::test_converts_mix_of_trigger_objects_and_strings PASSED [ 55%] 948: tests/test_client/test_collections.py::test_trigger_subscription PASSED [ 57%] 949: tests/test_client/test_endpoints.py::test_endpoint PASSED [ 59%] 950: tests/test_client/test_enum.py::test_tag_enum PASSED [ 61%] 951: tests/test_client/test_enum.py::test_app_enum PASSED [ 63%] 952: tests/test_client/test_enum.py::test_action_enum FAILED [ 65%] ... 961: tests/test_tools/test_local/test_workspace.py::test_stderr PASSED [ 85%] 962: tests/test_tools/test_local/test_workspace.py::test_workspace PASSED [ 87%] 963: tests/test_utils/test_decorators.py::test_deprecated PASSED [ 89%] 964: tests/test_utils/test_git.py::test_get_git_user_info PASSED [ 91%] 965: tests/test_utils/test_shared.py::test_get_pydantic_signature_format_from_schema_params PASSED [ 93%] 966: tests/test_utils/test_shared.py::test_json_schema_to_pydantic_field PASSED [ 95%] 967: tests/test_utils/test_shared.py::test_json_schema_to_fields_dict PASSED [ 97%] 968: tests/test_utils/test_url.py::test_get_web_url PASSED [100%] 969: =================================== FAILURES =================================== ... 979: self = 980: value = 'GITHUB_ISSUES_LIST' 981: def __init__(self, value: t.Union[str, te.Self]) -> None: 982: """Create an Enum""" 983: if isinstance(value, _AnnotatedEnum): 984: value = value._slug 985: value = t.cast(str, value).upper() 986: if value not in self.__annotations__ and value not in _runtime_actions: 987: > raise ValueError(f"Invalid value `{value}` for `{self.__class__.__name__}`") 988: E ValueError: Invalid value `GITHUB_ISSUES_LIST` for `Action` 989: composio/client/enums/base.py:112: ValueError ... 994: .tox/unittests/lib/python3.11/site-packages/paramiko/pkey.py:100 995: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.11/site-packages/paramiko/pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0. 996: "cipher": algorithms.TripleDES, 997: .tox/unittests/lib/python3.11/site-packages/paramiko/transport.py:259 998: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.11/site-packages/paramiko/transport.py:259: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0. 999: "class": algorithms.TripleDES, 1000: .tox/unittests/lib/python3.11/site-packages/pydantic/_internal/_config.py:291 1001: .tox/unittests/lib/python3.11/site-packages/pydantic/_internal/_config.py:291 1002: /home/runner/work/composio/composio/python/.tox/unittests/lib/python3.11/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/ ... 1197: examples/Podcast_summarizer_Agents/Tools/composio_slack.py 4 4 0% 1-5 1198: examples/Podcast_summarizer_Agents/__init__.py 0 0 100% 1199: examples/Podcast_summarizer_Agents/main.py 15 15 0% 1-21 1200: -------------------------------------------------------------------------------------------------------------- 1201: TOTAL 9992 2323 77% 1202: Coverage HTML written to dir htmlcov 1203: Coverage XML written to file coverage.xml 1204: =========================== short test summary info ============================ 1205: FAILED tests/test_client/test_enum.py::test_action_enum - ValueError: Invalid value `GITHUB_ISSUES_LIST` for `Action` 1206: ============= 1 failed, 41 passed, 5 skipped, 5 warnings in 36.75s ============= 1207: unittests: exit 1 (37.66 seconds) /home/runner/work/composio/composio/python> pytest -vvv -rfE --doctest-modules composio/ tests/ --cov=composio --cov=examples --cov-report=html --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc pid=5767 1208: .pkg: _exit> python /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__ 1209: unittests: FAIL code 1 (83.80=setup[40.83]+cmd[5.31,37.66] seconds) 1210: evaluation failed :( (83.87 seconds) 1211: ##[error]Process completed with exit code 1. ```

    โœจ CI feedback usage guide:
    The CI feedback tool (`/checks)` automatically triggers when a PR has a failed check. The tool analyzes the failed checks and provides several feedbacks: - Failed stage - Failed test name - Failure summary - Relevant error logs In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR: ``` /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}" ``` where `{repo_name}` is the name of the repository, `{run_number}` is the run number of the failed check, and `{job_number}` is the job number of the failed check. #### Configuration options - `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true. - `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list. - `enable_help_text` - if set to true, the tool will provide a help message with the feedback. Default is true. - `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true. - `final_update_message` - if `persistent_comment` is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true. See more information about the `checks` tool in the [docs](https://pr-agent-docs.codium.ai/tools/ci_feedback/).