Skip to content

Commit 9019602

Browse files
Fix bug where people who were there before we implemented the editable templates could not use them anymore
1 parent fc75203 commit 9019602

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

src/common-ui/components/prompt-templates/logic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class PromptTemplatesLogic extends UILogic<
9595
const currentTemplates = previousState.promptTemplatesArray
9696

9797
this.dependencies.onTemplateSelect(
98-
marked.parse(currentTemplates[selectedTemplate].text),
98+
marked.parse(currentTemplates[selectedTemplate]?.text),
9999
)
100100
}
101101
setTemplateEdit: EventHandler<'setTemplateEdit'> = async ({

src/sidebar/annotations-sidebar/containers/logic.ts

+16-20
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import { UserReference } from '@worldbrain/memex-common/lib/web-interface/types/
119119
import { convertLinksInAIResponse } from '@worldbrain/memex-common/lib/ai-chat/utils'
120120
import { DEFAULT_AI_MODEL } from '@worldbrain/memex-common/lib/ai-chat/constants'
121121
import { HighlightRendererInterface } from '@worldbrain/memex-common/lib/in-page-ui/highlighting/types'
122+
import { PromptTemplate } from 'src/common-ui/components/prompt-templates/types'
122123
const md = new MarkdownIt()
123124

124125
export type SidebarContainerOptions = SidebarContainerDependencies & {
@@ -3576,14 +3577,24 @@ export class SidebarContainerLogic extends UILogic<
35763577
let prompt = event.prompt
35773578

35783579
if (event.prompt == null) {
3579-
const syncsettings =
3580-
(await this.syncSettings.openAI?.get('promptSuggestions')) ??
3581-
AI_PROMPT_DEFAULTS.map((text) => ({
3580+
let savedPrompts = await this.syncSettings.openAI?.get(
3581+
'promptSuggestions',
3582+
)
3583+
if (!savedPrompts) {
3584+
savedPrompts = AI_PROMPT_DEFAULTS.map((text) => ({
35823585
text,
35833586
isEditing: null,
35843587
isFocused: false,
35853588
}))
3586-
prompt = marked.parse(syncsettings[0].text)
3589+
} else if (typeof savedPrompts[0] === 'string') {
3590+
savedPrompts = ((savedPrompts as unknown) as string[]).map(
3591+
(text) => ({
3592+
text: text,
3593+
}),
3594+
)
3595+
this.syncSettings.openAI?.set('promptSuggestions', savedPrompts)
3596+
}
3597+
prompt = marked.parse(savedPrompts[0].text)
35873598
}
35883599

35893600
if (event.textToProcess) {
@@ -3609,21 +3620,6 @@ export class SidebarContainerLogic extends UILogic<
36093620
}
36103621
if (!event.textToProcess) {
36113622
let executed = false
3612-
let prompt = event.prompt
3613-
3614-
if (event.prompt == null) {
3615-
const syncsettings =
3616-
(await this.syncSettings.openAI?.get(
3617-
'promptSuggestions',
3618-
)) ??
3619-
AI_PROMPT_DEFAULTS.map((text) => ({
3620-
text,
3621-
isEditing: null,
3622-
isFocused: false,
3623-
}))
3624-
prompt = marked.parse(syncsettings[0].text)
3625-
}
3626-
36273623
let retries = 0
36283624
const maxRetries = 100
36293625
while (!executed && retries < maxRetries) {
@@ -3663,7 +3659,7 @@ export class SidebarContainerLogic extends UILogic<
36633659
isEditing: null,
36643660
isFocused: false,
36653661
}))
3666-
prompt = syncsettings[0].text
3662+
prompt = syncsettings[0]?.text
36673663
}
36683664

36693665
if (previousState.activeTab === 'summary') {

0 commit comments

Comments
 (0)