Skip to content

Commit 4e3aa90

Browse files
committedJul 26, 2024
fix: add docs for ai storage
1 parent fa8d614 commit 4e3aa90

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed
 

Diff for: ‎src/content/content-ai/capabilities/text-generation/manage-responses.mdx

+19-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ meta:
88

99
import { CodeDemo } from '@/components/CodeDemo'
1010

11-
The AI extension stores the current state in it’s extension storage under `editor.storage.ai`. This storage is used to keep track of the current state of the AI response, as well as any past responses.
11+
The AI extension stores the current state in it’s extension storage under `editor.storage.ai || editor.storage.aiAdvanced` (depending on if you are using the extension-ai or extension-ai-advanced extension). This storage is used to keep track of the current state of the AI response, as well as any past responses.
1212

1313
<CodeDemo isPro path="/Extensions/AiStorage" />
1414

@@ -23,20 +23,22 @@ The AI extension stores the current state in it’s extension storage under `edi
2323
You can use this storage to read out the current state of AI responses like:
2424

2525
```ts
26-
if (editor.storage.ai.response.state === 'error') {
26+
const aiStorage = editor.storage.ai || editor.storage.aiAdvanced
27+
28+
if (aiStorage.response.state === 'error') {
2729
// The error that occurred
28-
editor.storage.ai.response.error
30+
aiStorage.response.error
2931
}
3032

31-
if (editor.storage.ai.response.state === 'loading') {
33+
if (aiStorage.response.state === 'loading') {
3234
// The message that is currently being processed
33-
editor.storage.ai.response.message
35+
aiStorage.response.message
3436
}
3537

36-
if (editor.storage.ai.response.state === 'idle') {
37-
if (editor.storage.ai.response.message) {
38+
if (aiStorage.response.state === 'idle') {
39+
if (aiStorage.response.message) {
3840
// The successful response
39-
editor.storage.ai.response.message
41+
aiStorage.response.message
4042
} else {
4143
// No response has been requested yet
4244
}
@@ -90,7 +92,7 @@ editor.chain().aiAccept({ append: true }).run()
9092

9193
### aiRegenerate
9294

93-
This command is meant to be ran when the user wants the to retry the AI response, it will use all the same options as the previous AI text operation and add to the `editor.storage.ai.pastResponses` array
95+
This command is meant to be ran when the user wants the to retry the AI response, it will use all the same options as the previous AI text operation and add to the `(editor.storage.ai || editor.storage.aiAdvanced).pastResponses` array
9496

9597
| key | type | definition |
9698
| -------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -115,7 +117,7 @@ editor.chain().aiRegenerate({ append: true }).run()
115117

116118
### aiReject
117119

118-
This command is meant to be ran when the user has rejected the AI response, it will reset the extension’s state to the initial idle state and clear all `editor.storage.ai.pastResponses`
120+
This command is meant to be ran when the user has rejected the AI response, it will reset the extension’s state to the initial idle state and clear all `(editor.storage.ai || editor.storage.aiAdvanced).pastResponses`
119121

120122
| key | type | definition |
121123
| ---- | ------------------ | --------------------------------------------------------------------------------------------------- |
@@ -124,7 +126,7 @@ This command is meant to be ran when the user has rejected the AI response, it w
124126
```ts
125127
editor.chain().aiReject().run()
126128

127-
// Will not clear out editor.storage.ai, useful for keeping current response in the editor storage
129+
// Will not clear out editor.storage.ai || editor.storage.aiAdvanced, useful for keeping current response in the editor storage
128130
editor.chain().aiReject({ type: 'pause' }).run()
129131
```
130132

@@ -139,14 +141,17 @@ To render a preview of what a chat would look like in your editor, we can use yo
139141
import { tryParseToTiptapHTML } from '@tiptap-pro/extension-ai'
140142

141143
// try to parse the current message as HTML, and null if it could not be parsed
142-
tryToParseToHTML(editor.storage.ai.response.message, editor)
144+
tryToParseToHTML((editor.storage.ai || editor.storage.aiAdvanced).response.message, editor)
143145

144146
// try to parse a previous response as HTML, and null if it could not be parsed
145-
tryToParseToHTML(editor.storage.ai.pastResponses[0], editor)
147+
tryToParseToHTML((editor.storage.ai || editor.storage.aiAdvanced).pastResponses[0], editor)
146148

147149
// For example in React
148150
function PreviewComponent({ editor }) {
149-
const htmlResponse = tryToParseToHTML(editor.storage.ai.response.message, editor)
151+
const htmlResponse = tryToParseToHTML(
152+
(editor.storage.ai || editor.storage.aiAdvanced).response.message,
153+
editor,
154+
)
150155
/* This is safe since we've parsed the content with prose-mirror first */
151156
return <div dangerouslySetInnerHTML={{ __html: htmlResponse }}></div>
152157
}

0 commit comments

Comments
 (0)