agent-lyra 0.8.0 → 0.11.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.
Files changed (128) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +320 -291
  3. package/bin/agent-lyra.js +51 -51
  4. package/bin/lyra-oss-preview.js +16 -16
  5. package/package.json +60 -60
  6. package/src/app-builder/export.js +109 -109
  7. package/src/app-builder/gateway.js +62 -62
  8. package/src/app-builder/init.js +115 -72
  9. package/src/app-builder/manifest-contract.js +46 -46
  10. package/src/app-builder/native-adapter.js +29 -29
  11. package/src/app-builder/preview.js +35 -31
  12. package/src/app-builder/publish.js +14 -14
  13. package/src/app-builder/saved-app.js +73 -70
  14. package/src/app-builder/saved-preview-browser.js +33 -33
  15. package/src/app-builder/saved-preview.html +24 -24
  16. package/src/app-builder/saved-preview.js +61 -61
  17. package/src/app-builder/support-manifest.js +50 -50
  18. package/src/app-builder/support-template/manifest.json +55 -55
  19. package/src/app-builder/support-template/support-preview.html +56 -56
  20. package/src/app-builder/support-template/support-preview.js +37 -37
  21. package/src/app-builder/support-template/support-preview.mjs +67 -67
  22. package/src/app-builder/support-template/support-workflow.mjs +36 -36
  23. package/src/app-builder/use.js +37 -37
  24. package/src/app-builder/validate.js +31 -21
  25. package/src/app-builder/value-schema.js +37 -37
  26. package/src/catalog.js +147 -147
  27. package/src/coding/catalog.js +56 -56
  28. package/src/coding/cloud-catalog.js +64 -64
  29. package/src/coding/detect-stack.mjs +110 -110
  30. package/src/coding/export.js +133 -133
  31. package/src/coding/setup.js +175 -175
  32. package/src/coding/skills/lyra-android/SKILL.md +37 -37
  33. package/src/coding/skills/lyra-angular/SKILL.md +37 -37
  34. package/src/coding/skills/lyra-cucumber/SKILL.md +37 -37
  35. package/src/coding/skills/lyra-dbt/SKILL.md +37 -37
  36. package/src/coding/skills/lyra-django/SKILL.md +37 -37
  37. package/src/coding/skills/lyra-docker/SKILL.md +37 -37
  38. package/src/coding/skills/lyra-dotnet/SKILL.md +37 -37
  39. package/src/coding/skills/lyra-express/SKILL.md +37 -37
  40. package/src/coding/skills/lyra-fastapi/SKILL.md +37 -37
  41. package/src/coding/skills/lyra-flutter/SKILL.md +37 -37
  42. package/src/coding/skills/lyra-github-actions/SKILL.md +37 -37
  43. package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -37
  44. package/src/coding/skills/lyra-go/SKILL.md +37 -37
  45. package/src/coding/skills/lyra-ios/SKILL.md +37 -37
  46. package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -37
  47. package/src/coding/skills/lyra-mongodb/SKILL.md +37 -37
  48. package/src/coding/skills/lyra-mysql/SKILL.md +37 -37
  49. package/src/coding/skills/lyra-nextjs/SKILL.md +37 -37
  50. package/src/coding/skills/lyra-node/SKILL.md +37 -37
  51. package/src/coding/skills/lyra-playwright/SKILL.md +37 -37
  52. package/src/coding/skills/lyra-postgresql/SKILL.md +37 -37
  53. package/src/coding/skills/lyra-python/SKILL.md +37 -37
  54. package/src/coding/skills/lyra-react/SKILL.md +37 -37
  55. package/src/coding/skills/lyra-react-native/SKILL.md +37 -37
  56. package/src/coding/skills/lyra-redis/SKILL.md +37 -37
  57. package/src/coding/skills/lyra-rust/SKILL.md +37 -37
  58. package/src/coding/skills/lyra-spark/SKILL.md +37 -37
  59. package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -37
  60. package/src/coding/skills/lyra-svelte/SKILL.md +37 -37
  61. package/src/coding/skills/lyra-terraform/SKILL.md +37 -37
  62. package/src/coding/skills/lyra-typescript/SKILL.md +37 -37
  63. package/src/coding/skills/lyra-vue/SKILL.md +37 -37
  64. package/src/framework/agent.js +181 -181
  65. package/src/framework/mda.js +65 -65
  66. package/src/framework/run.py +111 -111
  67. package/src/gated/hostedAgents.js +56 -56
  68. package/src/gated/index.d.ts +25 -25
  69. package/src/gated/index.js +5 -5
  70. package/src/index.d.ts +2 -2
  71. package/src/index.js +2 -2
  72. package/src/init.js +963 -960
  73. package/src/intelligence/graphsnip-provider.d.ts +5 -5
  74. package/src/intelligence/graphsnip-provider.js +57 -57
  75. package/src/intelligence/lifecycle.js +25 -25
  76. package/src/memory/LICENSE +21 -21
  77. package/src/memory/README.md +5 -5
  78. package/src/memory/UPSTREAM.json +24 -24
  79. package/src/memory/bridge-cli.js +16 -16
  80. package/src/memory/bridge.js +18 -18
  81. package/src/memory/cli.js +21 -21
  82. package/src/memory/cloud-sync-actions.js +61 -61
  83. package/src/memory/contract.json +45 -45
  84. package/src/memory/index.d.ts +50 -50
  85. package/src/memory/index.js +7 -7
  86. package/src/memory/lifecycle.js +29 -29
  87. package/src/memory/local-cli.js +34 -34
  88. package/src/memory/local-store.js +209 -209
  89. package/src/memory/package.json +33 -33
  90. package/src/memory/proposals.js +90 -90
  91. package/src/memory/skills-cli.js +26 -26
  92. package/src/memory/standalone.d.ts +50 -50
  93. package/src/memory/standalone.js +1 -1
  94. package/src/memory/sync.js +89 -89
  95. package/src/memory/validation.js +25 -25
  96. package/src/onboardingAgents.js +532 -532
  97. package/src/promptTemplates.js +178 -178
  98. package/src/resource-files.js +18 -18
  99. package/src/runtime/contracts.d.ts +47 -47
  100. package/src/runtime/local-cli.js +161 -161
  101. package/src/runtime/mcp-stdio.js +111 -111
  102. package/src/runtime/orchestration.js +59 -59
  103. package/src/runtime/run-agent.js +54 -54
  104. package/src/standalone/index.d.ts +45 -45
  105. package/src/standalone/index.js +13 -13
  106. package/src/standalone/init.js +14 -12
  107. package/src/standalone/orchestration.js +6 -6
  108. package/src/standalone/rag.js +113 -113
  109. package/src/studio/agent-ui.css +43 -43
  110. package/src/studio/agent-ui.js +32 -32
  111. package/src/studio/browser.js +562 -345
  112. package/src/studio/cli-providers.js +40 -0
  113. package/src/studio/export.js +83 -86
  114. package/src/studio/index.html +74 -37
  115. package/src/studio/memory-actions.js +37 -37
  116. package/src/studio/memory-panel.js +200 -200
  117. package/src/studio/project.js +333 -240
  118. package/src/studio/pull-agent.js +72 -72
  119. package/src/studio/push.js +54 -54
  120. package/src/studio/python-agent.js +47 -47
  121. package/src/studio/python-agent.py +25 -25
  122. package/src/studio/server.js +164 -150
  123. package/src/studio/session.js +83 -83
  124. package/src/studio/studio.css +257 -10
  125. package/src/studio/sync.js +42 -42
  126. package/src/studio/workflow-editor.js +240 -0
  127. package/src/studio/workflow-sync.js +229 -157
  128. package/src/vscode/workspace.js +158 -0
@@ -1,54 +1,54 @@
1
- import { randomUUID } from "node:crypto";
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_ENDPOINT: ["endpoint_error", "Check the local MDA server, assistant ID, and authorization."],
7
- FRAMEWORK_OUTPUT: ["invalid_output", "Framework agent returned an invalid output."],
8
- };
9
-
10
- /**
11
- * @param {{
12
- * agentId: string,
13
- * request: import("./contracts.js").ModelRequest,
14
- * provider: import("./contracts.js").ModelProvider,
15
- * store: import("./contracts.js").RunStore,
16
- * traceId?: string, framework?: string, revision?: string,
17
- * onStarted?: (runId: string) => void,
18
- * }} options
19
- */
20
- export async function runAgent({ agentId, request, provider, store, onStarted, traceId, framework, revision }) {
21
- const runId = randomUUID();
22
- const started = Date.now();
23
- /** @param {number} seq */
24
- const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString(), ...(traceId ? { schemaVersion: 1, trace_id: traceId } : {}) });
25
- await store.append({
26
- ...envelope(0),
27
- type: "run.started",
28
- data: { agentId, model: request.model, ...(framework ? { framework, revision, execution: "local" } : {}) },
29
- });
30
- onStarted?.(runId);
31
-
32
- /** @type {import("./contracts.js").ModelResult} */
33
- let result;
34
- try {
35
- result = await provider.complete(request);
36
- } catch (error) {
37
- const [reason, message] = Object.hasOwn(frameworkFailures, error?.code)
38
- ? frameworkFailures[error.code] : ["execution_error", "Framework execution failed."];
39
- const failed = /** @type {const} */ ({
40
- ...envelope(1),
41
- type: "run.failed",
42
- data: { message: framework ? message : "Model request failed.", ...(framework ? { durationMs: Date.now() - started, reason } : {}) },
43
- });
44
- await store.append(failed);
45
- return failed;
46
- }
47
- const completed = /** @type {const} */ ({
48
- ...envelope(1),
49
- type: "run.completed",
50
- data: { result },
51
- });
52
- await store.append(framework ? { ...completed, data: { durationMs: Date.now() - started } } : completed);
53
- return completed;
54
- }
1
+ import { randomUUID } from "node:crypto";
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_ENDPOINT: ["endpoint_error", "Check the local MDA server, assistant ID, and authorization."],
7
+ FRAMEWORK_OUTPUT: ["invalid_output", "Framework agent returned an invalid output."],
8
+ };
9
+
10
+ /**
11
+ * @param {{
12
+ * agentId: string,
13
+ * request: import("./contracts.js").ModelRequest,
14
+ * provider: import("./contracts.js").ModelProvider,
15
+ * store: import("./contracts.js").RunStore,
16
+ * traceId?: string, framework?: string, revision?: string,
17
+ * onStarted?: (runId: string) => void,
18
+ * }} options
19
+ */
20
+ export async function runAgent({ agentId, request, provider, store, onStarted, traceId, framework, revision }) {
21
+ const runId = randomUUID();
22
+ const started = Date.now();
23
+ /** @param {number} seq */
24
+ const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString(), ...(traceId ? { schemaVersion: 1, trace_id: traceId } : {}) });
25
+ await store.append({
26
+ ...envelope(0),
27
+ type: "run.started",
28
+ data: { agentId, model: request.model, ...(framework ? { framework, revision, execution: "local" } : {}) },
29
+ });
30
+ onStarted?.(runId);
31
+
32
+ /** @type {import("./contracts.js").ModelResult} */
33
+ let result;
34
+ try {
35
+ result = await provider.complete(request);
36
+ } catch (error) {
37
+ const [reason, message] = Object.hasOwn(frameworkFailures, error?.code)
38
+ ? frameworkFailures[error.code] : ["execution_error", "Framework execution failed."];
39
+ const failed = /** @type {const} */ ({
40
+ ...envelope(1),
41
+ type: "run.failed",
42
+ data: { message: framework ? message : "Model request failed.", ...(framework ? { durationMs: Date.now() - started, reason } : {}) },
43
+ });
44
+ await store.append(failed);
45
+ return failed;
46
+ }
47
+ const completed = /** @type {const} */ ({
48
+ ...envelope(1),
49
+ type: "run.completed",
50
+ data: { result },
51
+ });
52
+ await store.append(framework ? { ...completed, data: { durationMs: Date.now() - started } } : completed);
53
+ return completed;
54
+ }
@@ -1,45 +1,45 @@
1
- export type WorkflowContext = Record<string, unknown>;
2
- export type TaskHandler = (context: WorkflowContext) => unknown;
3
-
4
- export interface Task {
5
- id: string;
6
- handler: TaskHandler;
7
- }
8
-
9
- export interface Workflow {
10
- tasks: Map<string, TaskHandler>;
11
- add(task: Task): this;
12
- list(): string[];
13
- }
14
-
15
- export function createTask(id: string, handler: TaskHandler): Task;
16
- export function createWorkflow(tasks?: Iterable<Task>): Workflow;
17
- export function createLinearWorkflow(...handlers: TaskHandler[]): Workflow;
18
- export function runWorkflow(workflow: Workflow, initialContext?: WorkflowContext): Promise<WorkflowContext>;
19
-
20
- export interface Document {
21
- id: string;
22
- text: string;
23
- metadata?: Record<string, unknown>;
24
- }
25
-
26
- export interface SearchOptions {
27
- topK?: number;
28
- }
29
-
30
- export interface VectorStore {
31
- add(document: Document): Promise<string>;
32
- search(query: string, options?: SearchOptions): Promise<Array<Document & { vector: number[]; score: number }>>;
33
- size(): number;
34
- }
35
-
36
- export interface KeywordRetriever<T extends Document = Document> {
37
- add(document: T): string;
38
- search(query: string, options?: SearchOptions): Array<T & { score: number }>;
39
- size(): number;
40
- }
41
-
42
- export function chunkText(text: string, options?: { chunkSize?: number; overlap?: number }): string[];
43
- export function cosineSimilarity(a: readonly number[], b: readonly number[]): number;
44
- export function createInMemoryVectorStore(embedder: (text: string) => number[] | Promise<number[]>): VectorStore;
45
- export function createKeywordRetriever<T extends Document = Document>(documents?: Iterable<T>): KeywordRetriever<T>;
1
+ export type WorkflowContext = Record<string, unknown>;
2
+ export type TaskHandler = (context: WorkflowContext) => unknown;
3
+
4
+ export interface Task {
5
+ id: string;
6
+ handler: TaskHandler;
7
+ }
8
+
9
+ export interface Workflow {
10
+ tasks: Map<string, TaskHandler>;
11
+ add(task: Task): this;
12
+ list(): string[];
13
+ }
14
+
15
+ export function createTask(id: string, handler: TaskHandler): Task;
16
+ export function createWorkflow(tasks?: Iterable<Task>): Workflow;
17
+ export function createLinearWorkflow(...handlers: TaskHandler[]): Workflow;
18
+ export function runWorkflow(workflow: Workflow, initialContext?: WorkflowContext): Promise<WorkflowContext>;
19
+
20
+ export interface Document {
21
+ id: string;
22
+ text: string;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+
26
+ export interface SearchOptions {
27
+ topK?: number;
28
+ }
29
+
30
+ export interface VectorStore {
31
+ add(document: Document): Promise<string>;
32
+ search(query: string, options?: SearchOptions): Promise<Array<Document & { vector: number[]; score: number }>>;
33
+ size(): number;
34
+ }
35
+
36
+ export interface KeywordRetriever<T extends Document = Document> {
37
+ add(document: T): string;
38
+ search(query: string, options?: SearchOptions): Array<T & { score: number }>;
39
+ size(): number;
40
+ }
41
+
42
+ export function chunkText(text: string, options?: { chunkSize?: number; overlap?: number }): string[];
43
+ export function cosineSimilarity(a: readonly number[], b: readonly number[]): number;
44
+ export function createInMemoryVectorStore(embedder: (text: string) => number[] | Promise<number[]>): VectorStore;
45
+ export function createKeywordRetriever<T extends Document = Document>(documents?: Iterable<T>): KeywordRetriever<T>;
@@ -1,13 +1,13 @@
1
- export {
2
- createWorkflow,
3
- runWorkflow,
4
- createTask,
5
- createLinearWorkflow,
6
- } from "./orchestration.js";
7
-
8
- export {
9
- chunkText,
10
- cosineSimilarity,
11
- createInMemoryVectorStore,
12
- createKeywordRetriever,
13
- } from "./rag.js";
1
+ export {
2
+ createWorkflow,
3
+ runWorkflow,
4
+ createTask,
5
+ createLinearWorkflow,
6
+ } from "./orchestration.js";
7
+
8
+ export {
9
+ chunkText,
10
+ cosineSimilarity,
11
+ createInMemoryVectorStore,
12
+ createKeywordRetriever,
13
+ } from "./rag.js";
@@ -1,12 +1,14 @@
1
- import { mkdir, writeFile } from 'node:fs/promises';
2
- import { resolve, join } from 'node:path';
3
- import { parseArgs } from 'node:util';
4
- export async function initStandalone(args) {
5
- if(args.includes('--help')) { console.log('Usage: agent-lyra init [--mode standalone] [--dir <directory>]'); return; }
6
- const {values}=parseArgs({args,options:{mode:{type:'string'},dir:{type:'string'}}});
7
- if(values.mode && values.mode!=='standalone') throw new Error('Only standalone initialization is available in this source edition.');
8
- const root=resolve(values.dir||process.cwd(),'.lyra');
9
- for(const folder of ['agents','skills','workflows','teams']) await mkdir(join(root,folder),{recursive:true});
10
- await writeFile(join(root,'config.json'),JSON.stringify({version:1,mode:'standalone',domains:[]},null,2)+'\n',{flag:'wx'}).catch(e=>{if(e.code!=='EEXIST')throw e;});
11
- console.log('Initialized '+root+' (existing files preserved).');
12
- }
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { resolve, join } from 'node:path';
3
+ import { parseArgs } from 'node:util';
4
+ import { ensureVSCodeAgentDiscovery } from '../vscode/workspace.js';
5
+ export async function initStandalone(args) {
6
+ if(args.includes('--help')) { console.log('Usage: agent-lyra init [--mode standalone] [--dir <directory>]'); return; }
7
+ const {values}=parseArgs({args,options:{mode:{type:'string'},dir:{type:'string'}}});
8
+ if(values.mode && values.mode!=='standalone') throw new Error('Only standalone initialization is available in this source edition.');
9
+ const root=resolve(values.dir||process.cwd(),'.lyra');
10
+ for(const folder of ['agents','skills','workflows','teams']) await mkdir(join(root,folder),{recursive:true});
11
+ await writeFile(join(root,'config.json'),JSON.stringify({version:1,mode:'standalone',domains:[]},null,2)+'\n',{flag:'wx'}).catch(e=>{if(e.code!=='EEXIST')throw e;});
12
+ await ensureVSCodeAgentDiscovery(resolve(values.dir||process.cwd()));
13
+ console.log('Initialized '+root+' (existing files preserved).');
14
+ }
@@ -1,6 +1,6 @@
1
- export {
2
- createWorkflow,
3
- runWorkflow,
4
- createTask,
5
- createLinearWorkflow,
6
- } from "../runtime/orchestration.js";
1
+ export {
2
+ createWorkflow,
3
+ runWorkflow,
4
+ createTask,
5
+ createLinearWorkflow,
6
+ } from "../runtime/orchestration.js";
@@ -1,113 +1,113 @@
1
- export function chunkText(text, { chunkSize = 500, overlap = 50 } = {}) {
2
- if (typeof text !== "string") {
3
- throw new Error("text must be a string");
4
- }
5
- if (chunkSize <= 0) {
6
- throw new Error("chunkSize must be > 0");
7
- }
8
- if (overlap < 0 || overlap >= chunkSize) {
9
- throw new Error("overlap must be >= 0 and < chunkSize");
10
- }
11
-
12
- const chunks = [];
13
- let start = 0;
14
-
15
- while (start < text.length) {
16
- const end = Math.min(start + chunkSize, text.length);
17
- chunks.push(text.slice(start, end));
18
- if (end === text.length) {
19
- break;
20
- }
21
- start = end - overlap;
22
- }
23
-
24
- return chunks;
25
- }
26
-
27
- export function cosineSimilarity(a, b) {
28
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
29
- throw new Error("Vectors must be arrays with equal length.");
30
- }
31
-
32
- let dot = 0;
33
- let normA = 0;
34
- let normB = 0;
35
-
36
- for (let i = 0; i < a.length; i += 1) {
37
- dot += a[i] * b[i];
38
- normA += a[i] * a[i];
39
- normB += b[i] * b[i];
40
- }
41
-
42
- if (normA === 0 || normB === 0) {
43
- return 0;
44
- }
45
-
46
- return dot / (Math.sqrt(normA) * Math.sqrt(normB));
47
- }
48
-
49
- export function createInMemoryVectorStore(embedder) {
50
- if (typeof embedder !== "function") {
51
- throw new Error("embedder must be a function");
52
- }
53
-
54
- const docs = [];
55
-
56
- return {
57
- async add({ id, text, metadata = {} }) {
58
- if (!id || typeof text !== "string") {
59
- throw new Error("Document requires id and text.");
60
- }
61
- const vector = await embedder(text);
62
- docs.push({ id, text, metadata, vector });
63
- return id;
64
- },
65
- async search(query, { topK = 5 } = {}) {
66
- const queryVector = await embedder(query);
67
- return docs
68
- .map((doc) => ({
69
- ...doc,
70
- score: cosineSimilarity(queryVector, doc.vector),
71
- }))
72
- .sort((left, right) => right.score - left.score)
73
- .slice(0, topK);
74
- },
75
- size() {
76
- return docs.length;
77
- },
78
- };
79
- }
80
-
81
- export function createKeywordRetriever(documents = []) {
82
- const docs = [...documents];
83
-
84
- return {
85
- add(document) {
86
- if (!document?.id || typeof document.text !== "string") {
87
- throw new Error("Document requires id and text.");
88
- }
89
- docs.push(document);
90
- return document.id;
91
- },
92
- search(query, { topK = 5 } = {}) {
93
- const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
94
- return docs
95
- .map((doc) => {
96
- const body = doc.text.toLowerCase();
97
- let hits = 0;
98
- for (const term of terms) {
99
- if (body.includes(term)) {
100
- hits += 1;
101
- }
102
- }
103
- return { ...doc, score: hits };
104
- })
105
- .filter((doc) => doc.score > 0)
106
- .sort((left, right) => right.score - left.score)
107
- .slice(0, topK);
108
- },
109
- size() {
110
- return docs.length;
111
- },
112
- };
113
- }
1
+ export function chunkText(text, { chunkSize = 500, overlap = 50 } = {}) {
2
+ if (typeof text !== "string") {
3
+ throw new Error("text must be a string");
4
+ }
5
+ if (chunkSize <= 0) {
6
+ throw new Error("chunkSize must be > 0");
7
+ }
8
+ if (overlap < 0 || overlap >= chunkSize) {
9
+ throw new Error("overlap must be >= 0 and < chunkSize");
10
+ }
11
+
12
+ const chunks = [];
13
+ let start = 0;
14
+
15
+ while (start < text.length) {
16
+ const end = Math.min(start + chunkSize, text.length);
17
+ chunks.push(text.slice(start, end));
18
+ if (end === text.length) {
19
+ break;
20
+ }
21
+ start = end - overlap;
22
+ }
23
+
24
+ return chunks;
25
+ }
26
+
27
+ export function cosineSimilarity(a, b) {
28
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
29
+ throw new Error("Vectors must be arrays with equal length.");
30
+ }
31
+
32
+ let dot = 0;
33
+ let normA = 0;
34
+ let normB = 0;
35
+
36
+ for (let i = 0; i < a.length; i += 1) {
37
+ dot += a[i] * b[i];
38
+ normA += a[i] * a[i];
39
+ normB += b[i] * b[i];
40
+ }
41
+
42
+ if (normA === 0 || normB === 0) {
43
+ return 0;
44
+ }
45
+
46
+ return dot / (Math.sqrt(normA) * Math.sqrt(normB));
47
+ }
48
+
49
+ export function createInMemoryVectorStore(embedder) {
50
+ if (typeof embedder !== "function") {
51
+ throw new Error("embedder must be a function");
52
+ }
53
+
54
+ const docs = [];
55
+
56
+ return {
57
+ async add({ id, text, metadata = {} }) {
58
+ if (!id || typeof text !== "string") {
59
+ throw new Error("Document requires id and text.");
60
+ }
61
+ const vector = await embedder(text);
62
+ docs.push({ id, text, metadata, vector });
63
+ return id;
64
+ },
65
+ async search(query, { topK = 5 } = {}) {
66
+ const queryVector = await embedder(query);
67
+ return docs
68
+ .map((doc) => ({
69
+ ...doc,
70
+ score: cosineSimilarity(queryVector, doc.vector),
71
+ }))
72
+ .sort((left, right) => right.score - left.score)
73
+ .slice(0, topK);
74
+ },
75
+ size() {
76
+ return docs.length;
77
+ },
78
+ };
79
+ }
80
+
81
+ export function createKeywordRetriever(documents = []) {
82
+ const docs = [...documents];
83
+
84
+ return {
85
+ add(document) {
86
+ if (!document?.id || typeof document.text !== "string") {
87
+ throw new Error("Document requires id and text.");
88
+ }
89
+ docs.push(document);
90
+ return document.id;
91
+ },
92
+ search(query, { topK = 5 } = {}) {
93
+ const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
94
+ return docs
95
+ .map((doc) => {
96
+ const body = doc.text.toLowerCase();
97
+ let hits = 0;
98
+ for (const term of terms) {
99
+ if (body.includes(term)) {
100
+ hits += 1;
101
+ }
102
+ }
103
+ return { ...doc, score: hits };
104
+ })
105
+ .filter((doc) => doc.score > 0)
106
+ .sort((left, right) => right.score - left.score)
107
+ .slice(0, topK);
108
+ },
109
+ size() {
110
+ return docs.length;
111
+ },
112
+ };
113
+ }
@@ -1,43 +1,43 @@
1
- .lyra-run-card {
2
- display: flex;
3
- flex-direction: column;
4
- gap: 8px;
5
- min-width: 0;
6
- padding: 14px;
7
- border: 1px solid var(--lyra-color-border, #cbdcd1);
8
- border-top: 3px solid var(--lyra-color-primary, #174b38);
9
- border-radius: 12px;
10
- background: var(--lyra-color-surface, #fff);
11
- color: var(--lyra-color-text, #173328);
12
- }
13
- .lyra-run-card-clickable { min-height: 350px; padding: 20px; cursor: pointer; }
14
- .lyra-run-card-heading { display: grid; gap: 3px; }
15
- .lyra-run-card-source { font-size: 11px; color: var(--lyra-color-text-muted, #47675a); }
16
- .lyra-run-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
17
- .lyra-run-card-actions .lyra-run-action {
18
- display: inline-flex;
19
- align-items: center;
20
- justify-content: center;
21
- gap: 8px;
22
- min-height: 36px;
23
- padding: 0 12px;
24
- border: 0;
25
- border-radius: 8px;
26
- background: var(--lyra-color-primary, #174b38);
27
- color: var(--app-on-accent, #fff);
28
- font: inherit;
29
- font-size: 12px;
30
- font-weight: 600;
31
- cursor: pointer;
32
- }
33
- .lyra-run-card-clickable .lyra-run-action { flex: 1; min-height: 40px; }
34
- .lyra-run-action:hover:not(:disabled) { filter: brightness(.94); }
35
- .lyra-run-action:disabled { opacity: .5; cursor: default; }
36
- .lyra-run-header { display: flex; align-items: center; gap: 10px; }
37
- .lyra-run-heading { flex: 1; min-width: 0; }
38
- .lyra-run-heading-line { display: flex; align-items: center; gap: 8px; }
39
- .lyra-run-header .lyra-run-title { font-size: 14px; font-weight: 650; line-height: 1.3; margin: 0; }
40
- .lyra-run-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
41
- .lyra-run-header .lyra-run-card-source { flex-shrink: 0; }
42
- .lyra-run-close { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; cursor: pointer; }
43
- .rd-header .lyra-run-close { width: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--lyra-color-text-muted); }
1
+ .lyra-run-card {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 8px;
5
+ min-width: 0;
6
+ padding: 14px;
7
+ border: 1px solid var(--lyra-color-border, #cbdcd1);
8
+ border-top: 3px solid var(--lyra-color-primary, #174b38);
9
+ border-radius: 12px;
10
+ background: var(--lyra-color-surface, #fff);
11
+ color: var(--lyra-color-text, #173328);
12
+ }
13
+ .lyra-run-card-clickable { min-height: 350px; padding: 20px; cursor: pointer; }
14
+ .lyra-run-card-heading { display: grid; gap: 3px; }
15
+ .lyra-run-card-source { font-size: 11px; color: var(--lyra-color-text-muted, #47675a); }
16
+ .lyra-run-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
17
+ .lyra-run-card-actions .lyra-run-action {
18
+ display: inline-flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ gap: 8px;
22
+ min-height: 36px;
23
+ padding: 0 12px;
24
+ border: 0;
25
+ border-radius: 8px;
26
+ background: var(--lyra-color-primary, #174b38);
27
+ color: var(--app-on-accent, #fff);
28
+ font: inherit;
29
+ font-size: 12px;
30
+ font-weight: 600;
31
+ cursor: pointer;
32
+ }
33
+ .lyra-run-card-clickable .lyra-run-action { flex: 1; min-height: 40px; }
34
+ .lyra-run-action:hover:not(:disabled) { filter: brightness(.94); }
35
+ .lyra-run-action:disabled { opacity: .5; cursor: default; }
36
+ .lyra-run-header { display: flex; align-items: center; gap: 10px; }
37
+ .lyra-run-heading { flex: 1; min-width: 0; }
38
+ .lyra-run-heading-line { display: flex; align-items: center; gap: 8px; }
39
+ .lyra-run-header .lyra-run-title { font-size: 14px; font-weight: 650; line-height: 1.3; margin: 0; }
40
+ .lyra-run-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
41
+ .lyra-run-header .lyra-run-card-source { flex-shrink: 0; }
42
+ .lyra-run-close { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; cursor: pointer; }
43
+ .rd-header .lyra-run-close { width: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--lyra-color-text-muted); }
@@ -1,32 +1,32 @@
1
- export function renderAgentCard(h, { name, source, onRun, onOpen, header, details, extraAction, runIcon }) {
2
- return h("article", { className: "lyra-run-card" + (onOpen ? " lyra-run-card-clickable" : ""), onClick: onOpen },
3
- header ?? h("div", { className: "lyra-run-card-heading" },
4
- h("span", { className: "lyra-run-card-source" }, source),
5
- h("strong", { className: "lyra-run-title", title: name }, name)),
6
- details,
7
- h("div", { className: "lyra-run-card-actions" },
8
- h("button", {
9
- type: "button", className: "lyra-run-action", disabled: !onRun,
10
- onClick: event => { event.stopPropagation(); onRun?.(); },
11
- }, runIcon, "Run now"),
12
- extraAction));
13
- }
14
-
15
- export function renderRunHeader(h, { title, kind, icon, details, actions, onClose, closeIcon, closeId, className, style }) {
16
- return h("header", { className: ["lyra-run-header", className].filter(Boolean).join(" "), style },
17
- icon,
18
- h("div", { className: "lyra-run-heading" },
19
- title && h("div", { className: "lyra-run-heading-line" },
20
- h("h2", { className: "lyra-run-title", id: closeId ? "run-title" : undefined }, title),
21
- kind && h("span", { className: "lyra-run-card-source" }, kind)),
22
- details),
23
- actions,
24
- onClose && renderRunClose(h, { onClose, closeIcon, closeId }));
25
- }
26
-
27
- export function renderRunClose(h, { onClose, closeIcon, closeId }) {
28
- return h("button", {
29
- type: "button", className: "lyra-run-close", id: closeId,
30
- onClick: onClose, title: "Close run drawer", "aria-label": "Close run drawer",
31
- }, closeIcon ?? "Close");
32
- }
1
+ export function renderAgentCard(h, { name, source, onRun, onOpen, header, details, extraAction, runIcon }) {
2
+ return h("article", { className: "lyra-run-card" + (onOpen ? " lyra-run-card-clickable" : ""), onClick: onOpen },
3
+ header ?? h("div", { className: "lyra-run-card-heading" },
4
+ h("span", { className: "lyra-run-card-source" }, source),
5
+ h("strong", { className: "lyra-run-title", title: name }, name)),
6
+ details,
7
+ h("div", { className: "lyra-run-card-actions" },
8
+ h("button", {
9
+ type: "button", className: "lyra-run-action", disabled: !onRun,
10
+ onClick: event => { event.stopPropagation(); onRun?.(); },
11
+ }, runIcon, "Run now"),
12
+ extraAction));
13
+ }
14
+
15
+ export function renderRunHeader(h, { title, kind, icon, details, actions, onClose, closeIcon, closeId, className, style }) {
16
+ return h("header", { className: ["lyra-run-header", className].filter(Boolean).join(" "), style },
17
+ icon,
18
+ h("div", { className: "lyra-run-heading" },
19
+ title && h("div", { className: "lyra-run-heading-line" },
20
+ h("h2", { className: "lyra-run-title", id: closeId ? "run-title" : undefined }, title),
21
+ kind && h("span", { className: "lyra-run-card-source" }, kind)),
22
+ details),
23
+ actions,
24
+ onClose && renderRunClose(h, { onClose, closeIcon, closeId }));
25
+ }
26
+
27
+ export function renderRunClose(h, { onClose, closeIcon, closeId }) {
28
+ return h("button", {
29
+ type: "button", className: "lyra-run-close", id: closeId,
30
+ onClick: onClose, title: "Close run drawer", "aria-label": "Close run drawer",
31
+ }, closeIcon ?? "Close");
32
+ }