-
Notifications
You must be signed in to change notification settings - Fork 18
Add uuid4FromHash utility to codegen (node_id skipping disabled pending vembda fix) #3272
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d57c57a
Add uuid4FromHash utility and skip node_id when it matches hash-gener…
devin-ai-integration[bot] 318d9f1
Add snapshot tests for node_id skipping and fix to use definition mod…
devin-ai-integration[bot] 84cc06d
Address PR feedback: update helper to accept full definition, comment…
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { createHash } from "crypto"; | ||
|
|
||
| /** | ||
| * Generate a deterministic UUID v4 from a string input using SHA-256 hashing. | ||
| * This matches the Python implementation in src/vellum/workflows/utils/uuids.py | ||
| * | ||
| * @param inputStr - The string to hash | ||
| * @returns A UUID v4 string derived from the hash | ||
| */ | ||
| export function uuid4FromHash(inputStr: string): string { | ||
| // Create a SHA-256 hash of the input string | ||
| const hashBytes = createHash("sha256").update(inputStr).digest(); | ||
|
|
||
| // Convert first 16 bytes into a mutable array | ||
| // SHA-256 always produces 32 bytes, so we're guaranteed to have at least 16 bytes | ||
| const hashList: number[] = Array.from(hashBytes.subarray(0, 16)); | ||
|
|
||
| // Set the version to 4 (UUID4) | ||
| // Version bits (4 bits) should be set to 4 | ||
| const byte6 = hashList[6]; | ||
| const byte8 = hashList[8]; | ||
| if (byte6 !== undefined && byte8 !== undefined) { | ||
| hashList[6] = (byte6 & 0x0f) | 0x40; | ||
| // Set the variant to 0b10xxxxxx | ||
| hashList[8] = (byte8 & 0x3f) | 0x80; | ||
| } | ||
|
|
||
| // Convert to UUID string format (8-4-4-4-12) | ||
| const hex = hashList.map((b) => b.toString(16).padStart(2, "0")).join(""); | ||
| return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice( | ||
| 12, | ||
| 16 | ||
| )}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`; | ||
| } | ||
|
|
||
| /** | ||
| * Generate a deterministic node ID from a module path and class name. | ||
| * This matches the Python SDK's node ID generation pattern: | ||
| * uuid4_from_hash(f"{node_class.__module__}.{node_class.__qualname__}") | ||
| * | ||
| * @param modulePath - The module path as an array of strings | ||
| * @param className - The class name | ||
| * @returns A UUID v4 string | ||
| */ | ||
| export function getNodeIdFromModuleAndName( | ||
| modulePath: readonly string[], | ||
| className: string | ||
| ): string { | ||
| const moduleStr = modulePath.join("."); | ||
| return uuid4FromHash(`${moduleStr}.${className}`); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DevinAI update this helper to accept the full definition instead of forcing the consumer to split the fields
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.
Addressed all feedback:
Updated helper to accept full definition - Renamed
getNodeIdFromModuleAndNametogetNodeIdFromDefinitionand updated it to accept the full definition object (withmoduleandnameproperties) instead of separate fieldsCommented out the node_id check - The check in
base.tsis now commented out with a TODO marker pending vembda-side fixesSkipped the tests - The
describeblock for node_id skipping tests is now usingdescribe.skipwith a TODO marker