Skip to content

Commit

Permalink
Fix bug where people who were there before we implemented the editabl…
Browse files Browse the repository at this point in the history
…e templates could not use them anymore
  • Loading branch information
blackforestboi committed Jul 30, 2024
1 parent fc75203 commit 9019602
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
2 changes: 1 addition & 1 deletion src/common-ui/components/prompt-templates/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class PromptTemplatesLogic extends UILogic<
const currentTemplates = previousState.promptTemplatesArray

this.dependencies.onTemplateSelect(
marked.parse(currentTemplates[selectedTemplate].text),
marked.parse(currentTemplates[selectedTemplate]?.text),
)
}
setTemplateEdit: EventHandler<'setTemplateEdit'> = async ({
Expand Down
36 changes: 16 additions & 20 deletions src/sidebar/annotations-sidebar/containers/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import { UserReference } from '@worldbrain/memex-common/lib/web-interface/types/
import { convertLinksInAIResponse } from '@worldbrain/memex-common/lib/ai-chat/utils'
import { DEFAULT_AI_MODEL } from '@worldbrain/memex-common/lib/ai-chat/constants'
import { HighlightRendererInterface } from '@worldbrain/memex-common/lib/in-page-ui/highlighting/types'
import { PromptTemplate } from 'src/common-ui/components/prompt-templates/types'
const md = new MarkdownIt()

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

if (event.prompt == null) {
const syncsettings =
(await this.syncSettings.openAI?.get('promptSuggestions')) ??
AI_PROMPT_DEFAULTS.map((text) => ({
let savedPrompts = await this.syncSettings.openAI?.get(
'promptSuggestions',
)
if (!savedPrompts) {
savedPrompts = AI_PROMPT_DEFAULTS.map((text) => ({
text,
isEditing: null,
isFocused: false,
}))
prompt = marked.parse(syncsettings[0].text)
} else if (typeof savedPrompts[0] === 'string') {
savedPrompts = ((savedPrompts as unknown) as string[]).map(
(text) => ({
text: text,
}),
)
this.syncSettings.openAI?.set('promptSuggestions', savedPrompts)
}
prompt = marked.parse(savedPrompts[0].text)
}

if (event.textToProcess) {
Expand All @@ -3609,21 +3620,6 @@ export class SidebarContainerLogic extends UILogic<
}
if (!event.textToProcess) {
let executed = false
let prompt = event.prompt

if (event.prompt == null) {
const syncsettings =
(await this.syncSettings.openAI?.get(
'promptSuggestions',
)) ??
AI_PROMPT_DEFAULTS.map((text) => ({
text,
isEditing: null,
isFocused: false,
}))
prompt = marked.parse(syncsettings[0].text)
}

let retries = 0
const maxRetries = 100
while (!executed && retries < maxRetries) {
Expand Down Expand Up @@ -3663,7 +3659,7 @@ export class SidebarContainerLogic extends UILogic<
isEditing: null,
isFocused: false,
}))
prompt = syncsettings[0].text
prompt = syncsettings[0]?.text
}

if (previousState.activeTab === 'summary') {
Expand Down

0 comments on commit 9019602

Please sign in to comment.