Upload 7 files
Browse files- README.md +11 -107
- app.js +97 -5
- config.js +7 -1
- index.html +4 -3
- styles.css +8 -1
README.md
CHANGED
|
@@ -14,117 +14,21 @@ short_description: Quadrilateral worksheets with CoreGX answers.
|
|
| 14 |
|
| 15 |
# CoreGX Quadrilateral Worksheet Studio
|
| 16 |
|
| 17 |
-
|
| 18 |
-
different quadrilateral questions and their CoreGX diagrams. The model chooses
|
| 19 |
-
valid givens and constructions; CoreGX renders each student diagram and
|
| 20 |
-
calculates the answer measurements. **Show answers** reveals the answer
|
| 21 |
-
construction, diagram, and CoreGX measurement in the same below-diagram
|
| 22 |
-
answer box used by the printable answer key. The model does not supply
|
| 23 |
-
the answers; CoreGX returns numeric or symbolic results. Each diagram is
|
| 24 |
-
displayed as an isolated SVG image so repeated font IDs in CoreGX's SVGs
|
| 25 |
-
cannot make later questions show the first diagram's labels.
|
| 26 |
-
After a worksheet is built, the Generate button becomes **Reroll 4 questions**.
|
| 27 |
-
Teachers can check **Keep** on any question they want to retain; the button then
|
| 28 |
-
becomes **Reroll unkept questions**. A reroll asks the model for fresh candidates
|
| 29 |
-
on the same topic but calls CoreGX only for replacement questions. The kept
|
| 30 |
-
questions, diagrams, and answers stay unchanged. The page briefly reminds
|
| 31 |
-
teachers to check AI-generated diagrams before printing. It sends a short
|
| 32 |
-
summary of the previous questions and answers to the model so it can choose
|
| 33 |
-
different givens and results. The
|
| 34 |
-
worksheet model's temperature is 0.3; the other demos' model setting is unchanged.
|
| 35 |
-
Each reroll makes a new model request and CoreGX calls, so it uses inference credits.
|
| 36 |
-
**Print worksheet** always prints the student diagrams without answers;
|
| 37 |
-
**Print answers** always prints the solved diagrams and answer boxes. The
|
| 38 |
-
print choice works independently of the on-screen **Show answers** checkbox.
|
| 39 |
-
Either browser print dialog can save a PDF, without another model or CoreGX call.
|
| 40 |
|
| 41 |
-
|
| 42 |
-
auxiliary triangles may appear inside it. The four example buttons cycle
|
| 43 |
-
through focused sides-and-angles, area-and-perimeter, diagonal, and
|
| 44 |
-
midpoint/midsegment requests. Each click describes one reusable construction
|
| 45 |
-
pattern with measurable targets; the free-text box still accepts other
|
| 46 |
-
quadrilateral topics. The model receives one detailed worksheet prompt with quadrilateral-relevant CoreGX grammar and shape definitions.
|
| 47 |
-
Its command signatures are checked against the [CoreGX language reference](https://coregx.dev/dev/language.html), with tested quadrilateral constructions added for worksheet-specific pitfalls.
|
| 48 |
-
The current topic and any requested solving method now take priority over the
|
| 49 |
-
reference examples. In particular, a Pythagorean-theorem request calls for a
|
| 50 |
-
visible right triangle with two given legs and a genuinely unknown hypotenuse,
|
| 51 |
-
not an acute-angle problem requiring trigonometry or an area question that is
|
| 52 |
-
already solved by base times height. For kite area from two given diagonals,
|
| 53 |
-
the prompt supplies a four-vertex diagonal-based kite construction instead of
|
| 54 |
-
two unconnected crossing segments.
|
| 55 |
-
For each construction category, the model defines a reusable CoreGX macro. Each
|
| 56 |
-
question calls the appropriate macro with different dimensions, plus an optional
|
| 57 |
-
answer construction and one measurement expression. Points measured outside a
|
| 58 |
-
macro must be formal point parameters, because CoreGX otherwise renames them
|
| 59 |
-
internally. The app assembles the program and adds the `measure` command, then
|
| 60 |
-
renders the four questions with CoreGX. There is no model rewrite
|
| 61 |
-
loop. Program-wide angle mode is placed before the macro definition; if a model
|
| 62 |
-
accidentally puts `anglemode` inside a macro, the app moves it outside.
|
| 63 |
-
Every worksheet now sets an angle mode explicitly: degrees by default, or
|
| 64 |
-
radians when the generated plan requests them.
|
| 65 |
-
The prompt avoids reserved CoreGX words as macro parameter names, and the app
|
| 66 |
-
also renames an accidental `angle` parameter before sending a program.
|
| 67 |
-
For rhombus macros defined as parallelograms with one adjacent-side equality,
|
| 68 |
-
the app removes redundant equal-side constraints that CoreGX treats as
|
| 69 |
-
overconstraints.
|
| 70 |
-
For a single construction topic, the prompt asks for one reusable macro and
|
| 71 |
-
four parameter sets. The shared question wording and givens are now filled
|
| 72 |
-
from each macro call, so a question cannot quietly switch shape or dimensions
|
| 73 |
-
while still using the old macro. A formed side-midpoint quadrilateral is drawn
|
| 74 |
-
in the student diagram; the app omits duplicate answer-construction commands.
|
| 75 |
-
For a broad request about the quadrilateral made from all four side midpoints,
|
| 76 |
-
the model is also guided to use a rectangle with two specified adjacent sides.
|
| 77 |
-
This determines the requested midpoint lengths, area, and perimeter without
|
| 78 |
-
supplying any answer values; other named base shapes remain available when
|
| 79 |
-
the user asks for them.
|
| 80 |
-
For a broad area-and-perimeter request, it likewise uses a dimensioned
|
| 81 |
-
rectangle rather than a general quadrilateral whose four sides do not fix
|
| 82 |
-
its area. If CoreGX leaves a composite perimeter symbolic, the answer uses
|
| 83 |
-
CoreGX's four individual side measurements and sums them; no answer value is
|
| 84 |
-
provided by the model.
|
| 85 |
-
For isosceles trapezoid leg questions with both bases and height given, the
|
| 86 |
-
prompt now includes a CoreGX-verified coordinate macro. It centers the upper
|
| 87 |
-
base from those givens, making both legs equal without a redundant congruence
|
| 88 |
-
constraint; CoreGX still derives the requested leg measurement.
|
| 89 |
-
If CoreGX leaves a free parameter such as `d_0`, the answer is shown as
|
| 90 |
-
not determined by the givens instead of displaying raw solver symbols. CoreGX
|
| 91 |
-
may report a geometry error inside an otherwise successful HTTP response. An
|
| 92 |
-
overconstraint triggers a bounded retry: the app removes the exact redundant
|
| 93 |
-
constraint CoreGX identifies, then reruns both student and answer diagrams with
|
| 94 |
-
the same seed. It will not silently remove a one-off length or angle given.
|
| 95 |
-
If a safe repair is unavailable, the worksheet still shows any usable SVG and
|
| 96 |
-
marks its missing measurement unavailable. Other geometry errors and missing
|
| 97 |
-
student diagrams still stop the worksheet.
|
| 98 |
|
| 99 |
-
##
|
| 100 |
|
| 101 |
-
1.
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
route and its 32B model; `worker-update.js` remains a reference copy. If
|
| 108 |
-
you replace the whole Worker later, first check that any changes you made
|
| 109 |
-
directly in Cloudflare are also present in that file.
|
| 110 |
-
4. Refresh the Space. Generate a worksheet and test both answer-toggle
|
| 111 |
-
positions and a partial reroll with one or more questions kept. A static page opened from disk is not sufficient because
|
| 112 |
-
it fetches its prompt file.
|
| 113 |
|
| 114 |
-
|
| 115 |
-
Hugging Face with the private `HF_TOKEN`. It does not call Gemma or Workers AI.
|
| 116 |
-
The browser and Space files never receive the token. The other demo routes
|
| 117 |
-
still use the 7B Hugging Face model. Worksheet requests use Hugging Face
|
| 118 |
-
credits and can exhaust the free monthly allowance. The Space remains static, but
|
| 119 |
-
its model and CoreGX calls are remote. A completed worksheet makes eight
|
| 120 |
-
CoreGX calls: student and answer versions of four questions, now sequentially
|
| 121 |
-
to avoid overlapping solver requests. Consider
|
| 122 |
-
rate limits before making the Space public. CORS origin checks alone do
|
| 123 |
-
not protect a public Worker against scripted requests.
|
| 124 |
|
| 125 |
## Local preview
|
| 126 |
|
| 127 |
-
Serve this
|
| 128 |
-
`http://127.0.0.1:7864/`. Add that localhost origin to the Worker's
|
| 129 |
-
allowed origins before testing generation locally. Run `node test.mjs`
|
| 130 |
-
to verify the local app/Worker contract without spending model credits.
|
|
|
|
| 14 |
|
| 15 |
# CoreGX Quadrilateral Worksheet Studio
|
| 16 |
|
| 17 |
+
Generate a four-question quadrilateral worksheet from a topic description. A hosted language model designs the questions and CoreGX programs; CoreGX draws the student diagrams and calculates the answers. Teachers can reroll unkept questions, edit and re-render a question's CoreGX programs, toggle answers on screen, and print separate student and answer copies. Review AI-generated diagrams and givens before handing out a worksheet.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
This is a **Static** Hugging Face Space. It needs a separate server to call the language model and CoreGX; it does not run the model or store credentials in the browser.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
## Make your own Space
|
| 22 |
|
| 23 |
+
1. Create or duplicate a **Static** Hugging Face Space. Find its direct `.hf.space` app origin; the `huggingface.co/spaces/...` page URL is different.
|
| 24 |
+
2. Get your own [CoreGX API key](https://coregx.dev/dev/index.html). The included model integration also needs a Hugging Face inference token, provider access, and enough credits for its 32B Qwen coder model. A different model/provider is possible if you adapt the server-side call.
|
| 25 |
+
3. Provide an HTTPS backend. A Cloudflare Worker is one option; a Node/Python service or server-backed Space can replace it. Preserve `POST /generate-worksheet` (returns `{ok:true,content:"worksheet JSON"}`) and `POST /solve-worksheet` (forwards CoreGX SVG and measurement responses). Configure CORS for your Space's origin if the backend is elsewhere.
|
| 26 |
+
4. Put `COREGX_API_KEY` and `HF_TOKEN` in **backend secrets/environment variables**. Worker code reads `env.COREGX_API_KEY` for the CoreGX request's `apikey` and `env.HF_TOKEN` for the model bearer token; a Node server would use `process.env.COREGX_API_KEY` and `process.env.HF_TOKEN`. `WORKSHEET_MODEL` in the server code selects the actual worksheet model. For the Worker option, set `ALLOWED_ORIGINS` to your exact Space origin (no path or trailing slash).
|
| 27 |
+
5. In `config.js`, set `spaceOrigin` to your direct origin and `workerUrl` to **your backend's** public HTTPS base URL. The setting is named `workerUrl` but does not require Cloudflare. A duplicate intentionally has no usable backend until you configure it.
|
| 28 |
+
6. Upload `README.md`, `index.html`, `styles.css`, `app.js`, `config.js`, and `system_prompt.txt` to the Space root. Deploy the backend separately; the Static Space does not execute its source code. Commit, refresh, and generate a worksheet. Test both print buttons and a partial reroll. `coregx_reference.txt` is a developer reference, not required at runtime.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
Never put literal credentials in a public Static Space repository, `app.js`, `config.js`, or Static Space variables: browser code can expose them. Keys belong on the server, preferably in secrets/environment instead of committed source. Generation and re-renders use model or CoreGX credits. A public backend needs rate or spending limits; an origin allowlist is not authentication because non-browser clients can forge `Origin`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
## Local preview
|
| 33 |
|
| 34 |
+
Serve this folder with `python -m http.server 7864` and open `http://127.0.0.1:7864/`. Allow that exact localhost origin on your backend for live requests. Opening `index.html` directly from disk will not load the prompt. Run `node test.mjs` for code checks without spending model credits.
|
|
|
|
|
|
|
|
|
app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
const BUILD_ID = "20261006-worksheet-
|
| 2 |
const PROXY_URL = String(window.WORKSHEET_STUDIO_CONFIG?.coregxProxyUrl || "").trim();
|
| 3 |
|
| 4 |
const EXAMPLES = {
|
|
@@ -37,6 +37,7 @@ const ui = {
|
|
| 37 |
};
|
| 38 |
let worksheet = null;
|
| 39 |
let lastDescription = "";
|
|
|
|
| 40 |
|
| 41 |
function status(message, error = false) {
|
| 42 |
ui.status.textContent = message;
|
|
@@ -629,11 +630,73 @@ async function solveQuestion(item, seed) {
|
|
| 629 |
overconstraint,
|
| 630 |
repairedOverconstraint,
|
| 631 |
answerNotice,
|
|
|
|
| 632 |
studentProgram: base,
|
| 633 |
answerProgram
|
| 634 |
};
|
| 635 |
}
|
| 636 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 637 |
function showResult() {
|
| 638 |
if (!worksheet) return;
|
| 639 |
ui.worksheet.replaceChildren();
|
|
@@ -673,10 +736,36 @@ function showResult() {
|
|
| 673 |
answerList.append(note);
|
| 674 |
}
|
| 675 |
answers.append(answerList);
|
| 676 |
-
const details = document.createElement("details");
|
| 677 |
-
|
| 678 |
-
const
|
| 679 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
card.append(headingRow, prompt, givens, diagram, answers, details);
|
| 681 |
ui.worksheet.append(card);
|
| 682 |
}
|
|
@@ -687,11 +776,13 @@ function showResult() {
|
|
| 687 |
}
|
| 688 |
|
| 689 |
async function generate() {
|
|
|
|
| 690 |
const description = ui.description.value.trim();
|
| 691 |
if (!description) return status("Describe a worksheet first.", true);
|
| 692 |
const reroll = worksheet && description === lastDescription;
|
| 693 |
const kept = reroll ? worksheet.items.map(item => Boolean(item.keep)) : [false, false, false, false];
|
| 694 |
if (kept.every(Boolean)) return status("Uncheck at least one question to reroll.");
|
|
|
|
| 695 |
ui.generate.disabled = true;
|
| 696 |
ui.generate.textContent = reroll ? "Rerolling…" : "Generating…";
|
| 697 |
try {
|
|
@@ -720,6 +811,7 @@ async function generate() {
|
|
| 720 |
} catch (error) {
|
| 721 |
status(error instanceof Error ? error.message : String(error), true);
|
| 722 |
} finally {
|
|
|
|
| 723 |
ui.generate.disabled = false;
|
| 724 |
updateGenerateLabel();
|
| 725 |
}
|
|
|
|
| 1 |
+
const BUILD_ID = "20261006-worksheet-58";
|
| 2 |
const PROXY_URL = String(window.WORKSHEET_STUDIO_CONFIG?.coregxProxyUrl || "").trim();
|
| 3 |
|
| 4 |
const EXAMPLES = {
|
|
|
|
| 37 |
};
|
| 38 |
let worksheet = null;
|
| 39 |
let lastDescription = "";
|
| 40 |
+
let busy = false;
|
| 41 |
|
| 42 |
function status(message, error = false) {
|
| 43 |
ui.status.textContent = message;
|
|
|
|
| 630 |
overconstraint,
|
| 631 |
repairedOverconstraint,
|
| 632 |
answerNotice,
|
| 633 |
+
seed,
|
| 634 |
studentProgram: base,
|
| 635 |
answerProgram
|
| 636 |
};
|
| 637 |
}
|
| 638 |
|
| 639 |
+
async function rerenderQuestion(index, feedback, button) {
|
| 640 |
+
if (busy || !worksheet) return;
|
| 641 |
+
const item = worksheet.items[index];
|
| 642 |
+
const studentProgram = String(item.studentDraft ?? item.studentProgram).trim();
|
| 643 |
+
const answerProgram = String(item.answerDraft ?? item.answerProgram).trim();
|
| 644 |
+
if (!studentProgram || !answerProgram) {
|
| 645 |
+
feedback.textContent = "Both CoreGX programs need code.";
|
| 646 |
+
feedback.classList.toggle("error", true);
|
| 647 |
+
return;
|
| 648 |
+
}
|
| 649 |
+
busy = true;
|
| 650 |
+
button.disabled = true;
|
| 651 |
+
ui.generate.disabled = true;
|
| 652 |
+
feedback.textContent = "Sending to CoreGX…";
|
| 653 |
+
feedback.classList.toggle("error", false);
|
| 654 |
+
try {
|
| 655 |
+
const seed = item.seed ?? 24001 + index;
|
| 656 |
+
const student = await post("solve-worksheet", { program: studentProgram, svg: true, seed });
|
| 657 |
+
const studentErrors = coregxErrors(student.value, "invalid worksheet diagram");
|
| 658 |
+
if (studentErrors.length) throw new Error("CoreGX: " + String(studentErrors[0].message || "overconstrained worksheet diagram"));
|
| 659 |
+
const svg = student.value?.svg;
|
| 660 |
+
if (typeof svg !== "string" || !svg.includes("<svg")) throw new Error("CoreGX returned no worksheet diagram.");
|
| 661 |
+
|
| 662 |
+
const answer = await post("solve-worksheet", { program: answerProgram, svg: true, equations: true, seed });
|
| 663 |
+
const answerErrors = coregxErrors(answer.value, "invalid answer diagram");
|
| 664 |
+
if (answerErrors.length) throw new Error("CoreGX: " + String(answerErrors[0].message || "overconstrained answer diagram"));
|
| 665 |
+
const answerSvg = answer.value?.svg;
|
| 666 |
+
if (typeof answerSvg !== "string" || !answerSvg.includes("<svg")) throw new Error("CoreGX returned no answer diagram.");
|
| 667 |
+
const measured = measuredAnswers(answer.value, answerProgram);
|
| 668 |
+
if (!measured.length || /^error$/i.test(measured[0].expression) || /^error$/i.test(measured[0].valueTex)) {
|
| 669 |
+
throw new Error("The answer program needs a working measure command.");
|
| 670 |
+
}
|
| 671 |
+
const primary = /^perimeter\s*\(/i.test(measured[0].expression) ?
|
| 672 |
+
resolvedPerimeter(measured[0], measured.slice(1)) : measured[0];
|
| 673 |
+
item.svg = svg;
|
| 674 |
+
item.answerSvg = answerSvg;
|
| 675 |
+
item.equations = [primary];
|
| 676 |
+
item.unresolved = isIndeterminateMeasurement(primary.valueTex) || hasFreeSolverParameter(primary.valueTex);
|
| 677 |
+
item.overconstraint = false;
|
| 678 |
+
item.repairedOverconstraint = false;
|
| 679 |
+
item.answerNotice = "";
|
| 680 |
+
item.studentProgram = studentProgram + "\n";
|
| 681 |
+
item.answerProgram = answerProgram + "\n";
|
| 682 |
+
item.studentDraft = undefined;
|
| 683 |
+
item.answerDraft = undefined;
|
| 684 |
+
item.answerEdited = false;
|
| 685 |
+
item.seed = seed;
|
| 686 |
+
showResult();
|
| 687 |
+
status("Question " + (index + 1) + " updated with CoreGX.");
|
| 688 |
+
} catch (error) {
|
| 689 |
+
feedback.textContent = error instanceof Error ? error.message : String(error);
|
| 690 |
+
feedback.classList.toggle("error", true);
|
| 691 |
+
status("Question " + (index + 1) + ": " + feedback.textContent, true);
|
| 692 |
+
} finally {
|
| 693 |
+
busy = false;
|
| 694 |
+
button.disabled = false;
|
| 695 |
+
ui.generate.disabled = false;
|
| 696 |
+
updateGenerateLabel();
|
| 697 |
+
}
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
function showResult() {
|
| 701 |
if (!worksheet) return;
|
| 702 |
ui.worksheet.replaceChildren();
|
|
|
|
| 736 |
answerList.append(note);
|
| 737 |
}
|
| 738 |
answers.append(answerList);
|
| 739 |
+
const details = document.createElement("details"); details.open = Boolean(item.programOpen);
|
| 740 |
+
details.addEventListener("toggle", () => { item.programOpen = details.open; });
|
| 741 |
+
const summary = document.createElement("summary"); summary.textContent = "CoreGX programs";
|
| 742 |
+
const note = document.createElement("p"); note.className = "program-note";
|
| 743 |
+
note.textContent = "Edits update diagrams and answers, not the question wording or givens.";
|
| 744 |
+
const studentLabel = document.createElement("label"); studentLabel.className = "program-label";
|
| 745 |
+
studentLabel.htmlFor = "student-program-" + index; studentLabel.textContent = "Worksheet diagram";
|
| 746 |
+
const studentEditor = document.createElement("textarea"); studentEditor.className = "program-editor student-program-editor";
|
| 747 |
+
studentEditor.id = studentLabel.htmlFor; studentEditor.rows = 9; studentEditor.spellcheck = false;
|
| 748 |
+
studentEditor.value = item.studentDraft ?? item.studentProgram;
|
| 749 |
+
const answerLabelElement = document.createElement("label"); answerLabelElement.className = "program-label";
|
| 750 |
+
answerLabelElement.htmlFor = "answer-program-" + index; answerLabelElement.textContent = "Answer diagram and measurement";
|
| 751 |
+
const answerEditor = document.createElement("textarea"); answerEditor.className = "program-editor answer-program-editor";
|
| 752 |
+
answerEditor.id = answerLabelElement.htmlFor; answerEditor.rows = 9; answerEditor.spellcheck = false;
|
| 753 |
+
answerEditor.value = item.answerDraft ?? item.answerProgram;
|
| 754 |
+
studentEditor.addEventListener("input", () => {
|
| 755 |
+
const previous = item.studentDraft ?? item.studentProgram;
|
| 756 |
+
const currentAnswer = item.answerDraft ?? item.answerProgram;
|
| 757 |
+
item.studentDraft = studentEditor.value;
|
| 758 |
+
if (!item.answerEdited && currentAnswer.startsWith(previous.trimEnd())) {
|
| 759 |
+
item.answerDraft = studentEditor.value.trimEnd() + currentAnswer.slice(previous.trimEnd().length);
|
| 760 |
+
answerEditor.value = item.answerDraft;
|
| 761 |
+
}
|
| 762 |
+
});
|
| 763 |
+
answerEditor.addEventListener("input", () => { item.answerDraft = answerEditor.value; item.answerEdited = true; });
|
| 764 |
+
const rerender = document.createElement("button"); rerender.type = "button"; rerender.className = "rerender-question";
|
| 765 |
+
rerender.textContent = "Re-render this question";
|
| 766 |
+
const feedback = document.createElement("p"); feedback.className = "program-feedback"; feedback.setAttribute("role", "status");
|
| 767 |
+
rerender.addEventListener("click", () => rerenderQuestion(index, feedback, rerender));
|
| 768 |
+
details.append(summary, note, studentLabel, studentEditor, answerLabelElement, answerEditor, rerender, feedback);
|
| 769 |
card.append(headingRow, prompt, givens, diagram, answers, details);
|
| 770 |
ui.worksheet.append(card);
|
| 771 |
}
|
|
|
|
| 776 |
}
|
| 777 |
|
| 778 |
async function generate() {
|
| 779 |
+
if (busy) return;
|
| 780 |
const description = ui.description.value.trim();
|
| 781 |
if (!description) return status("Describe a worksheet first.", true);
|
| 782 |
const reroll = worksheet && description === lastDescription;
|
| 783 |
const kept = reroll ? worksheet.items.map(item => Boolean(item.keep)) : [false, false, false, false];
|
| 784 |
if (kept.every(Boolean)) return status("Uncheck at least one question to reroll.");
|
| 785 |
+
busy = true;
|
| 786 |
ui.generate.disabled = true;
|
| 787 |
ui.generate.textContent = reroll ? "Rerolling…" : "Generating…";
|
| 788 |
try {
|
|
|
|
| 811 |
} catch (error) {
|
| 812 |
status(error instanceof Error ? error.message : String(error), true);
|
| 813 |
} finally {
|
| 814 |
+
busy = false;
|
| 815 |
ui.generate.disabled = false;
|
| 816 |
updateGenerateLabel();
|
| 817 |
}
|
config.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
window.WORKSHEET_STUDIO_CONFIG = {
|
| 2 |
-
coregxProxyUrl:
|
|
|
|
| 3 |
};
|
|
|
|
| 1 |
+
// A copied Space must supply its own origin, Worker, and API credentials.
|
| 2 |
+
const WORKSHEET_DEPLOYMENT = {
|
| 3 |
+
spaceOrigin: "https://saltiresoftware-coregx-worksheet.static.hf.space",
|
| 4 |
+
workerUrl: "https://coregx-proxy.mis-c31.workers.dev/",
|
| 5 |
+
};
|
| 6 |
window.WORKSHEET_STUDIO_CONFIG = {
|
| 7 |
+
coregxProxyUrl: window.location.origin === WORKSHEET_DEPLOYMENT.spaceOrigin
|
| 8 |
+
? WORKSHEET_DEPLOYMENT.workerUrl : "",
|
| 9 |
};
|
index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>CoreGX Quadrilateral Worksheet Studio</title>
|
| 7 |
-
<link rel="stylesheet" href="styles.css?v=20261006-worksheet-
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<main class="page">
|
|
@@ -43,9 +43,10 @@
|
|
| 43 |
<footer class="site-footer">
|
| 44 |
<p>CoreGX is a constraint-based geometry engine. Send a request in the CoreGX language and receive precise SVG output and symbolic measurements in return. This demo uses an LLM to convert natural language into CoreGX. Visit <a href="https://coregx.dev/dev/index.html" target="_blank" rel="noopener noreferrer">coregx.dev</a> to get your own CoreGX API key.</p>
|
| 45 |
<p>Explore the <a href="https://huggingface.co/spaces/saltiresoftware/coregx-triangles" target="_blank" rel="noopener noreferrer">triangle</a>, <a href="https://huggingface.co/spaces/saltiresoftware/CoreGX-Cams" target="_blank" rel="noopener noreferrer">CAM</a>, and <a href="https://huggingface.co/spaces/saltiresoftware/coregx-multilingual" target="_blank" rel="noopener noreferrer">multilingual circle</a> demos. For broader natural language geometry, try <a href="https://gengx.geometryexpressions.com/" target="_blank" rel="noopener noreferrer">GenGX</a>.</p>
|
|
|
|
| 46 |
</footer>
|
| 47 |
</main>
|
| 48 |
-
<script src="config.js?v=
|
| 49 |
-
<script type="module" src="app.js?v=20261006-worksheet-
|
| 50 |
</body>
|
| 51 |
</html>
|
|
|
|
| 4 |
<meta charset="utf-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
<title>CoreGX Quadrilateral Worksheet Studio</title>
|
| 7 |
+
<link rel="stylesheet" href="styles.css?v=20261006-worksheet-58">
|
| 8 |
</head>
|
| 9 |
<body>
|
| 10 |
<main class="page">
|
|
|
|
| 43 |
<footer class="site-footer">
|
| 44 |
<p>CoreGX is a constraint-based geometry engine. Send a request in the CoreGX language and receive precise SVG output and symbolic measurements in return. This demo uses an LLM to convert natural language into CoreGX. Visit <a href="https://coregx.dev/dev/index.html" target="_blank" rel="noopener noreferrer">coregx.dev</a> to get your own CoreGX API key.</p>
|
| 45 |
<p>Explore the <a href="https://huggingface.co/spaces/saltiresoftware/coregx-triangles" target="_blank" rel="noopener noreferrer">triangle</a>, <a href="https://huggingface.co/spaces/saltiresoftware/CoreGX-Cams" target="_blank" rel="noopener noreferrer">CAM</a>, and <a href="https://huggingface.co/spaces/saltiresoftware/coregx-multilingual" target="_blank" rel="noopener noreferrer">multilingual circle</a> demos. For broader natural language geometry, try <a href="https://gengx.geometryexpressions.com/" target="_blank" rel="noopener noreferrer">GenGX</a>.</p>
|
| 46 |
+
<p>To construct, manipulate, and explore dynamic shapes, try <a href="https://www.geometryexpressions.com/gxweb/" target="_blank" rel="noopener noreferrer">GXWeb</a>.</p>
|
| 47 |
</footer>
|
| 48 |
</main>
|
| 49 |
+
<script src="config.js?v=20261007-new-worker-1"></script>
|
| 50 |
+
<script type="module" src="app.js?v=20261006-worksheet-58"></script>
|
| 51 |
</body>
|
| 52 |
</html>
|
styles.css
CHANGED
|
@@ -49,7 +49,14 @@ h1{margin:0;color:var(--blue);font-size:clamp(2.2rem,5.5vw,4rem);letter-spacing:
|
|
| 49 |
.answers li{margin:3px 0;overflow-wrap:anywhere}
|
| 50 |
.question-card details{margin-top:16px;border-top:1px solid #d5e5f8}
|
| 51 |
.question-card summary{padding:9px 0;cursor:pointer;color:#124f9d;font-size:.85rem;font-weight:750}
|
| 52 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
.site-footer{margin-top:28px;border-left:3px solid var(--blue);padding:4px 0 4px 14px;color:#705d86;font-size:.96rem;line-height:1.5}
|
| 54 |
.site-footer p{margin:0 0 5px}
|
| 55 |
.site-footer a{color:#124f9d;font-weight:800}
|
|
|
|
| 49 |
.answers li{margin:3px 0;overflow-wrap:anywhere}
|
| 50 |
.question-card details{margin-top:16px;border-top:1px solid #d5e5f8}
|
| 51 |
.question-card summary{padding:9px 0;cursor:pointer;color:#124f9d;font-size:.85rem;font-weight:750}
|
| 52 |
+
.program-note{margin:0 0 10px!important;color:#526677;font-size:.78rem}
|
| 53 |
+
.program-label{display:block;margin:11px 0 5px;color:#124f9d;font-size:.82rem;font-weight:750}
|
| 54 |
+
.program-editor{display:block;width:100%;min-height:130px;resize:vertical;border:1px solid #b8d0ee;background:#f8fbff;padding:9px;color:var(--ink);font:.77rem/1.5 ui-monospace,Consolas,monospace;white-space:pre;overflow:auto}
|
| 55 |
+
.program-editor:focus{outline:2px solid var(--blue);outline-offset:1px}
|
| 56 |
+
.rerender-question{margin-top:11px;border:1px solid var(--blue);background:#dcecff;color:#124f9d;padding:8px 11px;font-size:.83rem;font-weight:750}
|
| 57 |
+
.rerender-question:disabled{cursor:default;opacity:.55}
|
| 58 |
+
.program-feedback{min-height:1.2em;margin:7px 0 0!important;color:#526677;font-size:.8rem}
|
| 59 |
+
.program-feedback.error{color:#a92158}
|
| 60 |
.site-footer{margin-top:28px;border-left:3px solid var(--blue);padding:4px 0 4px 14px;color:#705d86;font-size:.96rem;line-height:1.5}
|
| 61 |
.site-footer p{margin:0 0 5px}
|
| 62 |
.site-footer a{color:#124f9d;font-weight:800}
|