agent-lyra 0.11.2 → 0.12.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 +45 -35
- package/bin/agent-lyra.js +1 -1
- package/package.json +1 -1
- package/src/app-builder/init.js +3 -3
- package/src/framework/agent.js +19 -8
- package/src/framework/mda.js +5 -2
- package/src/framework/run.py +83 -11
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/init.js +1 -1
- package/src/intelligence/lifecycle.js +3 -2
- package/src/memory/LICENSE +1 -1
- package/src/memory/UPSTREAM.json +6 -3
- package/src/memory/external-engine.js +35 -0
- package/src/memory/index.js +19 -1
- package/src/memory/lifecycle.js +2 -1
- package/src/runtime/programmatic.d.ts +84 -0
- package/src/runtime/programmatic.js +155 -0
- package/src/runtime/run-agent.js +10 -2
- package/src/studio/browser.js +125 -19
- package/src/studio/export.js +7 -4
- package/src/studio/graphsnip-workbench.js +77 -0
- package/src/studio/history-panel.js +155 -0
- package/src/studio/ide-provider.js +65 -0
- package/src/studio/index.html +61 -9
- package/src/studio/intelligence.js +94 -0
- package/src/studio/local-provider.js +43 -0
- package/src/studio/memory-actions.js +28 -1
- package/src/studio/memory-panel.js +29 -5
- package/src/studio/mission-ui.css +52 -0
- package/src/studio/mission-ui.js +57 -0
- package/src/studio/programmatic-runner.mjs +21 -0
- package/src/studio/programmatic.js +58 -0
- package/src/studio/project.js +102 -24
- package/src/studio/python-agent.py +28 -4
- package/src/studio/run-history.js +119 -0
- package/src/studio/server.js +77 -8
- package/src/studio/session.js +1 -1
- package/src/studio/studio.css +76 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ModelProvider } from "./contracts.js";
|
|
2
|
+
export type { ModelProvider } from "./contracts.js";
|
|
3
|
+
|
|
4
|
+
type ScalarSchema = { type: "string" | "number" | "integer" | "boolean" | "null" };
|
|
5
|
+
export type ValueSchema = ScalarSchema | {
|
|
6
|
+
type: "object";
|
|
7
|
+
properties: Record<string, ScalarSchema>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
additionalProperties?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface ExecutionContext {
|
|
13
|
+
runId?: string;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
provider?: ModelProvider;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface LearningSuggestion {
|
|
19
|
+
type: "corrective" | "episodic" | "semantic" | "procedural";
|
|
20
|
+
title: string;
|
|
21
|
+
learning: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AgentContext extends ExecutionContext {
|
|
25
|
+
suggestLearning(suggestion: LearningSuggestion): void;
|
|
26
|
+
runId: string;
|
|
27
|
+
tool(id: string, input: unknown): Promise<unknown>;
|
|
28
|
+
skill(id: string, input: unknown): Promise<unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Definition<I, O, C = ExecutionContext> {
|
|
32
|
+
id: string;
|
|
33
|
+
inputSchema?: ValueSchema;
|
|
34
|
+
outputSchema?: ValueSchema;
|
|
35
|
+
execute(input: I, context: C): O | Promise<O>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare class Executable<I, O> {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
constructor(definition: Definition<I, O>);
|
|
41
|
+
execute(input: I, context?: ExecutionContext): Promise<O>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class Tool<I = unknown, O = unknown> extends Executable<I, O> {}
|
|
45
|
+
export class Skill<I = unknown, O = unknown> extends Executable<I, O> {}
|
|
46
|
+
export class Guardrail<I = unknown> extends Executable<I, boolean> {}
|
|
47
|
+
export class Evaluator<I = unknown, O = unknown> extends Executable<I, O> {}
|
|
48
|
+
|
|
49
|
+
type Outcome<O> =
|
|
50
|
+
| { status: "completed"; output: O; evaluations: Array<{ id: string; result: unknown }> }
|
|
51
|
+
| { status: "blocked"; guardrailId: string }
|
|
52
|
+
| { status: "failed"; stage: "guardrail" | "execution" | "evaluation" }
|
|
53
|
+
| { status: "cancelled" };
|
|
54
|
+
|
|
55
|
+
export type AgentResult<O> = { runId: string; agentId: string } & Outcome<O>;
|
|
56
|
+
export interface AgentEvent {
|
|
57
|
+
type: "run.started" | `run.${Outcome<unknown>["status"]}`;
|
|
58
|
+
runId: string;
|
|
59
|
+
agentId: string;
|
|
60
|
+
timestamp: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class Agent<I = unknown, O = unknown> {
|
|
64
|
+
readonly id: string;
|
|
65
|
+
constructor(definition: Definition<I, O, AgentContext> & {
|
|
66
|
+
tools?: ReadonlyArray<Tool>;
|
|
67
|
+
skills?: ReadonlyArray<Skill>;
|
|
68
|
+
guardrails?: ReadonlyArray<Guardrail<I>>;
|
|
69
|
+
evaluators?: ReadonlyArray<Evaluator<O>>;
|
|
70
|
+
});
|
|
71
|
+
run(input: I, options?: {
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
provider?: ModelProvider;
|
|
74
|
+
onLearning?(suggestion: LearningSuggestion): void | Promise<void>;
|
|
75
|
+
onEvent?(event: AgentEvent): void | Promise<void>;
|
|
76
|
+
onActivity?(event: { type: `${"tool" | "skill" | "evaluation"}.${"started" | "completed" | "failed"}`; id: string }): void | Promise<void>;
|
|
77
|
+
}): Promise<AgentResult<O>>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class AgentRegistry {
|
|
81
|
+
register<I, O>(agent: Agent<I, O>): this;
|
|
82
|
+
get(id: string): Agent | undefined;
|
|
83
|
+
list(): Agent[];
|
|
84
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { assertValueSchema, matchesValueSchema } from "../app-builder/value-schema.js";
|
|
3
|
+
|
|
4
|
+
function assertMatch(value, schema, label) {
|
|
5
|
+
if (schema && !matchesValueSchema(value, schema)) {
|
|
6
|
+
throw new TypeError(label + " does not match its schema.");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class Executable {
|
|
11
|
+
#handler;
|
|
12
|
+
#input;
|
|
13
|
+
#output;
|
|
14
|
+
|
|
15
|
+
constructor({ id, execute, inputSchema, outputSchema }) {
|
|
16
|
+
if (typeof id !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,95}$/.test(id)) {
|
|
17
|
+
throw new TypeError("Use a stable executable ID.");
|
|
18
|
+
}
|
|
19
|
+
if (typeof execute !== "function") throw new TypeError("An execute function is required.");
|
|
20
|
+
if (inputSchema !== undefined) assertValueSchema(inputSchema, "Input schema");
|
|
21
|
+
if (outputSchema !== undefined) assertValueSchema(outputSchema, "Output schema");
|
|
22
|
+
Object.defineProperty(this, "id", { value: id, enumerable: true });
|
|
23
|
+
this.#handler = execute;
|
|
24
|
+
this.#input = inputSchema === undefined ? undefined : structuredClone(inputSchema);
|
|
25
|
+
this.#output = outputSchema === undefined ? undefined : structuredClone(outputSchema);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async execute(input, context = {}) {
|
|
29
|
+
context.signal?.throwIfAborted();
|
|
30
|
+
assertMatch(input, this.#input, "Input");
|
|
31
|
+
const output = await this.#handler(input, context);
|
|
32
|
+
context.signal?.throwIfAborted();
|
|
33
|
+
assertMatch(output, this.#output, "Output");
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Tool extends Executable {}
|
|
39
|
+
export class Skill extends Executable {}
|
|
40
|
+
export class Guardrail extends Executable {}
|
|
41
|
+
export class Evaluator extends Executable {}
|
|
42
|
+
|
|
43
|
+
function dependencies(items, Type) {
|
|
44
|
+
const entries = new Map();
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
if (!(item instanceof Type) || entries.has(item.id)) throw new TypeError("Use unique executable dependencies.");
|
|
47
|
+
entries.set(item.id, item);
|
|
48
|
+
}
|
|
49
|
+
return entries;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class Agent {
|
|
53
|
+
#definition;
|
|
54
|
+
#tools;
|
|
55
|
+
#skills;
|
|
56
|
+
#guardrails;
|
|
57
|
+
#evaluators;
|
|
58
|
+
|
|
59
|
+
constructor({ tools = [], skills = [], guardrails = [], evaluators = [], ...definition }) {
|
|
60
|
+
this.#definition = new Executable(definition);
|
|
61
|
+
this.#tools = dependencies(tools, Tool);
|
|
62
|
+
this.#skills = dependencies(skills, Skill);
|
|
63
|
+
this.#guardrails = dependencies(guardrails, Guardrail);
|
|
64
|
+
this.#evaluators = dependencies(evaluators, Evaluator);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get id() {
|
|
68
|
+
return this.#definition.id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async run(input, { signal, provider, onEvent, onActivity, onLearning } = {}) {
|
|
72
|
+
const runId = randomUUID();
|
|
73
|
+
const notify = async type => {
|
|
74
|
+
try {
|
|
75
|
+
await onEvent?.({ type, runId, agentId: this.id, timestamp: new Date().toISOString() });
|
|
76
|
+
} catch {
|
|
77
|
+
// An observer cannot alter executable results.
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const context = { runId, signal, provider };
|
|
81
|
+
const suggestions = [];
|
|
82
|
+
const invoke = async (entries, kind, id, value) => {
|
|
83
|
+
const target = entries.get(id);
|
|
84
|
+
if (!target) throw new Error("Unknown " + kind + " dependency: " + id);
|
|
85
|
+
const observe = async status => {
|
|
86
|
+
try { await onActivity?.({ type: kind + "." + status, id }); } catch {}
|
|
87
|
+
};
|
|
88
|
+
await observe("started");
|
|
89
|
+
try {
|
|
90
|
+
const result = await target.execute(value, context);
|
|
91
|
+
await observe("completed");
|
|
92
|
+
return result;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
await observe("failed");
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const settle = async result => {
|
|
99
|
+
await notify("run." + result.status);
|
|
100
|
+
return { runId, agentId: this.id, ...result };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
await notify("run.started");
|
|
104
|
+
let stage = "guardrail";
|
|
105
|
+
try {
|
|
106
|
+
signal?.throwIfAborted();
|
|
107
|
+
for (const [id, check] of this.#guardrails) {
|
|
108
|
+
if (await check.execute(input, context) !== true) return settle({ status: "blocked", guardrailId: id });
|
|
109
|
+
}
|
|
110
|
+
stage = "execution";
|
|
111
|
+
const output = await this.#definition.execute(input, {
|
|
112
|
+
...context,
|
|
113
|
+
suggestLearning: value => {
|
|
114
|
+
if (suggestions.length < 3 && typeof value?.type === "string" &&
|
|
115
|
+
typeof value.title === "string" && value.title.length <= 160 &&
|
|
116
|
+
typeof value.learning === "string" && value.learning.length <= 4000) {
|
|
117
|
+
suggestions.push({ type: value.type, title: value.title, learning: value.learning });
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
tool: (id, value) => invoke(this.#tools, "tool", id, value),
|
|
121
|
+
skill: (id, value) => invoke(this.#skills, "skill", id, value),
|
|
122
|
+
});
|
|
123
|
+
stage = "evaluation";
|
|
124
|
+
const evaluations = [];
|
|
125
|
+
for (const id of this.#evaluators.keys()) {
|
|
126
|
+
evaluations.push({ id, result: await invoke(this.#evaluators, "evaluation", id, output) });
|
|
127
|
+
}
|
|
128
|
+
for (const suggestion of suggestions) {
|
|
129
|
+
try { await onLearning?.(suggestion); } catch {}
|
|
130
|
+
}
|
|
131
|
+
return settle({ status: "completed", output, evaluations });
|
|
132
|
+
} catch {
|
|
133
|
+
return settle(signal?.aborted ? { status: "cancelled" } : { status: "failed", stage });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class AgentRegistry {
|
|
139
|
+
#agents = new Map();
|
|
140
|
+
|
|
141
|
+
register(agent) {
|
|
142
|
+
if (!(agent instanceof Agent)) throw new TypeError("Register an Agent instance.");
|
|
143
|
+
if (this.#agents.has(agent.id)) throw new Error("Agent is already registered: " + agent.id);
|
|
144
|
+
this.#agents.set(agent.id, agent);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get(id) {
|
|
149
|
+
return this.#agents.get(id);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
list() {
|
|
153
|
+
return [...this.#agents.values()];
|
|
154
|
+
}
|
|
155
|
+
}
|
package/src/runtime/run-agent.js
CHANGED
|
@@ -14,10 +14,11 @@ const frameworkFailures = {
|
|
|
14
14
|
* provider: import("./contracts.js").ModelProvider,
|
|
15
15
|
* store: import("./contracts.js").RunStore,
|
|
16
16
|
* traceId?: string, framework?: string, revision?: string,
|
|
17
|
+
* signal?: AbortSignal,
|
|
17
18
|
* onStarted?: (runId: string) => void,
|
|
18
19
|
* }} options
|
|
19
20
|
*/
|
|
20
|
-
export async function runAgent({ agentId, request, provider, store, onStarted, traceId, framework, revision }) {
|
|
21
|
+
export async function runAgent({ agentId, request, provider, store, onStarted, signal, traceId, framework, revision }) {
|
|
21
22
|
const runId = randomUUID();
|
|
22
23
|
const started = Date.now();
|
|
23
24
|
/** @param {number} seq */
|
|
@@ -32,8 +33,15 @@ export async function runAgent({ agentId, request, provider, store, onStarted, t
|
|
|
32
33
|
/** @type {import("./contracts.js").ModelResult} */
|
|
33
34
|
let result;
|
|
34
35
|
try {
|
|
35
|
-
|
|
36
|
+
signal?.throwIfAborted();
|
|
37
|
+
result = await provider.complete(request, { signal });
|
|
38
|
+
signal?.throwIfAborted();
|
|
36
39
|
} catch (error) {
|
|
40
|
+
if (signal?.aborted) {
|
|
41
|
+
const cancelled = /** @type {const} */ ({ ...envelope(1), type: "run.cancelled", data: {} });
|
|
42
|
+
await store.append(cancelled);
|
|
43
|
+
return cancelled;
|
|
44
|
+
}
|
|
37
45
|
const [reason, message] = Object.hasOwn(frameworkFailures, error?.code)
|
|
38
46
|
? frameworkFailures[error.code] : ["execution_error", "Framework execution failed."];
|
|
39
47
|
const failed = /** @type {const} */ ({
|
package/src/studio/browser.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { mountIntelligence } from "./intelligence.js";
|
|
1
2
|
import { mountWorkflowEditor } from "./workflow-editor.js";
|
|
3
|
+
import { mountHistoryPanel } from "./history-panel.js";
|
|
2
4
|
import { mountMemoryPanel } from "./memory-panel.js";
|
|
3
5
|
import { renderAgentCard, renderRunHeader } from "./agent-ui.js";
|
|
4
6
|
|
|
@@ -7,16 +9,16 @@ const element = (tag, text) => Object.assign(document.createElement(tag), text =
|
|
|
7
9
|
function dom(tag, props, ...children) {
|
|
8
10
|
const node = document.createElement(tag);
|
|
9
11
|
for (const [key, value] of Object.entries(props)) {
|
|
10
|
-
if (value == null) continue;
|
|
12
|
+
if (value == null || key === "key") continue;
|
|
11
13
|
if (key === "onClick") node.onclick = value;
|
|
12
|
-
else if (key
|
|
14
|
+
else if (key.startsWith("aria-") || key.startsWith("data-")) node.setAttribute(key, value);
|
|
13
15
|
else node[key] = value;
|
|
14
16
|
}
|
|
15
17
|
node.append(...children.filter(child => child != null && child !== false && child !== ""));
|
|
16
18
|
return node;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
|
|
21
|
+
const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", programmatic: "Executable Lyra agent", framework: "Registered framework agent" };
|
|
20
22
|
const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
|
|
21
23
|
const componentMarks = {
|
|
22
24
|
heading: "H", text: "≡", input: "▏", textarea: "▤",
|
|
@@ -46,18 +48,54 @@ async function api(path, data) {
|
|
|
46
48
|
return payload;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
mountMemoryPanel(api);
|
|
51
|
+
const openMemoryPanel = mountMemoryPanel(api);
|
|
52
|
+
const workbenchViews = {
|
|
53
|
+
mission: ["open-history", "history-panel"],
|
|
54
|
+
registry: ["show-registry", "library"],
|
|
55
|
+
layout: ["show-layout", "canvas-panel"],
|
|
56
|
+
workflow: ["show-workflow", "workflow-panel"],
|
|
57
|
+
cloud: ["show-cloud", "cloud-settings"],
|
|
58
|
+
graph: ["show-graph", "graph-panel"],
|
|
59
|
+
tokens: ["show-tokens", "token-panel"],
|
|
60
|
+
};
|
|
61
|
+
let view = "layout";
|
|
62
|
+
let layoutLibraryView = libraryView;
|
|
63
|
+
let layoutSearch = "";
|
|
64
|
+
|
|
65
|
+
function showView(next) {
|
|
66
|
+
const search = $("#library-search");
|
|
67
|
+
if (view === "layout" && next !== "layout") {
|
|
68
|
+
layoutLibraryView = libraryView;
|
|
69
|
+
layoutSearch = search.value;
|
|
70
|
+
}
|
|
71
|
+
if (next !== view && (next === "layout" || next === "registry")) {
|
|
72
|
+
libraryView = next === "registry" ? "agents" : layoutLibraryView;
|
|
73
|
+
search.value = next === "registry" ? "" : layoutSearch;
|
|
74
|
+
}
|
|
75
|
+
view = next;
|
|
76
|
+
if (next !== "mission" && location.hash.startsWith("#run=")) {
|
|
77
|
+
history.replaceState(history.state, "", location.pathname + location.search);
|
|
78
|
+
}
|
|
79
|
+
for (const [key, [control, panel]] of Object.entries(workbenchViews)) {
|
|
80
|
+
$("#" + control).setAttribute("aria-pressed", String(next === key));
|
|
81
|
+
$("#" + panel).hidden = next !== key;
|
|
82
|
+
}
|
|
83
|
+
$("#library").hidden = next !== "layout" && next !== "registry";
|
|
84
|
+
$("#library").classList.toggle("registry-view", next === "registry");
|
|
85
|
+
$("#library-title").textContent = next === "registry" ? "Agent Registry" : "Project library";
|
|
86
|
+
$("#library-tabs").hidden = next === "registry";
|
|
87
|
+
$("#refresh").hidden = next !== "registry";
|
|
88
|
+
$("#save").hidden = next !== "layout";
|
|
89
|
+
if (next !== "layout") closeInspector();
|
|
90
|
+
if (next === "registry" || next === "layout") renderCatalog();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
mountIntelligence(api, showView);
|
|
94
|
+
const syncHistoryLocation = mountHistoryPanel(api, () => showView("mission"), dom, openMemoryPanel);
|
|
50
95
|
const workflowEditor = mountWorkflowEditor({
|
|
51
96
|
api, project: () => project, reloadCatalog: () => load({ catalogOnly: true }),
|
|
52
97
|
run: id => openRun(["workflow:" + id]),
|
|
53
|
-
switchView: editing =>
|
|
54
|
-
$("#save").hidden = $("#canvas-panel").hidden = editing;
|
|
55
|
-
$("#library").hidden = editing;
|
|
56
|
-
if (editing) closeInspector();
|
|
57
|
-
$("#workflow-panel").hidden = !editing;
|
|
58
|
-
$("#show-layout").setAttribute("aria-pressed", String(!editing));
|
|
59
|
-
$("#show-workflow").setAttribute("aria-pressed", String(editing));
|
|
60
|
-
},
|
|
98
|
+
switchView: editing => showView(editing ? "workflow" : "layout"),
|
|
61
99
|
});
|
|
62
100
|
|
|
63
101
|
function announce(message) { $("#status").textContent = message; }
|
|
@@ -244,7 +282,7 @@ function renderCatalog() {
|
|
|
244
282
|
if (id === "agents" && !project.cloudConnected) {
|
|
245
283
|
const callout = dom("div", { className: "cloud-callout" },
|
|
246
284
|
element("p", "Connect to AgentLyra Cloud to pull, push, and sync agents."),
|
|
247
|
-
button("
|
|
285
|
+
button("Open Cloud Sync", () => showView("cloud")));
|
|
248
286
|
section.append(callout);
|
|
249
287
|
}
|
|
250
288
|
if (id === "skills" && rows.length) section.append(element("p",
|
|
@@ -415,15 +453,18 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
415
453
|
}
|
|
416
454
|
plan.replaceChildren(element("h2", "Execution steps"), list);
|
|
417
455
|
plan.hidden = false;
|
|
418
|
-
providerPicker.replaceChildren(...(setup.providers || []).map(id => new Option(id === "openai" ? "Local OpenAI API" : id === "cloud" ? "Lyra Cloud" : id + " CLI", id)));
|
|
456
|
+
providerPicker.replaceChildren(...(setup.providers || []).map(id => new Option(id === "openai" ? "Local OpenAI API" : id === "cloud" ? "Lyra Cloud" : id === "vscode" ? "VS Code model" : id === "local-model" ? "Local model server" : id + " CLI", id)));
|
|
419
457
|
providerPicker.value = setup.provider || "";
|
|
420
458
|
providerPicker.hidden = providerLabel.hidden = !setup.providers?.length;
|
|
421
459
|
const previousModel = picker.value;
|
|
422
|
-
|
|
460
|
+
modelLabel.textContent = setup.provider === "vscode" ? "Authorized VS Code model" : setup.provider === "local-model" ? "Local model" : "Local OpenAI model";
|
|
461
|
+
picker.replaceChildren(...setup.models.map(model => new Option(setup.ideModelName && setup.provider === "vscode"
|
|
462
|
+
? setup.ideModelName : model, model)));
|
|
423
463
|
if (setup.models.includes(previousModel)) picker.value = previousModel;
|
|
424
464
|
picker.hidden = modelLabel.hidden = !setup.needsModel;
|
|
425
465
|
$("#openai-setup").hidden = !setup.needsOpenAIKey || project.preview || project.exported;
|
|
426
466
|
action.inputKind = setup.inputKind;
|
|
467
|
+
action.frameworkOnly = setup.frameworkOnly;
|
|
427
468
|
if (setup.inputKind === "json") $("#run-input-label").textContent = "JSON input";
|
|
428
469
|
action.ready = setup.issues.length === 0;
|
|
429
470
|
$("#run-status").textContent = setup.issues.join(" ");
|
|
@@ -470,6 +511,35 @@ function showRunResults({ answers, traceId, steps }) {
|
|
|
470
511
|
$("#run-result").textContent = lines.join("\n\n");
|
|
471
512
|
}
|
|
472
513
|
|
|
514
|
+
async function streamRun(body) {
|
|
515
|
+
const response = await fetch("/api/run", {
|
|
516
|
+
method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),
|
|
517
|
+
});
|
|
518
|
+
if (!response.ok) throw new Error((await response.json()).error);
|
|
519
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
520
|
+
let remaining = "";
|
|
521
|
+
try {
|
|
522
|
+
for (;;) {
|
|
523
|
+
const { value, done } = await reader.read();
|
|
524
|
+
if (done) break;
|
|
525
|
+
const lines = (remaining + value).split("\n");
|
|
526
|
+
remaining = lines.pop();
|
|
527
|
+
for (const line of lines) {
|
|
528
|
+
const event = JSON.parse(line);
|
|
529
|
+
if (event.type === "event" && event.event.type === "step.started") {
|
|
530
|
+
$("#run-status").textContent = "Running step " + event.event.index + "…";
|
|
531
|
+
}
|
|
532
|
+
if (event.type === "delta") $("#run-result").append(document.createTextNode(event.text));
|
|
533
|
+
if (event.type === "result") return event.result;
|
|
534
|
+
if (event.type === "error") throw Object.assign(new Error(event.message), { progress: event.progress });
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
throw new Error("The run stream ended before completion.");
|
|
538
|
+
} finally {
|
|
539
|
+
await reader.cancel().catch(() => {});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
473
543
|
$("#runner").onsubmit = async event => {
|
|
474
544
|
event.preventDefault();
|
|
475
545
|
if (!pending?.ready || runInProgress) return;
|
|
@@ -487,8 +557,21 @@ $("#runner").onsubmit = async event => {
|
|
|
487
557
|
$("#close-run").disabled = true;
|
|
488
558
|
$("#run-status").textContent = "Running…";
|
|
489
559
|
$("#run-result").textContent = "";
|
|
560
|
+
const body = { targets: pending.targets, buttonId: pending.buttonId, revision: pending.revision,
|
|
561
|
+
input: prompt.value, model: $("#model").value, provider: $("#execution-provider").value };
|
|
562
|
+
const cancel = $("#cancel-run");
|
|
563
|
+
body.streamId = crypto.randomUUID();
|
|
564
|
+
if (body.provider === "vscode" || pending.frameworkOnly) {
|
|
565
|
+
cancel.hidden = false;
|
|
566
|
+
cancel.disabled = false;
|
|
567
|
+
cancel.onclick = async () => {
|
|
568
|
+
cancel.disabled = true;
|
|
569
|
+
try { await api("cancel-run", { streamId: body.streamId }); }
|
|
570
|
+
catch (error) { if (runInProgress) $("#run-status").textContent = error.message; }
|
|
571
|
+
};
|
|
572
|
+
}
|
|
490
573
|
try {
|
|
491
|
-
const result = await
|
|
574
|
+
const result = await streamRun(body);
|
|
492
575
|
showRunResults(result);
|
|
493
576
|
if (pending.outputId) outputs.set(pending.outputId, result.answers.at(-1).output);
|
|
494
577
|
renderCanvas();
|
|
@@ -498,6 +581,8 @@ $("#runner").onsubmit = async event => {
|
|
|
498
581
|
$("#run-status").textContent = error.message;
|
|
499
582
|
} finally {
|
|
500
583
|
runInProgress = false;
|
|
584
|
+
cancel.hidden = true;
|
|
585
|
+
cancel.onclick = null;
|
|
501
586
|
$("#run").disabled = false;
|
|
502
587
|
$("#close-run").disabled = false;
|
|
503
588
|
}
|
|
@@ -535,11 +620,16 @@ async function load({ catalogOnly = false } = {}) {
|
|
|
535
620
|
$("#cloud-state").textContent = project.cloudConnected ? "Cloud connected" : "Working locally";
|
|
536
621
|
$("#pull").hidden = !project.cloudConnected;
|
|
537
622
|
$("#connect-cloud").hidden = project.cloudConnected;
|
|
623
|
+
$("#pause-cloud").hidden = !project.cloudConnected;
|
|
624
|
+
$("#cloud-settings-description").textContent = project.cloudConnected
|
|
625
|
+
? "Pull your Cloud catalog or sync edits from the Agent Registry. Work locally pauses Cloud actions and keeps your saved key."
|
|
626
|
+
: "Your project is working locally. Connect your AgentLyra account to sync supported agents, workflows, teams, and skills.";
|
|
538
627
|
$("#open-memory").hidden = Boolean(project.exported || project.preview);
|
|
628
|
+
$("#open-history").hidden = Boolean(project.exported || project.preview);
|
|
539
629
|
if (project.exported || project.preview) {
|
|
540
630
|
document.body.classList.add("exported");
|
|
541
631
|
document.title = project.name;
|
|
542
|
-
$("
|
|
632
|
+
$("#canvas-panel h1").textContent = project.name;
|
|
543
633
|
} else {
|
|
544
634
|
renderCatalog();
|
|
545
635
|
renderInspector();
|
|
@@ -608,7 +698,9 @@ $("#canvas").ondrop = event => {
|
|
|
608
698
|
selected = node.id;
|
|
609
699
|
change();
|
|
610
700
|
};
|
|
611
|
-
$("#
|
|
701
|
+
$("#show-registry").onclick = () => showView("registry");
|
|
702
|
+
$("#show-cloud").onclick = () => showView("cloud");
|
|
703
|
+
$("#refresh").onclick = () => load({ catalogOnly: true }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
|
|
612
704
|
function openCloudSetup() {
|
|
613
705
|
$("#cloud-key").value = "";
|
|
614
706
|
$("#cloud-key").required = !project.hasCloudKey;
|
|
@@ -619,6 +711,16 @@ function openCloudSetup() {
|
|
|
619
711
|
$("#cloud-setup").showModal();
|
|
620
712
|
}
|
|
621
713
|
$("#connect-cloud").onclick = openCloudSetup;
|
|
714
|
+
$("#pause-cloud").onclick = async () => {
|
|
715
|
+
const control = $("#pause-cloud");
|
|
716
|
+
control.disabled = true;
|
|
717
|
+
try {
|
|
718
|
+
await api("work-locally", {});
|
|
719
|
+
await load({ catalogOnly: true });
|
|
720
|
+
announce("Working locally. Cloud sync is paused.");
|
|
721
|
+
} catch (error) { announce(error.message); }
|
|
722
|
+
finally { control.disabled = false; }
|
|
723
|
+
};
|
|
622
724
|
$("#close-cloud").onclick = () => $("#cloud-setup").close();
|
|
623
725
|
$("#cloud-setup").addEventListener("close", () => { $("#cloud-key").value = ""; });
|
|
624
726
|
$("#cloud-form").onsubmit = async event => {
|
|
@@ -654,4 +756,8 @@ $("#save").onclick = async () => {
|
|
|
654
756
|
finally { $("#save").disabled = false; }
|
|
655
757
|
};
|
|
656
758
|
window.addEventListener("beforeunload", event => { if (dirty || workflowEditor.dirty()) { event.preventDefault(); event.returnValue = ""; } });
|
|
657
|
-
load().
|
|
759
|
+
load().then(() => {
|
|
760
|
+
if (project.exported || project.preview) return;
|
|
761
|
+
showView("mission");
|
|
762
|
+
return syncHistoryLocation();
|
|
763
|
+
}).catch(error => announce(error.message));
|
package/src/studio/export.js
CHANGED
|
@@ -5,12 +5,12 @@ import { readCatalog, resolveSequence, validateLayout, validateRunBindings } fro
|
|
|
5
5
|
|
|
6
6
|
const runtime = [
|
|
7
7
|
"resource-files.js",
|
|
8
|
-
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html", "studio/lyra-icon.png",
|
|
9
|
-
"studio/browser.js", "studio/workflow-editor.js", "studio/cli-providers.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
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",
|
|
8
|
+
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/history-panel.js", "studio/intelligence.js", "studio/graphsnip-workbench.js", "studio/mission-ui.js", "studio/mission-ui.css", "studio/project.js", "studio/sync.js", "studio/index.html", "studio/lyra-icon.png",
|
|
9
|
+
"studio/browser.js", "studio/workflow-editor.js", "studio/cli-providers.js", "studio/ide-provider.js", "studio/local-provider.js", "studio/run-history.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
10
|
+
"memory/index.js", "memory/external-engine.js", "memory/UPSTREAM.json", "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
11
|
"framework/agent.js", "framework/run.py", "framework/mda.js",
|
|
12
12
|
"intelligence/lifecycle.js", "intelligence/graphsnip-provider.js",
|
|
13
|
-
"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",
|
|
13
|
+
"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", "studio/programmatic.js", "studio/programmatic-runner.mjs",
|
|
14
14
|
];
|
|
15
15
|
|
|
16
16
|
export async function exportStudioApp(app, root, directory) {
|
|
@@ -40,6 +40,9 @@ export async function exportStudioApp(app, root, directory) {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
if ([...agents.values()].some(agent => agent.source === "programmatic")) {
|
|
44
|
+
throw new Error("Executable Lyra agents run from their source project. Use Studio or app preview there.");
|
|
45
|
+
}
|
|
43
46
|
if ([...agents.values()].some(agent => agent.source === "framework")) {
|
|
44
47
|
throw new Error("Registered framework agents run from their source project. Use Studio or app preview there.");
|
|
45
48
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
|
|
6
|
+
const exec = promisify(execFile);
|
|
7
|
+
const graphsnipVersion = "0.3.0";
|
|
8
|
+
const name = value => typeof value === "string" ? value.slice(0, 160) : String(value ?? "").slice(0, 160);
|
|
9
|
+
|
|
10
|
+
async function command(root, args, timeout = 10_000) {
|
|
11
|
+
const executable = process.env.LYRA_GRAPHSNIP_EXECUTABLE || "graphsnip";
|
|
12
|
+
return (await exec(executable, args, {
|
|
13
|
+
cwd: root, windowsHide: true, timeout, maxBuffer: 1024 * 1024,
|
|
14
|
+
})).stdout.trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function version(root) {
|
|
18
|
+
try {
|
|
19
|
+
const actual = await command(root, ["--version"]);
|
|
20
|
+
// The upstream 0.3.0 wheel still reports 0.2.1 from its CLI.
|
|
21
|
+
return ["graphsnip 0.2.1", "graphsnip " + graphsnipVersion].includes(actual)
|
|
22
|
+
? { installed: true, version: actual.slice("graphsnip ".length) }
|
|
23
|
+
: { installed: false, issue: "Workbench supports GraphSnip " + graphsnipVersion + "." };
|
|
24
|
+
} catch {
|
|
25
|
+
return { installed: false, issue: "Install GraphSnip " + graphsnipVersion + " or set LYRA_GRAPHSNIP_EXECUTABLE to its executable." };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function knowledgeGraph(root) {
|
|
30
|
+
const dependency = await version(root);
|
|
31
|
+
const folder = join(root, "graphify-out");
|
|
32
|
+
const path = join(folder, "graph.json");
|
|
33
|
+
try {
|
|
34
|
+
if (!(await lstat(folder)).isDirectory()) throw new Error();
|
|
35
|
+
const file = await lstat(path);
|
|
36
|
+
if (!file.isFile() || file.size > 16 * 1024 * 1024) throw new Error();
|
|
37
|
+
const graph = JSON.parse(await readFile(path, "utf8"));
|
|
38
|
+
const edges = graph.links ?? graph.edges;
|
|
39
|
+
if (!Array.isArray(graph.nodes) || !Array.isArray(edges)) throw new Error();
|
|
40
|
+
const nodes = graph.nodes.slice(0, 100).map(node => ({ id: name(node.id), label: name(node.label ?? node.id) }));
|
|
41
|
+
const ids = new Set(nodes.map(node => node.id));
|
|
42
|
+
const links = [];
|
|
43
|
+
for (const edge of edges) {
|
|
44
|
+
const source = name(edge.source);
|
|
45
|
+
const target = name(edge.target);
|
|
46
|
+
if (ids.has(source) && ids.has(target)) links.push({ source, target });
|
|
47
|
+
if (links.length >= 300) break;
|
|
48
|
+
}
|
|
49
|
+
return { ...dependency, graph: { nodeCount: graph.nodes.length, edgeCount: edges.length, nodes, links } };
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return { ...dependency, graph: null, ...(error.code === "ENOENT" ? {} : { graphIssue: "The graph is unreadable or exceeds the Workbench size limit." }) };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function buildKnowledgeGraph(root) {
|
|
56
|
+
const dependency = await version(root);
|
|
57
|
+
if (!dependency.installed) throw new Error(dependency.issue);
|
|
58
|
+
try {
|
|
59
|
+
await command(root, ["build"], 180_000);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new Error("GraphSnip could not update the graph. Run graphsnip build in the project terminal for details.");
|
|
62
|
+
}
|
|
63
|
+
return knowledgeGraph(root);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function graphTokenLedger(root) {
|
|
67
|
+
const dependency = await version(root);
|
|
68
|
+
if (!dependency.installed) return dependency;
|
|
69
|
+
try {
|
|
70
|
+
const result = JSON.parse(await command(root, ["stats", "--json"]));
|
|
71
|
+
const projectLedger = group => Object.fromEntries(["calls", "baseline", "returned", "saved", "pct", "usd_saved"]
|
|
72
|
+
.filter(key => Number.isFinite(group?.[key])).map(key => [key, group[key]]));
|
|
73
|
+
return { ...dependency, live: projectLedger(result.live), benchmark: projectLedger(result.bench) };
|
|
74
|
+
} catch {
|
|
75
|
+
return { ...dependency, issue: "GraphSnip's project ledger could not be read." };
|
|
76
|
+
}
|
|
77
|
+
}
|