assistantAddBlockFromResult()
This method should add one or more new blocks using the AI assistant output from assistantGetResults(). context and return the
The method is called when the user drag and drops the "Add with AI Assitant" action in a field, writes their prompt in the assistant sidebar pane and clicks on "Generate".
Example
typescript
import {
defineBlokkliEditAdapter,
type AdapterAssistantAddBlockFromResult,
} from '#blokkli/adapter'
export default defineBlokkliEditAdapter((ctx) => {
return {
assistantAddBlockFromResult: async (
e: AdapterAssistantAddBlockFromResult,
) => {
// The object returned by assistantGetResults().
const result: AssistantResult = e.result
return $fetch(
`/backend-api/edit/${ctx.value.entityUuid}/add-new-text-block`,
{
method: 'post',
body: {
// The text content generated by the AI assistant.
text: result.content,
// The parent entity type where the block is being added.
// Could be the entity type of the <BlokkliProvider> or in case
// of nested blocks, the entity type of the block.
entityType: e.host.type,
entityUuid: e.host.uuid,
// The field name where the block is added.
fieldName: e.host.fieldName,
// The UUID of the block that should be before the new one.
preceedingUuid: e.afterUuid,
},
},
)
},
}
})