-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(editor): persist versioned prompt fields during SDK updates #17088
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
Open
Akash504-ai
wants to merge
4
commits into
mastra-ai:main
Choose a base branch
from
Akash504-ai:fix/prompt-update-versioned-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a87508
fix(editor): persist versioned prompt fields during SDK updates
Akash504-ai e6ec40e
refactor(editor): avoid partial writes during prompt version updates
Akash504-ai 18b582f
fix(editor): handle in-memory duplicate version retries
Akash504-ai cde2750
Merge branch 'main' into fix/prompt-update-versioned-fields
Akash504-ai 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@mastra/editor': patch | ||
| --- | ||
|
|
||
| Fixed prompt block SDK updates to persist editable fields. |
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,72 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { InMemoryStore } from '@mastra/core/storage'; | ||
|
|
||
| import { EditorPromptNamespace } from './prompt'; | ||
|
|
||
| function createPromptNamespace(storage: InMemoryStore) { | ||
| return new EditorPromptNamespace({ | ||
| __mastra: { | ||
| getStorage: () => storage, | ||
| removePromptBlock: vi.fn(), | ||
| }, | ||
| __logger: { | ||
| debug: vi.fn(), | ||
| }, | ||
| } as any); | ||
| } | ||
|
|
||
| describe('EditorPromptNamespace', () => { | ||
| it('updates prompt block snapshot fields through the SDK', async () => { | ||
| const storage = new InMemoryStore(); | ||
| const prompt = createPromptNamespace(storage); | ||
|
|
||
| await prompt.create({ | ||
| id: 'sdk-updatable-block', | ||
| name: 'SDK Updatable Block', | ||
| content: 'Initial content', | ||
| }); | ||
|
|
||
| const updated = await prompt.update({ | ||
| id: 'sdk-updatable-block', | ||
| name: 'SDK Updated Block', | ||
| content: 'Updated content', | ||
| rules: { | ||
| operator: 'AND', | ||
| conditions: [{ field: 'role', operator: 'equals', value: 'admin' }], | ||
| }, | ||
| requestContextSchema: { | ||
| type: 'object', | ||
| properties: { | ||
| role: { type: 'string' }, | ||
| }, | ||
| required: ['role'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(updated.name).toBe('SDK Updated Block'); | ||
| expect(updated.content).toBe('Updated content'); | ||
| expect(updated.rules).toEqual({ | ||
| operator: 'AND', | ||
| conditions: [{ field: 'role', operator: 'equals', value: 'admin' }], | ||
| }); | ||
| expect(updated.requestContextSchema).toEqual({ | ||
| type: 'object', | ||
| properties: { | ||
| role: { type: 'string' }, | ||
| }, | ||
| required: ['role'], | ||
| }); | ||
|
|
||
| const persisted = await prompt.getById('sdk-updatable-block'); | ||
| expect(persisted!.name).toBe('SDK Updated Block'); | ||
| expect(persisted!.content).toBe('Updated content'); | ||
| expect(persisted!.rules).toEqual(updated.rules); | ||
| expect(persisted!.requestContextSchema).toEqual(updated.requestContextSchema); | ||
|
|
||
| const promptStore = await storage.getStore('promptBlocks'); | ||
| const versions = await promptStore!.listVersions({ blockId: 'sdk-updatable-block' }); | ||
| expect(versions.versions).toHaveLength(2); | ||
| expect(versions.versions[0]!.changedFields).toEqual(['name', 'content', 'rules', 'requestContextSchema']); | ||
| expect(updated.activeVersionId).toBeUndefined(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Make the snapshot write atomic with the block update.
store.update()persists the thin record first, andcreateVersion()happens afterward. If version creation fails, this method throws after a partial update and the versioned fields are still stale. This should be one storage-domain operation or a transaction.🤖 Prompt for AI Agents