-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
New Components - hathr_ai #16592
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
WalkthroughThis 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
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()
Assessment against linked issues
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ 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: 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:
- It doesn't handle edge cases like empty strings or non-string inputs
- 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 configurableThe 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 methodsConsider 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 validationThe 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 messageConsider 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 availableIf 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 optionsThe 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
⛔ 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 functionalitymime-types
likely for handling file uploads in the document upload actionThe 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 documentsThe 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 linksThe 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 descriptionsThe component includes clear metadata with version, type, dedupe settings, and a comprehensive description with a link to documentation, which follows best practices.
components/hathr_ai/sources/new-document-created/new-document-created.mjs
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!
Resolves #15830
Summary by CodeRabbit