Skip to content

New Components - hathr_ai #16592

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

Merged
merged 2 commits into from
May 9, 2025
Merged

New Components - hathr_ai #16592

merged 2 commits into from
May 9, 2025

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented May 8, 2025

Resolves #15830

Summary by CodeRabbit

  • New Features
    • Added the ability to send chat messages to Hathr AI, with options for controlling response randomness and providing document context.
    • Introduced actions to list all available documents and upload documents to Hathr AI.
    • Implemented a new event source that emits notifications when new documents are created.
  • Improvements
    • Enhanced integration with Hathr AI by providing a robust client interface for document management and chat interactions.
  • Chores
    • Updated dependencies and package version for improved compatibility and stability.

Copy link

vercel bot commented May 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) May 8, 2025 7:28pm
pipedream-docs ⬜️ Ignored (Inspect) May 8, 2025 7:28pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 8, 2025 7:28pm

Copy link
Contributor

coderabbitai bot commented May 8, 2025

Walkthrough

This update introduces a comprehensive Hathr AI integration, including an API client, utility functions, three new actions (chat, upload document, list documents), and a polling source for new document creation. The package metadata is updated for dependencies, and all components interact with the Hathr AI API using structured methods.

Changes

File(s) Change Summary
components/hathr_ai/actions/chat/chat.mjs Added new "Send Chat Message" action to send messages (optionally with documents) to Hathr AI.
components/hathr_ai/actions/list-documents/list-documents.mjs Added new "List Documents" action to retrieve all available documents from Hathr AI.
components/hathr_ai/actions/upload-document/upload-document.mjs Added new "Upload Document" action for uploading files to Hathr AI via signed URLs.
components/hathr_ai/common/utils.mjs Added utility function checkTmp to ensure file paths are within /tmp.
components/hathr_ai/hathr_ai.app.mjs Implemented full Hathr AI API client: methods for chat, document listing, upload URL, and prop definitions.
components/hathr_ai/package.json Updated version to 0.1.0; added dependencies for "@pipedream/platform" and "mime-types".
components/hathr_ai/sources/new-document-created/new-document-created.mjs Added new polling source "New Document Created" to emit events when a document is created in Hathr AI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Action
    participant HathrAIApp
    participant HathrAIAPI

    User->>Action: Trigger "Upload Document"
    Action->>HathrAIApp: getUploadUrl(filename, mimeType)
    HathrAIApp->>HathrAIAPI: POST /document/upload
    HathrAIAPI-->>HathrAIApp: Signed URL
    HathrAIApp-->>Action: Signed URL
    Action->>HathrAIAPI: PUT file to Signed URL
    HathrAIAPI-->>Action: Upload success
    Action-->>User: Return upload summary

    User->>Action: Trigger "Chat" (with/without documents)
    Action->>HathrAIApp: chat or chatWithDocuments(message, [documents], [params])
    HathrAIApp->>HathrAIAPI: POST /chat or /document/chat
    HathrAIAPI-->>HathrAIApp: AI Response
    HathrAIApp-->>Action: AI Response
    Action-->>User: Return chat summary

    User->>Action: Trigger "List Documents"
    Action->>HathrAIApp: listDocuments()
    HathrAIApp->>HathrAIAPI: GET /document/list
    HathrAIAPI-->>HathrAIApp: Document List
    HathrAIApp-->>Action: Document List
    Action-->>User: Return list summary

    Note over Action, HathrAIApp: "New Document Created" polling source periodically calls listDocuments()
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement "new-document-created" source to emit events on new document creation (#15830)
Implement "chat" action to make chat requests to Hathr AI (#15830)
Implement "upload-document" action to upload documents for future chat requests (#15830)
Implement "list-documents" action to retrieve all available documents (#15830)

Poem

In the land of code, where the Hathr winds blow,
New actions and sources now shimmer and glow!
Documents upload, chat replies on cue,
Listing and polling—so much to do!
With every hop, this rabbit’s proud—
The Hathr AI’s ready, robust, and loud!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (8)
components/hathr_ai/common/utils.mjs (1)

1-6: Consider adding more robust path validation.

The checkTmp function works for basic path normalization but could benefit from additional validation:

  1. It doesn't handle edge cases like empty strings or non-string inputs
  2. It doesn't handle relative paths with "tmp" in them (e.g., "./tmp/file.txt")
- export const checkTmp = (filename) => {
-   if (!filename.startsWith("/tmp")) {
-     return `/tmp/${filename}`;
-   }
-   return filename;
- };
+ export const checkTmp = (filename) => {
+   if (!filename || typeof filename !== 'string') {
+     throw new Error('Invalid filename provided');
+   }
+   
+   // Handle both absolute and relative paths
+   const normalizedPath = filename.replace(/^\.?\/?tmp\//, '');
+   return `/tmp/${normalizedPath}`;
+ };
components/hathr_ai/actions/chat/chat.mjs (1)

9-34: Consider changing temperature and topP to numeric types.

These properties represent numerical values with specific ranges:

  • temperature: range 0-2.0, default 0.2
  • topP: range 0-1.0, default 1.0

Using the 'number' type instead of 'string' would provide better validation and user experience.

  temperature: {
-   type: "string",
+   type: "number",
    label: "Temperature",
    description: "Controls randomness (Optional, default: 0.2, range: 0-2.0)",
    optional: true,
+   min: 0,
+   max: 2,
+   default: 0.2,
  },
  topP: {
-   type: "string",
+   type: "number",
    label: "Top P",
    description: "Controls diversity (Optional, default: 1.0, range: 0-1.0)",
    optional: true,
+   min: 0,
+   max: 1,
+   default: 1.0,
  },
components/hathr_ai/hathr_ai.app.mjs (2)

19-21: Consider making the base URL configurable

The base URL is currently hardcoded. For better maintainability, consider making it configurable through environment variables or app settings, which would facilitate easier switching between environments (e.g., development, staging, production).

_baseUrl() {
-  return "https://api.hathr.ai/v1";
+  return this.$auth.base_url || "https://api.hathr.ai/v1";
}

33-59: Add JSDoc comments to API methods

Consider adding JSDoc comments to document the parameters and return values of your API methods. This would improve developer experience when using this app module in other components.

Example for one method:

+ /**
+  * Lists all documents in the Hathr AI system
+  * @param {Object} opts - Additional options to pass to the request
+  * @param {Object} [opts.$] - Custom Pipedream event object
+  * @returns {Promise<Object>} Response containing documents array
+  */
listDocuments(opts = {}) {
  return this._makeRequest({
    path: "/document/list",
    ...opts,
  });
},
components/hathr_ai/actions/upload-document/upload-document.mjs (2)

15-19: Consider adding file size validation

The action currently doesn't check the file size before upload. Consider adding file size validation to prevent uploading files that might be too large for the API to handle.

filePath: {
  type: "string",
  label: "File Path",
  description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
+  async options({ prevContext }) {
+    // This would provide a dropdown of files in /tmp
+    // Implementation depends on how you want to handle this
+  },
},

And in the run method:

// Add this after reading file
if (fileBuffer.length > MAX_FILE_SIZE) {
  throw new Error(`File size exceeds the maximum allowed size of ${MAX_FILE_SIZE / (1024 * 1024)}MB`);
}

48-49: Export more details in the summary message

Consider enhancing the summary message with more details about the uploaded document, such as the filename and link if available.

- $.export("$summary", "Successfully uploaded document.");
+ $.export("$summary", `Successfully uploaded document: ${this.filename}`);
components/hathr_ai/sources/new-document-created/new-document-created.mjs (2)

22-28: Include document creation date in metadata if available

If the document object includes a creation date, consider using that instead of the current time for the timestamp in the metadata.

generateMeta(doc) {
  return {
    id: doc.name,
    summary: `New Document Created: ${doc.name}`,
-   ts: Date.now(),
+   ts: doc.createdAt ? new Date(doc.createdAt).getTime() : Date.now(),
  };
},

13-19: Consider adding filtering options

The current implementation fetches all documents without any filtering. Consider adding optional props to filter documents by name pattern, creation date range, or other criteria that the API might support.

props: {
  hathrAi,
  db: "$.service.db",
+  filter: {
+    type: "string",
+    label: "Filter Pattern",
+    description: "Only emit documents whose names match this pattern (optional)",
+    optional: true,
+  },
  timer: {
    type: "$.interface.timer",
    default: {
      intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
    },
  },
},

And in the run method:

// Add filtering logic if filter is provided
if (this.filter) {
  documents = documents.filter(doc => doc.name.includes(this.filter));
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b5a9bf and 933a180.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • components/hathr_ai/actions/chat/chat.mjs (1 hunks)
  • components/hathr_ai/actions/list-documents/list-documents.mjs (1 hunks)
  • components/hathr_ai/actions/upload-document/upload-document.mjs (1 hunks)
  • components/hathr_ai/common/utils.mjs (1 hunks)
  • components/hathr_ai/hathr_ai.app.mjs (1 hunks)
  • components/hathr_ai/package.json (2 hunks)
  • components/hathr_ai/sources/new-document-created/new-document-created.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (6)
components/hathr_ai/package.json (2)

3-3: Version bump to 0.1.0 looks appropriate.

The version increase from 0.0.1 to 0.1.0 aligns with the introduction of multiple new components for the Hathr AI integration. This follows semantic versioning principles for feature additions.


14-18: Dependencies look appropriate for the integration.

The added dependencies make sense for this integration:

  • @pipedream/platform for core Pipedream functionality
  • mime-types likely for handling file uploads in the document upload action

The package.json structure is also correct with proper JSON formatting.

components/hathr_ai/actions/list-documents/list-documents.mjs (1)

3-11: Component definition looks good.

The action is well-defined with an appropriate key, name, description, version, and props configuration. The documentation link is helpful for users.

components/hathr_ai/hathr_ai.app.mjs (1)

6-17: Good implementation of dynamic options for documents

The propDefinitions for documents correctly uses async options to fetch document names dynamically and handles the possibility of null/undefined responses gracefully with optional chaining and fallback to an empty array.

components/hathr_ai/actions/upload-document/upload-document.mjs (1)

7-12: Good component metadata and documentation links

The component includes clear metadata with version, type, and a comprehensive description with a link to documentation, which follows best practices.

components/hathr_ai/sources/new-document-created/new-document-created.mjs (1)

4-10: Good component metadata and clear descriptions

The component includes clear metadata with version, type, dedupe settings, and a comprehensive description with a link to documentation, which follows best practices.

Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@michelle0927 michelle0927 merged commit 3dc9601 into master May 9, 2025
11 checks passed
@michelle0927 michelle0927 deleted the issue-15830 branch May 9, 2025 14:37
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.

[Components] hathr_ai
2 participants