agent-lyra 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +395 -173
- package/bin/agent-lyra.js +16 -3
- package/package.json +60 -56
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/preview.js +22 -22
- package/src/app-builder/saved-app.js +70 -70
- package/src/app-builder/saved-preview-browser.js +33 -33
- package/src/app-builder/saved-preview.html +24 -24
- package/src/app-builder/saved-preview.js +61 -61
- package/src/app-builder/validate.js +64 -64
- package/src/memory/cli.js +49 -0
- package/src/memory/contract.json +28 -0
- package/src/memory/index.d.ts +49 -0
- package/src/memory/index.js +259 -0
- package/src/memory/lifecycle.js +29 -0
- package/src/memory/proposals.js +84 -0
- package/src/memory/skills-cli.js +26 -0
- package/src/memory/sync.js +85 -0
- package/src/memory/validation.js +25 -0
- package/src/runtime/local-cli.js +2 -1
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -289
- package/src/studio/export.js +80 -79
- package/src/studio/index.html +37 -16
- package/src/studio/memory-actions.js +37 -0
- package/src/studio/memory-panel.js +200 -0
- package/src/studio/project.js +197 -190
- package/src/studio/pull-agent.js +72 -0
- package/src/studio/push.js +54 -0
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -102
- package/src/studio/session.js +83 -0
- package/src/studio/studio.css +10 -7
- package/src/studio/sync.js +42 -39
- package/src/studio/workflow-sync.js +157 -0
package/src/studio/export.js
CHANGED
|
@@ -1,79 +1,80 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { pythonSource } from "./python-agent.js";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { readCatalog, resolveSequence, validateLayout } from "./project.js";
|
|
5
|
-
|
|
6
|
-
const runtime = [
|
|
7
|
-
"studio/server.js", "studio/project.js", "studio/sync.js", "studio/index.html",
|
|
8
|
-
"studio/browser.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
workflows.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
["
|
|
60
|
-
["
|
|
61
|
-
["
|
|
62
|
-
[".
|
|
63
|
-
["
|
|
64
|
-
["
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
throw
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { pythonSource } from "./python-agent.js";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { readCatalog, resolveSequence, validateLayout } from "./project.js";
|
|
5
|
+
|
|
6
|
+
const runtime = [
|
|
7
|
+
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html",
|
|
8
|
+
"studio/browser.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
9
|
+
"memory/index.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
|
|
10
|
+
"runtime/local-cli.js", "runtime/run-agent.js", "studio/session.js", "studio/push.js", "studio/workflow-sync.js", "studio/pull-agent.js", "studio/python-agent.js", "studio/python-agent.py",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export async function exportStudioApp(app, root, directory) {
|
|
14
|
+
const layout = validateLayout(app.studio.layout);
|
|
15
|
+
if (!layout.length) throw new Error("Add components to the Studio canvas and save before exporting.");
|
|
16
|
+
const catalog = await readCatalog(root);
|
|
17
|
+
const agents = new Map();
|
|
18
|
+
const workflows = new Map();
|
|
19
|
+
const buttons = layout.filter(node => ["button", "agent-card"].includes(node.kind));
|
|
20
|
+
for (const button of buttons) {
|
|
21
|
+
if ((button.sourceId && !layout.some(node => node.id === button.sourceId && ["input", "textarea"].includes(node.kind))) ||
|
|
22
|
+
(button.outputId && !layout.some(node => node.id === button.outputId && node.kind === "output"))) {
|
|
23
|
+
throw new Error("Fix the input or output binding for " + button.label + " in Studio.");
|
|
24
|
+
}
|
|
25
|
+
let sequence;
|
|
26
|
+
try {
|
|
27
|
+
sequence = resolveSequence(catalog, button.targets);
|
|
28
|
+
if (button.kind === "agent-card" && !catalog.agents.has(button.targets[0])) {
|
|
29
|
+
throw new Error("Choose one agent for this card.");
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new Error("Fix the run targets for " + button.label + ": " + error.message);
|
|
33
|
+
}
|
|
34
|
+
for (const { agentId } of sequence) agents.set(agentId, catalog.agents.get(agentId));
|
|
35
|
+
for (const target of button.targets.filter(id => id.startsWith("workflow:"))) {
|
|
36
|
+
const workflow = catalog.workflows.find(item => "workflow:" + item.id === target);
|
|
37
|
+
workflows.set(workflow.id, {
|
|
38
|
+
id: workflow.id, name: workflow.name, runnable: true,
|
|
39
|
+
steps: workflow.steps.map(({ agentId, task, input, output }) => ({ agentId, task, input, output })),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const name = typeof app.application?.name === "string" ? app.application.name : "Lyra app";
|
|
44
|
+
const files = await Promise.all(runtime.map(async file => [
|
|
45
|
+
"runtime/" + file, await readFile(new URL("../" + file, import.meta.url)),
|
|
46
|
+
]));
|
|
47
|
+
const pythonAgents = [...agents.values()].filter(agent => agent.source === "python");
|
|
48
|
+
const pythonFiles = new Map();
|
|
49
|
+
for (const agent of pythonAgents) {
|
|
50
|
+
if (pythonFiles.has(agent.file)) continue;
|
|
51
|
+
const path = await pythonSource(root, agent, false);
|
|
52
|
+
pythonFiles.set(agent.file, await readFile(path));
|
|
53
|
+
}
|
|
54
|
+
for (const [filename, source] of pythonFiles) files.push(["python-agents/" + filename, source]);
|
|
55
|
+
const pythonNotes = pythonAgents.length
|
|
56
|
+
? "\nInstall the Python SDK and any agent dependencies in your Python environment. Set LYRA_PYTHON to its interpreter if needed. The python-agents folder contains the source of the bound agents.\n"
|
|
57
|
+
: "";
|
|
58
|
+
files.push(
|
|
59
|
+
["LICENSE", await readFile(new URL("../../LICENSE", import.meta.url))],
|
|
60
|
+
["package.json", { name: "lyra-app", version: "1.0.0", private: true, type: "module", engines: { node: ">=22.13.0" }, scripts: { start: "node server.js" } }],
|
|
61
|
+
["manifest.json", { version: "3.0", application: { id: "lyra-app", name }, studio: { layout } }],
|
|
62
|
+
["catalog.json", { agents: [...agents.values()], workflows: [...workflows.values()] }],
|
|
63
|
+
[".gitignore", ".lyra/\n.env\n"],
|
|
64
|
+
["README.md", "# Run the exported Lyra app\n\nUse Node.js 22.13 or newer. Run `npm start` and open the loopback URL printed in the terminal.\n\nLocal agents require `OPENAI_API_KEY`. Cloud agents require `LYRA_API_KEY`, plus an OpenAI key configured in Cloud Models. Set credentials in the environment. The export includes system prompts for referenced local agents. The server is intended for local use.\n" + pythonNotes],
|
|
65
|
+
["server.js", 'import { readFile } from "node:fs/promises";\nimport { fileURLToPath } from "node:url";\nimport { startStudio } from "./runtime/studio/server.js";\n\nconst snapshot = JSON.parse(await readFile(new URL("./catalog.json", import.meta.url), "utf8"));\nconst catalog = { agents: new Map(snapshot.agents.map(agent => [agent.id, agent])), workflows: snapshot.workflows, teams: [] };\nconst { url } = await startStudio(fileURLToPath(new URL(".", import.meta.url)), { appCatalog: catalog });\nconsole.log("Lyra app: " + url);\n'],
|
|
66
|
+
);
|
|
67
|
+
try {
|
|
68
|
+
await mkdir(directory);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
for (const [file, contents] of files) {
|
|
74
|
+
const path = join(directory, file);
|
|
75
|
+
await mkdir(dirname(path), { recursive: true });
|
|
76
|
+
await writeFile(path, typeof contents === "string" || Buffer.isBuffer(contents)
|
|
77
|
+
? contents
|
|
78
|
+
: JSON.stringify(contents, null, 2) + "\n", { flag: "wx" });
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/studio/index.html
CHANGED
|
@@ -1,16 +1,37 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
-
<title>AgentLyra Studio</title><link rel="stylesheet" href="/studio.css"><link rel="stylesheet" href="/agent-ui.css"><script src="/studio.js" type="module"></script>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<header><strong>AgentLyra Studio</strong><span id="project-name"></span><div><button id="refresh">Reload agents</button> <button id="pull">Pull from Cloud</button> <button class="primary" id="save">Save layout</button></div></header>
|
|
9
|
-
<p role="status" id="status"></p>
|
|
10
|
-
<main>
|
|
11
|
-
<aside><h2>Components</h2><div id="palette"></div><h2>Agents</h2><div id="agents"></div><h2>Workflows</h2><div id="workflows"></div><h2>Teams</h2><div id="teams"></div></aside>
|
|
12
|
-
<section><h1>App canvas</h1><p>Drop a component here or select it from the palette. Use the inspector to bind an Agent card or Run button to your inputs and outputs.</p><div id="canvas"></div></section>
|
|
13
|
-
<aside><h2>Inspector</h2><div id="inspector"></div></aside>
|
|
14
|
-
</main>
|
|
15
|
-
<dialog id="
|
|
16
|
-
</
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<title>AgentLyra Studio</title><link rel="stylesheet" href="/studio.css"><link rel="stylesheet" href="/agent-ui.css"><script src="/studio.js" type="module"></script>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<header><strong>AgentLyra Studio</strong><span id="project-name"></span><div><button id="open-memory" type="button" hidden>Memory</button> <button id="refresh">Reload agents</button> <button id="pull">Pull from Cloud</button> <button class="primary" id="save">Save layout</button></div></header>
|
|
9
|
+
<p role="status" id="status"></p>
|
|
10
|
+
<main>
|
|
11
|
+
<aside><h2>Components</h2><div id="palette"></div><h2>Agents</h2><div id="agents"></div><h2>Workflows</h2><div id="workflows"></div><h2>Teams</h2><div id="teams"></div><h2>Skills</h2><div id="skills"></div></aside>
|
|
12
|
+
<section><h1>App canvas</h1><p>Drop a component here or select it from the palette. Use the inspector to bind an Agent card or Run button to your inputs and outputs.</p><div id="canvas"></div></section>
|
|
13
|
+
<aside><h2>Inspector</h2><div id="inspector"></div></aside>
|
|
14
|
+
</main>
|
|
15
|
+
<dialog id="memory-panel" aria-labelledby="memory-title">
|
|
16
|
+
<header><h2 id="memory-title">Memory</h2><button id="close-memory" type="button">Close</button></header>
|
|
17
|
+
<p>Project memories stay local until you choose to upload a verified record.</p>
|
|
18
|
+
<p id="memory-status" role="status"></p>
|
|
19
|
+
<p id="memory-summary"></p>
|
|
20
|
+
<form id="memory-search"><label for="memory-query">Search project memories</label><input id="memory-query" maxlength="240"><button type="submit">Search</button></form>
|
|
21
|
+
<details><summary>Record a candidate</summary><form id="memory-create">
|
|
22
|
+
<label>Type<select name="type"><option>corrective</option><option>episodic</option><option>semantic</option><option>procedural</option></select></label>
|
|
23
|
+
<label>Title<input name="title" maxlength="160" required></label>
|
|
24
|
+
<label>Learning<textarea name="learning" maxlength="4000" required></textarea></label>
|
|
25
|
+
<label>Evidence IDs, separated by commas<input name="evidence" maxlength="2048"></label>
|
|
26
|
+
<button type="submit">Record candidate</button>
|
|
27
|
+
</form></details>
|
|
28
|
+
<details><summary>Pull a Cloud memory</summary><form id="memory-pull">
|
|
29
|
+
<label>Cloud memory ID<input name="id" maxlength="36" required></label>
|
|
30
|
+
<button type="submit">Pull from Cloud</button>
|
|
31
|
+
</form></details>
|
|
32
|
+
<div id="memory-list" aria-label="Project memories"></div>
|
|
33
|
+
<section id="memory-detail" aria-label="Selected memory"></section>
|
|
34
|
+
<details><summary>Skill proposals</summary><section id="memory-proposals" aria-label="Skill proposals"></section></details>
|
|
35
|
+
</dialog>
|
|
36
|
+
<dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><label for="model">Local model</label><select id="model"></select><label for="prompt">Input</label><textarea id="prompt" maxlength="4000" rows="6" required></textarea><button class="primary" id="run">Run</button><p role="status" id="run-status"></p><pre id="run-result"></pre></form></dialog>
|
|
37
|
+
</body></html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { openMemoryStore } from "../memory/index.js";
|
|
2
|
+
import { syncMemory } from "../memory/sync.js";
|
|
3
|
+
|
|
4
|
+
export function memoryActions(root) {
|
|
5
|
+
return new Map([
|
|
6
|
+
["/api/memory/list", ({ query = "" }) => useStore(root, store => ({
|
|
7
|
+
records: query.trim() ? store.search(query, 50) : store.list(50), stats: store.stats(),
|
|
8
|
+
}))],
|
|
9
|
+
["/api/memory/record", body => useStore(root, store => store.record({
|
|
10
|
+
...body, evidence: typeof body.evidence === "string" ? body.evidence.split(",").map(value => value.trim()).filter(Boolean) : body.evidence,
|
|
11
|
+
}))],
|
|
12
|
+
["/api/memory/archive", ({ id }) => useStore(root, store => {
|
|
13
|
+
const record = store.archive(id);
|
|
14
|
+
if (!record) throw new Error("Memory record was not found.");
|
|
15
|
+
return record;
|
|
16
|
+
})],
|
|
17
|
+
["/api/memory/preview", ({ id }) => syncMemory(root, "preview", id)],
|
|
18
|
+
["/api/memory/push", ({ id, fingerprint }) => {
|
|
19
|
+
if (typeof fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(fingerprint)) throw new Error("Preview the outbound memory before uploading.");
|
|
20
|
+
return syncMemory(root, "push", id, { confirmed: true, expectedPreview: fingerprint });
|
|
21
|
+
}],
|
|
22
|
+
["/api/memory/pull", ({ id }) => syncMemory(root, "pull", id)],
|
|
23
|
+
["/api/memory/compare", ({ id }) => syncMemory(root, "compare", id)],
|
|
24
|
+
["/api/memory/resolve", ({ id, choice, fingerprint }) =>
|
|
25
|
+
syncMemory(root, "resolve", id, { choice, expectedConflict: fingerprint })],
|
|
26
|
+
["/api/memory/verify", ({ id, evidence }) => useStore(root, store => store.verify(id, evidence))],
|
|
27
|
+
["/api/memory/proposals", () => useStore(root, store => store.proposals())],
|
|
28
|
+
["/api/memory/proposal-decision", ({ id, decision, evidence }) =>
|
|
29
|
+
useStore(root, store => store.decideProposal(id, decision, evidence))],
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function useStore(root, action) {
|
|
34
|
+
const store = await openMemoryStore(root);
|
|
35
|
+
try { return await action(store); }
|
|
36
|
+
finally { store.close(); }
|
|
37
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
export function mountMemoryPanel(api) {
|
|
2
|
+
const byId = id => document.getElementById(id);
|
|
3
|
+
const panel = byId("memory-panel");
|
|
4
|
+
const lists = byId("memory-list");
|
|
5
|
+
const detail = byId("memory-detail");
|
|
6
|
+
const status = byId("memory-status");
|
|
7
|
+
const query = byId("memory-query");
|
|
8
|
+
let busy = false;
|
|
9
|
+
|
|
10
|
+
function element(tag, text) {
|
|
11
|
+
const node = document.createElement(tag);
|
|
12
|
+
node.textContent = text;
|
|
13
|
+
return node;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function action(text, callback) {
|
|
17
|
+
const button = element("button", text);
|
|
18
|
+
button.type = "button";
|
|
19
|
+
button.addEventListener("click", event => run(button, () => callback(event)));
|
|
20
|
+
return button;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function run(button, callback) {
|
|
24
|
+
if (busy) return;
|
|
25
|
+
busy = true;
|
|
26
|
+
if (button) button.disabled = true;
|
|
27
|
+
status.textContent = "Working…";
|
|
28
|
+
try { status.textContent = await callback() || ""; }
|
|
29
|
+
catch (error) { status.textContent = error.message; }
|
|
30
|
+
finally { busy = false; if (button) button.disabled = false; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function reload() {
|
|
34
|
+
const { records, stats } = await api("memory/list", { query: query.value });
|
|
35
|
+
byId("memory-summary").textContent = stats.candidate + " candidates · " + stats.verified + " verified · " + stats.archived + " archived";
|
|
36
|
+
await loadProposals();
|
|
37
|
+
lists.replaceChildren();
|
|
38
|
+
detail.replaceChildren();
|
|
39
|
+
if (!records.length) lists.append(element("p", query.value.trim() ? "No matching memories." : "No memories yet. Record a lesson to get started."));
|
|
40
|
+
for (const record of records) {
|
|
41
|
+
const item = document.createElement("article");
|
|
42
|
+
item.className = "node";
|
|
43
|
+
item.append(element("strong", record.title), element("p", record.type + " · " + record.status),
|
|
44
|
+
action("View memory", () => show(record)));
|
|
45
|
+
lists.append(item);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function evidenceForm(fields, label, callback) {
|
|
50
|
+
const form = document.createElement("form");
|
|
51
|
+
for (const [name, caption, options] of fields) {
|
|
52
|
+
const field = element("label", caption);
|
|
53
|
+
const input = document.createElement(options ? "select" : "input");
|
|
54
|
+
input.name = name;
|
|
55
|
+
input.required = true;
|
|
56
|
+
for (const option of options ?? []) input.append(element("option", option));
|
|
57
|
+
field.append(input);
|
|
58
|
+
form.append(field);
|
|
59
|
+
}
|
|
60
|
+
const agreement = element("label", "I reviewed the evidence and confirmed it passed");
|
|
61
|
+
const checkbox = document.createElement("input");
|
|
62
|
+
checkbox.type = "checkbox";
|
|
63
|
+
checkbox.required = true;
|
|
64
|
+
agreement.prepend(checkbox);
|
|
65
|
+
const submit = element("button", label);
|
|
66
|
+
form.append(agreement, submit);
|
|
67
|
+
form.onsubmit = event => {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
const evidence = Object.fromEntries(new FormData(form));
|
|
70
|
+
return run(submit, () => callback({ ...evidence, result: "passed", reviewed: true }));
|
|
71
|
+
};
|
|
72
|
+
return form;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function loadProposals() {
|
|
76
|
+
const section = byId("memory-proposals");
|
|
77
|
+
const proposals = await api("memory/proposals", {});
|
|
78
|
+
section.replaceChildren();
|
|
79
|
+
if (!proposals.length) section.append(element("p", "No skill proposals in this project."));
|
|
80
|
+
for (const proposal of proposals) {
|
|
81
|
+
const item = document.createElement("details");
|
|
82
|
+
item.className = "node";
|
|
83
|
+
item.append(element("summary", proposal.title + " · " + proposal.status),
|
|
84
|
+
element("pre", proposal.markdown),
|
|
85
|
+
element("p", "Source evidence: " + proposal.sources.map(source => source.evidenceId).join(", ")));
|
|
86
|
+
const decide = async (decision, evidence) => {
|
|
87
|
+
await api("memory/proposal-decision", { id: proposal.id, decision, evidence });
|
|
88
|
+
await loadProposals();
|
|
89
|
+
return "Proposal " + decision + ".";
|
|
90
|
+
};
|
|
91
|
+
if (proposal.status === "pending") {
|
|
92
|
+
item.append(evidenceForm([["evidenceId", "Independent regression evidence ID"]], "Approve proposal",
|
|
93
|
+
evidence => decide("approved", { ...evidence, context: proposal.context })),
|
|
94
|
+
action("Reject proposal", () => decide("rejected")));
|
|
95
|
+
}
|
|
96
|
+
if (proposal.status === "approved") item.append(action("Withdraw approval", () => decide("withdrawn")));
|
|
97
|
+
section.append(item);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function show(record) {
|
|
102
|
+
detail.replaceChildren(element("h3", record.title), element("pre", record.learning),
|
|
103
|
+
element("p", "Evidence: " + (record.evidence.join(", ") || "None")), element("p", "Record ID: " + record.id));
|
|
104
|
+
if (record.status !== "archived") detail.append(action("Archive", async () => {
|
|
105
|
+
await api("memory/archive", { id: record.id });
|
|
106
|
+
await reload();
|
|
107
|
+
return "Archived memory.";
|
|
108
|
+
}));
|
|
109
|
+
if (record.status === "candidate") {
|
|
110
|
+
const review = document.createElement("details");
|
|
111
|
+
review.append(element("summary", "Review verification evidence"), evidenceForm([
|
|
112
|
+
["adapter", "Evidence type", ["coding", "practice"]], ["context", "Review context"],
|
|
113
|
+
["evidenceId", "Evidence ID"], ["description", "Test or exercise name"],
|
|
114
|
+
], "Verify memory", async ({ description, ...evidence }) => {
|
|
115
|
+
const field = evidence.adapter === "coding" ? "test" : "exercise";
|
|
116
|
+
const verified = await api("memory/verify", { id: record.id, evidence: { ...evidence, [field]: description } });
|
|
117
|
+
await reload();
|
|
118
|
+
show(verified);
|
|
119
|
+
return "Verified memory.";
|
|
120
|
+
}));
|
|
121
|
+
detail.append(review);
|
|
122
|
+
}
|
|
123
|
+
if (record.status !== "verified") return;
|
|
124
|
+
detail.append(action("Preview Cloud upload", async () => {
|
|
125
|
+
const preview = await api("memory/preview", { id: record.id });
|
|
126
|
+
const review = document.createElement("section");
|
|
127
|
+
review.className = "node";
|
|
128
|
+
review.append(element("h3", preview.destination), element("pre", JSON.stringify(preview.memory, null, 2)));
|
|
129
|
+
const push = action("Push this memory to Cloud", async () => {
|
|
130
|
+
await api("memory/push", { id: record.id, fingerprint: preview.fingerprint });
|
|
131
|
+
review.remove();
|
|
132
|
+
return "Pushed memory to Cloud.";
|
|
133
|
+
});
|
|
134
|
+
review.append(push, action("Cancel upload", () => review.remove()));
|
|
135
|
+
detail.querySelector("[data-preview]")?.remove();
|
|
136
|
+
review.dataset.preview = "";
|
|
137
|
+
detail.append(review);
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
byId("open-memory").onclick = () => {
|
|
142
|
+
panel.showModal();
|
|
143
|
+
return run(null, reload);
|
|
144
|
+
};
|
|
145
|
+
byId("close-memory").onclick = () => panel.close();
|
|
146
|
+
byId("memory-search").onsubmit = event => {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
return run(event.submitter, reload);
|
|
149
|
+
};
|
|
150
|
+
byId("memory-create").onsubmit = event => {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
const form = event.currentTarget;
|
|
153
|
+
return run(event.submitter, async () => {
|
|
154
|
+
await api("memory/record", Object.fromEntries(new FormData(form)));
|
|
155
|
+
form.reset();
|
|
156
|
+
query.value = "";
|
|
157
|
+
await reload();
|
|
158
|
+
return "Recorded a candidate.";
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
function compareCopies(id, copies) {
|
|
162
|
+
detail.replaceChildren(element("h3", "Both copies changed"),
|
|
163
|
+
element("h4", "Project copy"),
|
|
164
|
+
element("pre", copies.localDeleted ? "Deleted locally" : JSON.stringify(copies.local, null, 2)),
|
|
165
|
+
element("h4", "Cloud copy"),
|
|
166
|
+
element("pre", copies.cloudDeleted ? "Deleted in Cloud" : JSON.stringify(copies.cloud, null, 2)));
|
|
167
|
+
if (copies.localDeleted || copies.cloudDeleted) {
|
|
168
|
+
detail.append(element("p", "Automatic replacement is unavailable when one copy was deleted."));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const resolve = async choice => {
|
|
172
|
+
const result = await api("memory/resolve", { id, choice, fingerprint: copies.fingerprint });
|
|
173
|
+
await reload();
|
|
174
|
+
return result?.keptLocal
|
|
175
|
+
? "Kept the project copy. Preview a fresh upload to update Cloud."
|
|
176
|
+
: "Saved the Cloud copy as a candidate for local review.";
|
|
177
|
+
};
|
|
178
|
+
detail.append(action("Keep project copy", () => resolve("local")),
|
|
179
|
+
action("Replace project copy with Cloud copy", () => resolve("cloud")));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
byId("memory-pull").onsubmit = event => {
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
const form = event.currentTarget;
|
|
185
|
+
return run(event.submitter, async () => {
|
|
186
|
+
const id = new FormData(form).get("id").trim();
|
|
187
|
+
let result;
|
|
188
|
+
try { result = await api("memory/pull", { id }); }
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error.message !== "Both copies changed. Review before syncing.") throw error;
|
|
191
|
+
const copies = await api("memory/compare", { id });
|
|
192
|
+
if (!copies) return "The copies changed during comparison. Try pulling again.";
|
|
193
|
+
compareCopies(id, copies);
|
|
194
|
+
return "Review both copies before choosing which to keep in this project.";
|
|
195
|
+
}
|
|
196
|
+
await reload();
|
|
197
|
+
return result.deleted ? "Applied Cloud deletion." : result.updated ? "Pulled a candidate for local review." : "Already up to date.";
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
}
|