Conversation
✅ Deploy Preview for ap-template-playground ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
aeb68d2 to
231b7cc
Compare
Signed-off-by: ZENFALLACY <udashiv18@gmail.com>
Signed-off-by: ZENFALLACY <udashiv18@gmail.com>
Signed-off-by: ZENFALLACY <udashiv18@gmail.com>
231b7cc to
8369f4a
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses several AI assistant chat reliability issues, primarily around preserving system prompts across multi-turn conversations and preventing UI/runtime errors during prompt inspection and message stopping.
Changes:
- Fixes system-prompt extraction for Anthropic and Google providers to reliably use the most recent
systemmessage. - Prevents a
showFullPromptruntime crash in the chat panel by safely locating the preceding system message. - Avoids stale state overwrites when stopping an in-flight message, and removes an extra
rebuild()during shared-link loads.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/ai-assistant/llmProviders.ts |
Uses the most recent system message instead of a fixed slice for provider system instructions. |
src/components/AIChatPanel.tsx |
Fixes showFullPrompt crash by safely finding the preceding system message. |
src/store/store.ts |
Removes rebuild() from loadFromLink and updates store formatting/structure in the diff hunk. |
src/ai-assistant/chatRelay.ts |
Makes stopMessage() apply updates in a single atomic state write to avoid stale overwrites. |
tsconfig.json |
Reformat-only changes; PR description claims an ES target/lib bump that isn’t reflected here. |
tsc_out.txt |
Adds a build/output log file to the repo (should not be versioned). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| `**System message:** ${chatState.messages.slice(0, index).reverse().find(m => m.role === 'system')?.content ?? '(none)'}\n**User message:** ${message.content}` | ||
| ) : message.content) | ||
| : message.content |
There was a problem hiding this comment.
When showFullPrompt is enabled, this renders the nearest system message by doing slice(0, index).reverse().find(...) inside the message loop. That allocates and reverses arrays per user message, which can become noticeably expensive for long chats. Consider tracking the last seen system message while iterating (single pass) or precomputing a per-index lookup so rendering stays O(n).
| loadFromLink: async (compressedData: string) => { | ||
| try { | ||
| const { templateMarkdown, modelCto, data, agreementHtml } = decompress(compressedData); | ||
| if (!templateMarkdown || !modelCto || !data) { | ||
| throw new Error("Invalid share link data"); | ||
| } | ||
| set(() => ({ | ||
| templateMarkdown, | ||
| editorValue: templateMarkdown, | ||
| modelCto, | ||
| editorModelCto: modelCto, | ||
| data, | ||
| editorAgreementData: data, | ||
| agreementHtml, | ||
| error: undefined, | ||
| })); | ||
| } catch (error) { |
There was a problem hiding this comment.
loadFromLink behavior changed (no longer triggers rebuild() and now relies on agreementHtml from the payload). There are existing tests around share-link generation/compression, but no coverage for loadFromLink (e.g., handling missing/old payload shapes, ensuring preview content is set as expected). Adding a small store-level test here would help prevent regressions for shared-link loads.
| const { templateMarkdown, modelCto, data, agreementHtml } = decompress(compressedData); | ||
| if (!templateMarkdown || !modelCto || !data) { | ||
| throw new Error("Invalid share link data"); | ||
| } | ||
| set(() => ({ | ||
| templateMarkdown, | ||
| editorValue: templateMarkdown, | ||
| modelCto, | ||
| editorModelCto: modelCto, | ||
| data, | ||
| editorAgreementData: data, | ||
| agreementHtml, | ||
| error: undefined, | ||
| })); |
There was a problem hiding this comment.
loadFromLink now trusts agreementHtml from the decompressed payload, but decompress() does not enforce/default missing fields and existing compression tests only include {templateMarkdown, modelCto, data} (no agreementHtml). This means older shared links (or any payload without agreementHtml) will set agreementHtml to undefined and skip the rebuild, leaving the preview blank and potentially violating the store's agreementHtml: string contract. Consider defaulting agreementHtml when absent and/or falling back to rebuild() when the field is missing, and update the compression typings/tests accordingly.
…npmrc Signed-off-by: ZENFALLACY <udashiv18@gmail.com>
d60fee3 to
191da73
Compare
…ly.github.com> I, Matt Roberts <7544022+mttrbrts@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 78ef327 I, Matt Roberts <7544022+mttrbrts@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 85090ea Signed-off-by: Matt Roberts <7544022+mttrbrts@users.noreply.github.com>
|
@mttrbrts Fixed the failing checks: |
fix: resolve AI system prompt loss and showFullPrompt crash
Closes
Changes
messages.slice(-2, -1)[0], which silently dropped all AI context after the first message in multi-turn conversations. Now usesmessages.findLast(m => m.role === 'system')to reliably find the most recent system message regardless of conversation length.TypeError: Cannot read properties of undefined) whenshowFullPromptis enabled. The previous code accessedchatState.messages[index-1]which returnsundefinedat index 0. Now usesslice(0, index).findLast()to safely locate the nearest preceding system message.agreementHtml, so re-running the full template engine on every shared-link load was unnecessary and could interfere with the shared debounce used by user edits.chatStatesnapshot. State is now read once and all changes applied atomically in a single setChatState call.targetandlibfromES2020toES2023to enableArray.prototype.findLast.Flags
tsconfigtarget bump to ES2023 is a minor compatibility change; all browsers listed inbrowserslist(last 2 versions, no IE) support ES2023 array methods natively.agreementHtmlin a link is ever stale, users would need to manually trigger a rebuild — this is an acceptable trade-off given the previous behaviour was always redundant.Screenshots or Video
N/A — changes are logic fixes with no UI changes.
Related Issues
Author Checklist
--signoffoption of git commit.mainfromfork:branchname