| 175 | } |
| 176 | |
| 177 | onAddCode (e) { |
| 178 | const a = this.treema.get('/context/code/current/javascript') |
| 179 | let b = this.treema.get('/context/code/fixed/javascript') |
| 180 | if (b == null) { b = this.treema.get('/context/code/solution/javascript') } |
| 181 | if ((a == null) || (b == null)) { |
| 182 | return noty({ |
| 183 | timeout: 5000, |
| 184 | text: 'You need to have both a current and solution context to add structured code to AI response.', |
| 185 | type: 'error', |
| 186 | layout: 'topCenter' |
| 187 | }) |
| 188 | } |
| 189 | let code = b |
| 190 | code = code.replace(/\s+$/, '') |
| 191 | this.treema.set('/message/textComponents/code', code) |
| 192 | const messageText = this.treema.get('/message/text') |
| 193 | this.treema.set('/message/textComponents/actionButtons', [{ action: 'fix', text: 'Fix It' }]) |
| 194 | const button = '<button action="fix">Fix It</button>' |
| 195 | this.treema.set('/message/text', `${messageText}\n\n${button}\n\n\`\`\`\n${code}\n\`\`\``) // TODO: replace existing code? |
| 196 | if (this.treema.childrenTreemas.message != null) { |
| 197 | this.treema.childrenTreemas.message.close() |
| 198 | } |
| 199 | return (this.treema.childrenTreemas.message != null ? this.treema.childrenTreemas.message.open(2) : undefined) |
| 200 | } |
| 201 | |
| 202 | onRegenerateMessage (e) { |
| 203 | let code, explanation, free |