agent-lyra 0.6.4 → 0.7.0
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 +42 -1
- package/bin/agent-lyra.js +3 -1
- package/package.json +1 -1
- package/src/app-builder/init.js +21 -1
- package/src/app-builder/preview.js +9 -0
- package/src/coding/export.js +10 -7
- package/src/coding/setup.js +4 -4
- package/src/framework/agent.js +173 -0
- package/src/framework/run.py +111 -0
- package/src/init.js +4 -9
- package/src/intelligence/graphsnip-provider.d.ts +5 -0
- package/src/intelligence/graphsnip-provider.js +57 -0
- package/src/memory/LICENSE +21 -0
- package/src/memory/README.md +5 -0
- package/src/memory/UPSTREAM.json +14 -0
- package/src/memory/bridge-cli.js +16 -0
- package/src/memory/bridge.js +18 -0
- package/src/memory/cloud-sync-actions.js +61 -0
- package/src/memory/contract.json +19 -2
- package/src/memory/index.js +3 -255
- package/src/memory/local-store.js +209 -0
- package/src/memory/package.json +33 -0
- package/src/memory/proposals.js +6 -0
- package/src/memory/standalone.d.ts +50 -0
- package/src/memory/standalone.js +1 -0
- package/src/resource-files.js +18 -0
- package/src/runtime/run-agent.js +16 -6
- package/src/studio/browser.js +19 -5
- package/src/studio/export.js +6 -1
- package/src/studio/project.js +37 -13
- package/src/studio/pull-agent.js +3 -3
- package/src/studio/server.js +8 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type MemoryType = "episodic" | "semantic" | "procedural" | "corrective";
|
|
2
|
+
export type MemoryStatus = "candidate" | "verified" | "archived";
|
|
3
|
+
export interface MemoryInput { type: MemoryType; title: string; learning: string; evidence?: string[] }
|
|
4
|
+
export type MemoryAdapter = "coding" | "practice";
|
|
5
|
+
export type VerificationReceipt = { evidenceId: string; context: string } & (
|
|
6
|
+
{ adapter: "coding"; test: string } | { adapter: "practice"; exercise: string }
|
|
7
|
+
);
|
|
8
|
+
export interface MemoryRecord extends MemoryInput {
|
|
9
|
+
id: string;
|
|
10
|
+
evidence: string[];
|
|
11
|
+
scope: "project";
|
|
12
|
+
status: MemoryStatus;
|
|
13
|
+
revision: number;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
verification?: VerificationReceipt;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillProposalSource { id: string; revision: number; evidenceId: string }
|
|
19
|
+
export interface SkillProposalReceipt { evidenceId: string; context: string; result: "passed"; reviewed: true }
|
|
20
|
+
export interface SkillProposal {
|
|
21
|
+
id: string;
|
|
22
|
+
context: string;
|
|
23
|
+
title: string;
|
|
24
|
+
markdown: string;
|
|
25
|
+
sources: SkillProposalSource[];
|
|
26
|
+
status: "pending" | "approved" | "rejected" | "withdrawn";
|
|
27
|
+
createdAt: string;
|
|
28
|
+
decidedAt: string | null;
|
|
29
|
+
receipt: SkillProposalReceipt | null;
|
|
30
|
+
}
|
|
31
|
+
export interface MemoryStore {
|
|
32
|
+
readonly file: string;
|
|
33
|
+
consolidate(context: string): Array<{ title: string; learning: string; sources: SkillProposalSource[] }>;
|
|
34
|
+
propose(context: string, memoryId: string): SkillProposal;
|
|
35
|
+
proposal(id: string): SkillProposal | null;
|
|
36
|
+
proposals(): SkillProposal[];
|
|
37
|
+
approvedSkills(context: string): SkillProposal[];
|
|
38
|
+
decideProposal(id: string, decision: "approved" | "rejected" | "withdrawn", evidence?: SkillProposalReceipt): SkillProposal;
|
|
39
|
+
close(): void;
|
|
40
|
+
get(id: string): MemoryRecord | null;
|
|
41
|
+
list(limit?: number): MemoryRecord[];
|
|
42
|
+
record(value: MemoryInput): MemoryRecord;
|
|
43
|
+
search(query: string, limit?: number): MemoryRecord[];
|
|
44
|
+
stats(): { schemaVersion: number; search: "fts5" | "keyword" } & Record<MemoryStatus, number>;
|
|
45
|
+
verify(id: string, evidence: VerificationReceipt & { result: "passed"; reviewed: true }): MemoryRecord;
|
|
46
|
+
retrieve(query: string, context: string, adapter?: MemoryAdapter): MemoryRecord[];
|
|
47
|
+
archive(id: string): MemoryRecord | null;
|
|
48
|
+
forget(id: string): boolean;
|
|
49
|
+
}
|
|
50
|
+
export function openLocalMemoryStore(root?: string, options?: { forceKeyword?: boolean; namespace?: string }): Promise<MemoryStore>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { openLocalMemoryStore } from "./local-store.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { lstat, readdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export async function resourceFiles(directory, extension, prefix = "") {
|
|
5
|
+
const stat = await lstat(directory).catch(error => {
|
|
6
|
+
if (error.code === "ENOENT") return null;
|
|
7
|
+
throw error;
|
|
8
|
+
});
|
|
9
|
+
if (!stat?.isDirectory()) return [];
|
|
10
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
11
|
+
const result = [];
|
|
12
|
+
for (const entry of entries.sort((a,b) => a.name.localeCompare(b.name))) {
|
|
13
|
+
const name = join(prefix, entry.name);
|
|
14
|
+
if (entry.isDirectory()) result.push(...await resourceFiles(join(directory, entry.name), extension, name));
|
|
15
|
+
else if (entry.isFile() && entry.name.endsWith(extension)) result.push(name);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
package/src/runtime/run-agent.js
CHANGED
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
|
|
3
|
+
const frameworkFailures = {
|
|
4
|
+
FRAMEWORK_TIMEOUT: ["timeout", "Framework run timed out."],
|
|
5
|
+
FRAMEWORK_DEPENDENCY: ["missing_dependency", "Install the framework in the selected Python environment."],
|
|
6
|
+
FRAMEWORK_OUTPUT: ["invalid_output", "Framework agent returned an invalid output."],
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* @param {{
|
|
5
11
|
* agentId: string,
|
|
6
12
|
* request: import("./contracts.js").ModelRequest,
|
|
7
13
|
* provider: import("./contracts.js").ModelProvider,
|
|
8
14
|
* store: import("./contracts.js").RunStore,
|
|
15
|
+
* traceId?: string, framework?: string, revision?: string,
|
|
9
16
|
* onStarted?: (runId: string) => void,
|
|
10
17
|
* }} options
|
|
11
18
|
*/
|
|
12
|
-
export async function runAgent({ agentId, request, provider, store, onStarted }) {
|
|
19
|
+
export async function runAgent({ agentId, request, provider, store, onStarted, traceId, framework, revision }) {
|
|
13
20
|
const runId = randomUUID();
|
|
21
|
+
const started = Date.now();
|
|
14
22
|
/** @param {number} seq */
|
|
15
|
-
const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString() });
|
|
23
|
+
const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString(), ...(traceId ? { schemaVersion: 1, trace_id: traceId } : {}) });
|
|
16
24
|
await store.append({
|
|
17
25
|
...envelope(0),
|
|
18
26
|
type: "run.started",
|
|
19
|
-
data: { agentId, model: request.model },
|
|
27
|
+
data: { agentId, model: request.model, ...(framework ? { framework, revision, execution: "local" } : {}) },
|
|
20
28
|
});
|
|
21
29
|
onStarted?.(runId);
|
|
22
30
|
|
|
@@ -24,11 +32,13 @@ export async function runAgent({ agentId, request, provider, store, onStarted })
|
|
|
24
32
|
let result;
|
|
25
33
|
try {
|
|
26
34
|
result = await provider.complete(request);
|
|
27
|
-
} catch {
|
|
35
|
+
} catch (error) {
|
|
36
|
+
const [reason, message] = Object.hasOwn(frameworkFailures, error?.code)
|
|
37
|
+
? frameworkFailures[error.code] : ["execution_error", "Framework execution failed."];
|
|
28
38
|
const failed = /** @type {const} */ ({
|
|
29
39
|
...envelope(1),
|
|
30
40
|
type: "run.failed",
|
|
31
|
-
data: { message: "Model request failed." },
|
|
41
|
+
data: { message: framework ? message : "Model request failed.", ...(framework ? { durationMs: Date.now() - started, reason } : {}) },
|
|
32
42
|
});
|
|
33
43
|
await store.append(failed);
|
|
34
44
|
return failed;
|
|
@@ -38,6 +48,6 @@ export async function runAgent({ agentId, request, provider, store, onStarted })
|
|
|
38
48
|
type: "run.completed",
|
|
39
49
|
data: { result },
|
|
40
50
|
});
|
|
41
|
-
await store.append(completed);
|
|
51
|
+
await store.append(framework ? { ...completed, data: { durationMs: Date.now() - started } } : completed);
|
|
42
52
|
return completed;
|
|
43
53
|
}
|
package/src/studio/browser.js
CHANGED
|
@@ -15,7 +15,7 @@ function dom(tag, props, ...children) {
|
|
|
15
15
|
return node;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent" };
|
|
18
|
+
const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
|
|
19
19
|
const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
|
|
20
20
|
let project = { layout: [], agents: [], workflows: [], teams: [], skills: [], models: [] };
|
|
21
21
|
let selected, pending;
|
|
@@ -184,6 +184,10 @@ function renderCatalog() {
|
|
|
184
184
|
const section = $("#" + id);
|
|
185
185
|
section.replaceChildren();
|
|
186
186
|
if (!rows.length) section.append(element("p", "None in this project."));
|
|
187
|
+
if (id === "agents" && project.frameworkCandidates?.length) {
|
|
188
|
+
section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
|
|
189
|
+
". Run agent-lyra agent discover, then register the entry you want."));
|
|
190
|
+
}
|
|
187
191
|
for (const row of rows) {
|
|
188
192
|
if (id === "agents") {
|
|
189
193
|
const push = row.source === "local" && project.mode !== "standalone"
|
|
@@ -205,8 +209,17 @@ function renderCatalog() {
|
|
|
205
209
|
} catch (error) { announce(error.message); }
|
|
206
210
|
finally { pull.disabled = false; }
|
|
207
211
|
});
|
|
208
|
-
const
|
|
209
|
-
|
|
212
|
+
const sync = row.source === "framework" && project.mode !== "standalone" && button("Sync registration", async () => {
|
|
213
|
+
try {
|
|
214
|
+
const id = row.id.slice("framework:".length);
|
|
215
|
+
const preview = await api("framework-preview", { id });
|
|
216
|
+
if (!window.confirm("Sync only this private registration?\n" + JSON.stringify(preview.payload, null, 2))) return;
|
|
217
|
+
await api("framework-sync", { id, fingerprint: preview.fingerprint });
|
|
218
|
+
announce("Registration synced. Open Cloud → Agents to view it.");
|
|
219
|
+
} catch (error) { announce(error.message); }
|
|
220
|
+
});
|
|
221
|
+
const actions = push ? dom("div", { className: "actions" }, push, pull) : sync;
|
|
222
|
+
section.append(renderAgentCard(dom, { name: row.name, source: row.framework ? row.framework + " · Local" : agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
|
|
210
223
|
continue;
|
|
211
224
|
}
|
|
212
225
|
const card = element("article");
|
|
@@ -263,7 +276,8 @@ $("#runner").onsubmit = async event => {
|
|
|
263
276
|
$("#run-status").textContent = "Running workflow…";
|
|
264
277
|
try {
|
|
265
278
|
const { answers } = await api("run", { targets: pending.targets, buttonId: pending.buttonId, input: $("#prompt").value, model: $("#model").value });
|
|
266
|
-
const text = answers.map(({ agent, output }) => agent + "\n" + output
|
|
279
|
+
const text = answers.map(({ agent, output, run }) => agent + "\n" + output +
|
|
280
|
+
(run ? "\nRun " + run.runId + " · Trace " + run.traceId : "")).join("\n\n");
|
|
267
281
|
$("#run-result").textContent = text;
|
|
268
282
|
if (pending.outputId) outputs.set(pending.outputId, answers.at(-1).output);
|
|
269
283
|
renderCanvas();
|
|
@@ -280,7 +294,7 @@ $("#drawer").oncancel = event => { if ($("#run").disabled) event.preventDefault(
|
|
|
280
294
|
async function load({ catalogOnly = false } = {}) {
|
|
281
295
|
const next = await api("project");
|
|
282
296
|
if (catalogOnly) {
|
|
283
|
-
for (const key of ["agents", "workflows", "teams", "skills", "models", "mode"]) project[key] = next[key];
|
|
297
|
+
for (const key of ["agents", "workflows", "teams", "skills", "models", "mode", "frameworkCandidates"]) project[key] = next[key];
|
|
284
298
|
} else {
|
|
285
299
|
project = next;
|
|
286
300
|
dirty = false;
|
package/src/studio/export.js
CHANGED
|
@@ -4,9 +4,11 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { readCatalog, resolveSequence, validateLayout } from "./project.js";
|
|
5
5
|
|
|
6
6
|
const runtime = [
|
|
7
|
+
"resource-files.js",
|
|
7
8
|
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html",
|
|
8
9
|
"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
|
+
"memory/index.js", "memory/local-store.js", "memory/cloud-sync-actions.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
|
|
11
|
+
"framework/agent.js", "framework/run.py",
|
|
10
12
|
"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
13
|
];
|
|
12
14
|
|
|
@@ -40,6 +42,9 @@ export async function exportStudioApp(app, root, directory) {
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
}
|
|
45
|
+
if ([...agents.values()].some(agent => agent.source === "framework")) {
|
|
46
|
+
throw new Error("Registered framework agents run from their source project. Use Studio or app preview there.");
|
|
47
|
+
}
|
|
43
48
|
const name = typeof app.application?.name === "string" ? app.application.name : "Lyra app";
|
|
44
49
|
const files = await Promise.all(runtime.map(async file => [
|
|
45
50
|
"runtime/" + file, await readFile(new URL("../" + file, import.meta.url)),
|
package/src/studio/project.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { lstat, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
3
|
+
import { join, dirname, basename } from "node:path";
|
|
4
|
+
import { resourceFiles } from "../resource-files.js";
|
|
5
|
+
import { frameworkDescriptor, runFrameworkAgent } from "../framework/agent.js";
|
|
4
6
|
import { createSavedAgentClient } from "../app-builder/saved-app.js";
|
|
5
7
|
import { createOpenAIProvider, openStore } from "../runtime/local-cli.js";
|
|
6
8
|
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
@@ -46,14 +48,14 @@ export function readLocalAgent(source) {
|
|
|
46
48
|
export async function readCatalog(root) {
|
|
47
49
|
const directory = join(root, ".lyra", "agents");
|
|
48
50
|
const agents = new Map();
|
|
49
|
-
for (const name of await
|
|
51
|
+
for (const name of await resourceFiles(directory, ".md")) {
|
|
50
52
|
const parsed = readLocalAgent(await readFile(join(directory, name), "utf8"));
|
|
51
53
|
if (parsed && !agents.has(parsed.id)) agents.set(parsed.id, parsed);
|
|
52
54
|
}
|
|
53
55
|
async function records(kind) {
|
|
54
56
|
const folder = join(root, ".lyra", kind);
|
|
55
57
|
const rows = [];
|
|
56
|
-
for (const name of await
|
|
58
|
+
for (const name of await resourceFiles(folder, ".json")) {
|
|
57
59
|
try {
|
|
58
60
|
const item = JSON.parse(await readFile(join(folder, name), "utf8"));
|
|
59
61
|
if (safeId.test(item.id) && typeof item.name === "string") rows.push(item);
|
|
@@ -63,7 +65,7 @@ export async function readCatalog(root) {
|
|
|
63
65
|
}
|
|
64
66
|
return rows;
|
|
65
67
|
}
|
|
66
|
-
for (const name of await
|
|
68
|
+
for (const name of await resourceFiles(directory, ".json")) {
|
|
67
69
|
let item;
|
|
68
70
|
try {
|
|
69
71
|
item = JSON.parse((await readFile(join(directory, name), "utf8")).replace(/^\uFEFF/, ""));
|
|
@@ -71,6 +73,12 @@ export async function readCatalog(root) {
|
|
|
71
73
|
if (error instanceof SyntaxError) continue;
|
|
72
74
|
throw error;
|
|
73
75
|
}
|
|
76
|
+
const external = frameworkDescriptor(item);
|
|
77
|
+
if (external && name === join("coding", external.id + ".json")) {
|
|
78
|
+
const id = "framework:" + external.id;
|
|
79
|
+
agents.set(id, { ...external, id, source: "framework" });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
74
82
|
const descriptor = pythonDescriptor(item);
|
|
75
83
|
if (!descriptor || typeof item.id !== "string" || !safeId.test(item.id) ||
|
|
76
84
|
typeof item.name !== "string" || !item.name.trim()) continue;
|
|
@@ -79,13 +87,11 @@ export async function readCatalog(root) {
|
|
|
79
87
|
}
|
|
80
88
|
const skills = await records("skills");
|
|
81
89
|
const skillRoot = join(root, ".lyra", "skills");
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!folder.isDirectory() || !safeId.test(folder.name)) continue;
|
|
88
|
-
const metadata = join(skillRoot, folder.name, "SKILL.md");
|
|
90
|
+
for (const relative of await resourceFiles(skillRoot, "SKILL.md")) {
|
|
91
|
+
if (basename(relative) !== "SKILL.md") continue;
|
|
92
|
+
const folder = { name: basename(dirname(relative)) };
|
|
93
|
+
if (!safeId.test(folder.name)) continue;
|
|
94
|
+
const metadata = join(skillRoot, relative);
|
|
89
95
|
const stat = await lstat(metadata).catch(error => {
|
|
90
96
|
if (error.code === "ENOENT") return null;
|
|
91
97
|
throw error;
|
|
@@ -184,7 +190,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
184
190
|
if (!exported) requireCloudMode(await readMode(root));
|
|
185
191
|
cloud = createSavedAgentClient(exported ? undefined : { key: await readSdkKey(root) });
|
|
186
192
|
}
|
|
187
|
-
const store = local ? await openStore(root) : null;
|
|
193
|
+
const store = local || sequence.some(step => step.agentId.startsWith("framework:")) ? await openStore(root) : null;
|
|
188
194
|
const answers = [];
|
|
189
195
|
const named = new Map();
|
|
190
196
|
try {
|
|
@@ -193,10 +199,28 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
193
199
|
const previous = step.input ? named.get(step.input) : answers.at(-1)?.output;
|
|
194
200
|
const text = [step.task, input.trim(), previous && "Previous result: " + previous].filter(Boolean).join("\n\n").slice(0, 12_000);
|
|
195
201
|
let output;
|
|
202
|
+
let run;
|
|
196
203
|
if (agent.source === "cloud") {
|
|
197
204
|
output = await cloud.invoke(agent.id.slice("cloud:".length), text);
|
|
198
205
|
} else if (agent.source === "python") {
|
|
199
206
|
output = await runPythonAgent(root, agent, text, exported);
|
|
207
|
+
} else if (agent.source === "framework") {
|
|
208
|
+
let payload = text;
|
|
209
|
+
if (agent.input === "json") {
|
|
210
|
+
try { payload = JSON.parse(previous ?? input); }
|
|
211
|
+
catch { throw new Error("Provide valid JSON for " + agent.name + "."); }
|
|
212
|
+
}
|
|
213
|
+
const traceId = randomUUID();
|
|
214
|
+
const revision = createHash("sha256").update(JSON.stringify(agent)).digest("hex");
|
|
215
|
+
const event = await runAgent({
|
|
216
|
+
agentId: agent.id, store, traceId, framework: agent.framework, revision,
|
|
217
|
+
request: { model: "framework-managed", messages: [] },
|
|
218
|
+
provider: { complete: async () => ({ text: await runFrameworkAgent(root, agent, payload, traceId) }) },
|
|
219
|
+
});
|
|
220
|
+
if (event.type !== "run.completed") throw new Error(event.data.message + " Run " + event.run_id + " · Trace " + traceId + ".");
|
|
221
|
+
|
|
222
|
+
output = event.data.result.text;
|
|
223
|
+
run = { runId: event.run_id, traceId, framework: agent.framework };
|
|
200
224
|
} else {
|
|
201
225
|
const request = { model, messages: [{ role: "system", content: agent.prompt }, { role: "user", content: text }] };
|
|
202
226
|
const event = await runAgent({
|
|
@@ -207,7 +231,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
207
231
|
output = event.data.result.text;
|
|
208
232
|
}
|
|
209
233
|
if (step.output) named.set(step.output, output);
|
|
210
|
-
answers.push({ agent: agent.name, output });
|
|
234
|
+
answers.push({ agent: agent.name, output, ...(run ? { run } : {}) });
|
|
211
235
|
}
|
|
212
236
|
return { answers };
|
|
213
237
|
} finally {
|
package/src/studio/pull-agent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { lstat, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { resourceFiles } from "../resource-files.js";
|
|
4
5
|
import { readLocalAgent } from "./project.js";
|
|
5
6
|
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
6
7
|
|
|
@@ -22,9 +23,8 @@ export async function pullAgentEdits(root, id, { request = fetch, key } = {}) {
|
|
|
22
23
|
if (!digest.test(link?.linkId ?? "") || !digest.test(link?.revision ?? "")) throw new Error("Invalid Cloud link.");
|
|
23
24
|
|
|
24
25
|
const matches = [];
|
|
25
|
-
for (const
|
|
26
|
-
|
|
27
|
-
const path = join(folder, entry.name);
|
|
26
|
+
for (const name of await resourceFiles(folder, ".md")) {
|
|
27
|
+
const path = join(folder, name);
|
|
28
28
|
const content = await readFile(path, "utf8");
|
|
29
29
|
const parsed = readLocalAgent(content);
|
|
30
30
|
if (parsed?.id === id) matches.push({ path, content, parsed });
|
package/src/studio/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
|
|
1
2
|
import { memoryActions } from "./memory-actions.js";
|
|
2
3
|
import { createServer } from "node:http";
|
|
3
4
|
import { readFile } from "node:fs/promises";
|
|
@@ -18,6 +19,11 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
18
19
|
|
|
19
20
|
const updates = new Map([
|
|
20
21
|
...(appCatalog ? [] : memoryActions(root)),
|
|
22
|
+
["/api/framework-preview", ({ id }) => syncFrameworkAgent(root, id)],
|
|
23
|
+
["/api/framework-sync", ({ id, fingerprint }) => {
|
|
24
|
+
if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
|
|
25
|
+
return syncFrameworkAgent(root, id, fingerprint);
|
|
26
|
+
}],
|
|
21
27
|
["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
|
|
22
28
|
["/api/pull", () => pull(root)],
|
|
23
29
|
["/api/push", ({ id }) => pushStudioAgent(root, id)],
|
|
@@ -53,7 +59,8 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
53
59
|
...await readLayout(root),
|
|
54
60
|
exported: Boolean(appCatalog),
|
|
55
61
|
mode: appCatalog ? undefined : await readMode(root),
|
|
56
|
-
agents: [...catalog.agents.values()].map(({ id, name, source }) => ({ id, name, source })),
|
|
62
|
+
agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
|
|
63
|
+
frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
|
|
57
64
|
workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
|
|
58
65
|
skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
|
|
59
66
|
teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
|