-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Utopian Labs new components #16812
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
base: master
Are you sure you want to change the base?
Utopian Labs new components #16812
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Skipped Deployments
|
""" WalkthroughA new Utopian Labs integration is introduced, including utility modules, constants, and multiple action modules for initiating and monitoring various agent runs (research, classification, copywriting, qualification, and timing). The app module is refactored to provide structured properties and encapsulated API client methods. Package metadata and dependencies are updated. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ActionModule
participant UtopianLabsApp
participant UtopianLabsAPI
User->>ActionModule: Provide input parameters
ActionModule->>UtopianLabsApp: initiateRun(args)
UtopianLabsApp->>UtopianLabsAPI: Create agent run (POST /agents/runs)
UtopianLabsAPI-->>UtopianLabsApp: Return run details
UtopianLabsApp-->>ActionModule: Return run details
ActionModule-->>User: Return summary and run details
User->>ActionModule: Provide run ID for status
ActionModule->>UtopianLabsApp: getRunStatus(runId)
UtopianLabsApp->>UtopianLabsAPI: Get run status (GET /agents/runs/{id})
UtopianLabsAPI-->>UtopianLabsApp: Return status
UtopianLabsApp-->>ActionModule: Return status
ActionModule-->>User: Return summary and status
Assessment against linked issues
Suggested labels
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
components/utopian_labs/actions/initiate-classification-run/initiate-classification-run.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/utopian_labs/actions/initiate-qualification-run/initiate-qualification-run.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs components/utopian_labs/actions/initiate-copywriting-run/initiate-copywriting-run.mjsOops! Something went wrong! :( ESLint: 8.57.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
⏰ Context from checks skipped due to timeout of 90000ms (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 12
🧹 Nitpick comments (9)
components/utopian_labs/actions/get-run-status/get-run-status.mjs (1)
17-21
: Consider adding explicit error handlingThe implementation is clean and follows Pipedream's component model. However, consider adding explicit error handling for cases where the API call might fail, providing a more user-friendly error message.
async run({ $ }) { - const response = await this.utopianLabs.getRunStatus(this.runId); - $.export("$summary", `Successfully retrieved status for run ${this.runId}`); - return response; + try { + const response = await this.utopianLabs.getRunStatus(this.runId); + $.export("$summary", `Successfully retrieved status for run ${this.runId}`); + return response; + } catch (error) { + $.export("$summary", `Failed to retrieve status for run ${this.runId}`); + throw error; + } },components/utopian_labs/common/utils.mjs (2)
3-9
: Add JSDoc comments to clarify function behaviorConsider adding JSDoc comments to explain what this function does, especially for edge cases. This will make the code more maintainable.
+/** + * Attempts to parse a value as JSON, returning the original value if parsing fails. + * + * @param {any} value - The value to parse + * @returns {any} The parsed JSON object or the original value if parsing fails + */ function optionalParseAsJSON(value) { try { return JSON.parse(value); } catch (e) { return value; } }
26-34
: Improve type handling in parseStringAsJSON
parseStringAsJSON
could be enhanced to handle non-string values more explicitly. Currently, if a non-string, non-object value is passed, it will simply return that value without validation.export function parseStringAsJSON(value) { try { - return typeof value === "string" - ? JSON.parse(value) - : value; + if (typeof value === "string") { + return JSON.parse(value); + } + if (typeof value === "object" && value !== null) { + return value; + } + throw new ConfigurationError(`Expected a JSON string or object, got ${typeof value}`); } catch (err) { throw new ConfigurationError(`Error parsing JSON string: ${err}`); } }components/utopian_labs/actions/initiate-copywriting-run/initiate-copywriting-run.mjs (1)
41-41
: Fix typo in language descriptionThere's a typo in the language property description.
- description: "The langauge to write the copy in (defaults to `en-US`)", + description: "The language to write the copy in (defaults to `en-US`)",components/utopian_labs/utopian_labs.app.mjs (3)
43-47
: Implement client caching for better performanceCreating a new client instance on every method call can be inefficient. Consider caching the client instance.
+ _clientInstance = null; _client() { + if (this._clientInstance) { + return this._clientInstance; + } - return new UtopianLabs({ + this._clientInstance = new UtopianLabs({ apiKey: this.$auth.api_key, }); + return this._clientInstance; },
48-50
: Add error handling to initiateRun methodThe initiateRun method currently doesn't handle potential API errors. Consider adding error handling for a more robust implementation.
initiateRun(args) { - return this._client().agents.runs.create(args); + try { + return this._client().agents.runs.create(args); + } catch (error) { + console.error("Error initiating run:", error); + throw new Error(`Failed to initiate run: ${error.message}`); + } },
51-55
: Add error handling and input validation to getRunStatus methodThe getRunStatus method could benefit from input validation and error handling.
getRunStatus(run) { + if (!run) { + throw new Error("Run ID is required"); + } + try { return this._client().agents.runs.get({ run, }); + } catch (error) { + console.error("Error getting run status:", error); + throw new Error(`Failed to get run status: ${error.message}`); + } },components/utopian_labs/actions/initiate-classification-run/initiate-classification-run.mjs (2)
38-42
: Consider adding validation for options array lengthThe description mentions that the options should have a minimum of 2 and maximum of 10 elements, but there's no validation in the code to enforce this constraint.
Consider adding validation in the
run
method to ensure the options array meets these requirements:async run({ $ }) { + const parsedOptions = parseArrayAsJSON(this.options); + if (parsedOptions.length < 2 || parsedOptions.length > 10) { + throw new Error("Options must contain between 2 and 10 elements"); + } const response = await this.utopianLabs.initiateRun({ agent: this.agent, lead: parseStringAsJSON(this.lead), - options: parseArrayAsJSON(this.options), + options: parsedOptions, min_research_steps: this.minResearchSteps, max_research_steps: this.maxResearchSteps, context: this.context, ...parseObjectEntries(this.additionalOptions), });
69-78
: Add error handling for the API callThe run method doesn't include error handling for the API call, which could lead to unhandled exceptions if the call fails.
Consider adding try-catch block to handle potential errors:
async run({ $ }) { + try { const response = await this.utopianLabs.initiateRun({ agent: this.agent, lead: parseStringAsJSON(this.lead), options: parseArrayAsJSON(this.options), min_research_steps: this.minResearchSteps, max_research_steps: this.maxResearchSteps, context: this.context, ...parseObjectEntries(this.additionalOptions), }); $.export("$summary", `Successfully initiated run (ID: ${response.id}`); return response; + } catch (error) { + $.export("$summary", `Failed to initiate run: ${error.message}`); + throw error; + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
components/utopian_labs/actions/get-run-status/get-run-status.mjs
(1 hunks)components/utopian_labs/actions/initiate-classification-run/initiate-classification-run.mjs
(1 hunks)components/utopian_labs/actions/initiate-copywriting-run/initiate-copywriting-run.mjs
(1 hunks)components/utopian_labs/actions/initiate-qualification-run/initiate-qualification-run.mjs
(1 hunks)components/utopian_labs/actions/initiate-research-run/initiate-research-run.mjs
(1 hunks)components/utopian_labs/actions/initiate-timing-run/initiate-timing-run.mjs
(1 hunks)components/utopian_labs/common/constants.mjs
(1 hunks)components/utopian_labs/common/utils.mjs
(1 hunks)components/utopian_labs/package.json
(2 hunks)components/utopian_labs/utopian_labs.app.mjs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: pnpm publish
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (6)
components/utopian_labs/package.json (1)
3-18
: LGTM! Dependencies and version updateThe package version update and added dependencies look appropriate for the new Utopian Labs integration. The JSON structure is properly formatted with the dependencies section.
components/utopian_labs/utopian_labs.app.mjs (1)
1-56
:✅ Verification successful
Verify API version compatibility
Ensure that the imported UtopianLabs client version is compatible with the methods being called. Consider adding version checking or documentation about compatible versions.
🏁 Script executed:
#!/bin/bash # Check package.json for utopianlabs dependency version grep -r "utopianlabs" --include="package.json" .Length of output: 115
🏁 Script executed:
#!/bin/bash set -e # Download utopianlabs v0.1.11 and inspect for the methods used npm pack [email protected] tar -xzf utopianlabs-0.1.11.tgz # Search for the agents.runs.create and agents.runs.get implementations grep -R "agents\.runs\.create" -n package grep -R "agents\.runs\.get" -n packageLength of output: 2216
No Action Needed: API Version Compatibility Confirmed
The
utopianlabs
client at version ^0.1.11 provides bothagents.runs.create
andagents.runs.get
methods (confirmed in the package’s README). No changes to your code are required.components/utopian_labs/actions/initiate-classification-run/initiate-classification-run.mjs (4)
1-5
: Imports look goodThe imports are well-structured, separating utility functions for JSON parsing and the main app module.
7-12
: Component metadata is well-definedThe component key, name, description, version, and type are properly defined with good documentation links.
13-68
: Props structure is well-organizedThe props are well-defined with appropriate references to propDefinitions from the app module. The descriptions provide clear guidance and include documentation links where needed.
80-82
: Return statement looks goodThe return statement properly returns the full response object from the API call.
components/utopian_labs/actions/initiate-research-run/initiate-research-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-research-run/initiate-research-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-qualification-run/initiate-qualification-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-qualification-run/initiate-qualification-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-copywriting-run/initiate-copywriting-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-copywriting-run/initiate-copywriting-run.mjs
Outdated
Show resolved
Hide resolved
components/utopian_labs/actions/initiate-classification-run/initiate-classification-run.mjs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Just an FYI, sometimes I like to use a waitForCompletion
prop for actions that start a job. Example
Closes #16726
Summary by CodeRabbit