diff --git a/amd/build/showprompt.min.js b/amd/build/showprompt.min.js
new file mode 100644
index 0000000..1762d0d
--- /dev/null
+++ b/amd/build/showprompt.min.js
@@ -0,0 +1,3 @@
+define("qtype_aitext/showprompt",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=()=>{document.getElementById("showprompt").addEventListener("click",(event=>{!function(event){event.preventDefault();var text=document.getElementById("fullprompt");"hidden"===text.className?text.className="visible":text.className="hidden"}(event)}))}}));
+
+//# sourceMappingURL=showprompt.min.js.map
\ No newline at end of file
diff --git a/amd/build/showprompt.min.js.map b/amd/build/showprompt.min.js.map
new file mode 100644
index 0000000..83f2dcb
--- /dev/null
+++ b/amd/build/showprompt.min.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"showprompt.min.js","sources":["../src/showprompt.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Display a button in testing to reveal the prompt that was sent\n *\n * @module qtype_aitext/showprompt\n * @copyright 2024 Marcus Green\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport const init = () => {\n var button = document.getElementById('showprompt');\n button.addEventListener('click', (event) => {\n toggleFullPrompt(event);\n });\n /**\n * Togle the visibility of the prompt that is sent to\n * the AI System\n * @param {*} event\n */\n function toggleFullPrompt(event) {\n event.preventDefault();\n var text = document.getElementById(\"fullprompt\");\n if (text.className === \"hidden\") {\n text.className = \"visible\";\n } else {\n text.className = \"hidden\";\n }\n }\n};\n"],"names":["document","getElementById","addEventListener","event","preventDefault","text","className","toggleFullPrompt"],"mappings":"4JAsBoB,KACHA,SAASC,eAAe,cAC9BC,iBAAiB,SAAUC,kBAQRA,OACtBA,MAAMC,qBACFC,KAAOL,SAASC,eAAe,cACZ,WAAnBI,KAAKC,UACLD,KAAKC,UAAY,UAEjBD,KAAKC,UAAY,SAbrBC,CAAiBJ"}
\ No newline at end of file
diff --git a/amd/src/showprompt.js b/amd/src/showprompt.js
new file mode 100644
index 0000000..2c27eee
--- /dev/null
+++ b/amd/src/showprompt.js
@@ -0,0 +1,43 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see .
+
+/**
+ * Display a button in testing to reveal the prompt that was sent
+ *
+ * @module qtype_aitext/showprompt
+ * @copyright 2024 Marcus Green
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+export const init = () => {
+ var button = document.getElementById('showprompt');
+ button.addEventListener('click', (event) => {
+ toggleFullPrompt(event);
+ });
+
+ /**
+ * Togle the visibility of the prompt that is sent to
+ * the AI System
+ * @param {*} event
+ */
+ function toggleFullPrompt(event) {
+ event.preventDefault();
+ var text = document.getElementById("fullprompt");
+ if (text.className === "hidden") {
+ text.className = "visible";
+ } else {
+ text.className = "hidden";
+ }
+ }
+};
diff --git a/question.php b/question.php
index cb7383a..b041c41 100755
--- a/question.php
+++ b/question.php
@@ -134,7 +134,7 @@ public function apply_attempt_state(question_attempt_step $step) {
* @return void
*/
public function grade_response(array $response) : array {
- if(!$this->is_complete_response($response)) {
+ if (!$this->is_complete_response($response)) {
$grade = [0 => 0, question_state::$needsgrading];
return $grade;
}
@@ -144,7 +144,7 @@ public function grade_response(array $response) : array {
$responsetext = '[['.$responsetext.']]';
$prompt = get_config('qtype_aitext', 'prompt');
$prompt = preg_replace("/\[responsetext\]/", $responsetext, $prompt);
- $prompt .= ' '.trim($this->aiprompt);
+ $prompt .= ' '.trim($this->aiprompt);
if ($this->markscheme > '') {
$prompt .= ' '.$this->markscheme;
} else {
@@ -187,10 +187,10 @@ public function grade_response(array $response) : array {
*/
public function process_feedback(string $feedback) {
if (preg_match('/\{[^{}]*\}/', $feedback, $matches)) {
- // $matches[1] contains the captured text inside the braces
+ // Array $matches[1] contains the captured text inside the braces.
$feedback = $matches[0];
}
-
+ xdebug_break();
$contentobject = json_decode($feedback);
if (json_last_error() === JSON_ERROR_NONE) {
$contentobject->feedback = trim($contentobject->feedback);
diff --git a/renderer.php b/renderer.php
index 7250aca..427f073 100755
--- a/renderer.php
+++ b/renderer.php
@@ -124,23 +124,12 @@ public function feedback(question_attempt $qa, question_display_options $options
// This probably should be retrieved by an api call.
$comment = $qa->get_current_manual_comment();
if ($this->page->pagetype == 'question-bank-previewquestion-preview') {
+ $this->page->requires->js_call_amd('qtype_aitext/showprompt', 'init', []);
if ($comment[0] > '') {
$prompt = $qa->get_last_qt_var('-aiprompt');
- $js = '';
- $showprompt = get_string('showprompt', 'qtype_aitext');
- $js .= ' ';
- $js .= '