@@ -11,7 +11,6 @@ import { type ContextItem, ContextItemSource } from '../codebase-context/message
1111import type { RangeData } from '../common/range'
1212import { displayPath } from '../editor/displayPath'
1313import type { PromptString } from '../prompt/prompt-string'
14- import { memoize } from '../utils'
1514import { AT_MENTION_SERIALIZED_PREFIX , deserializeParagraph } from './atMentionsSerializer'
1615import {
1716 CONTEXT_ITEM_MENTION_NODE_TYPE ,
@@ -148,36 +147,36 @@ export function serializedPromptEditorStateFromText(text: string): SerializedPro
148147 }
149148}
150149
151- export const serializedPromptEditorStateFromChatMessage = memoize (
152- ( chatMessage : ChatMessage ) : SerializedPromptEditorState => {
153- function isCompatibleVersionEditorState ( value : unknown ) : value is SerializedPromptEditorState {
154- if ( ! value ) {
155- return false
156- }
157-
158- const editorState = value as SerializedPromptEditorState
159-
160- // We can read this if the version of the serialized text is compatible
161- // or its minimum version is compatible.
162- return (
163- SUPPORTED_READER_VERSIONS . includes ( editorState . v ) ||
164- SUPPORTED_READER_VERSIONS . includes ( editorState . minReaderV ?? DEFAULT_MIN_READER_V )
165- )
150+ export const serializedPromptEditorStateFromChatMessage = (
151+ chatMessage : ChatMessage
152+ ) : SerializedPromptEditorState => {
153+ function isCompatibleVersionEditorState ( value : unknown ) : value is SerializedPromptEditorState {
154+ if ( ! value ) {
155+ return false
166156 }
167157
168- if ( isCompatibleVersionEditorState ( chatMessage . editorState ) ) {
169- return chatMessage . editorState
170- }
158+ const editorState = value as SerializedPromptEditorState
171159
172- // Fall back to using plain text for chat messages that don't have a serialized Lexical editor
173- // state that we recognize.
174- //
175- // It would be smoother to automatically import or convert textual @-mentions to the Lexical
176- // mention nodes, but that would add a lot of extra complexity for the relatively rare use case
177- // of editing old messages in your chat history.
178- return serializedPromptEditorStateFromText ( chatMessage . text ? chatMessage . text . toString ( ) : '' )
160+ // We can read this if the version of the serialized text is compatible
161+ // or its minimum version is compatible.
162+ return (
163+ SUPPORTED_READER_VERSIONS . includes ( editorState . v ) ||
164+ SUPPORTED_READER_VERSIONS . includes ( editorState . minReaderV ?? DEFAULT_MIN_READER_V )
165+ )
179166 }
180- )
167+
168+ if ( isCompatibleVersionEditorState ( chatMessage . editorState ) ) {
169+ return chatMessage . editorState
170+ }
171+
172+ // Fall back to using plain text for chat messages that don't have a serialized Lexical editor
173+ // state that we recognize.
174+ //
175+ // It would be smoother to automatically import or convert textual @-mentions to the Lexical
176+ // mention nodes, but that would add a lot of extra complexity for the relatively rare use case
177+ // of editing old messages in your chat history.
178+ return serializedPromptEditorStateFromText ( chatMessage . text ? chatMessage . text . toString ( ) : '' )
179+ }
181180
182181export function contextItemsFromPromptEditorValue (
183182 state : SerializedPromptEditorState
0 commit comments