agent-lyra 0.6.2 → 0.6.3
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/LICENSE +21 -21
- package/README.md +435 -435
- package/bin/agent-lyra.js +49 -49
- package/bin/lyra-oss-preview.js +16 -14
- package/package.json +60 -60
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/gateway.js +62 -62
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/manifest-contract.js +46 -46
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +22 -22
- package/src/app-builder/publish.js +14 -14
- 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/support-manifest.js +50 -50
- package/src/app-builder/support-template/manifest.json +55 -55
- package/src/app-builder/support-template/support-preview.html +56 -56
- package/src/app-builder/support-template/support-preview.js +37 -37
- package/src/app-builder/support-template/support-preview.mjs +67 -67
- package/src/app-builder/support-template/support-workflow.mjs +36 -36
- package/src/app-builder/use.js +37 -37
- package/src/app-builder/validate.js +21 -21
- package/src/app-builder/value-schema.js +37 -37
- package/src/catalog.js +147 -147
- package/src/coding/catalog.js +56 -56
- package/src/coding/cloud-catalog.js +64 -44
- package/src/coding/detect-stack.mjs +110 -110
- package/src/coding/export.js +130 -130
- package/src/coding/setup.js +175 -174
- package/src/coding/skills/lyra-android/SKILL.md +37 -0
- package/src/coding/skills/lyra-angular/SKILL.md +37 -0
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -0
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -0
- package/src/coding/skills/lyra-django/SKILL.md +37 -0
- package/src/coding/skills/lyra-docker/SKILL.md +37 -0
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -0
- package/src/coding/skills/lyra-express/SKILL.md +37 -0
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -0
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -0
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -0
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -0
- package/src/coding/skills/lyra-go/SKILL.md +37 -0
- package/src/coding/skills/lyra-ios/SKILL.md +37 -0
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -0
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -0
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -0
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -0
- package/src/coding/skills/lyra-node/SKILL.md +37 -0
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -0
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -0
- package/src/coding/skills/lyra-python/SKILL.md +37 -0
- package/src/coding/skills/lyra-react/SKILL.md +37 -0
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -0
- package/src/coding/skills/lyra-redis/SKILL.md +37 -0
- package/src/coding/skills/lyra-rust/SKILL.md +37 -0
- package/src/coding/skills/lyra-spark/SKILL.md +37 -0
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -0
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -0
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -0
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -0
- package/src/coding/skills/lyra-vue/SKILL.md +37 -0
- package/src/gated/hostedAgents.js +56 -56
- package/src/gated/index.d.ts +25 -25
- package/src/gated/index.js +5 -5
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/init.js +965 -965
- package/src/memory/cli.js +21 -21
- package/src/memory/contract.json +28 -28
- package/src/memory/index.d.ts +49 -49
- package/src/memory/index.js +259 -259
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -34
- package/src/memory/proposals.js +84 -84
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/sync.js +89 -89
- package/src/memory/validation.js +25 -25
- package/src/onboardingAgents.js +532 -532
- package/src/promptTemplates.js +178 -178
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +160 -160
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +43 -43
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -0
- package/src/standalone/orchestration.js +6 -6
- package/src/standalone/rag.js +113 -113
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -331
- package/src/studio/export.js +80 -80
- package/src/studio/index.html +37 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +216 -216
- package/src/studio/pull-agent.js +72 -72
- package/src/studio/push.js +54 -54
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -143
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +10 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-sync.js +157 -157
package/src/runtime/run-agent.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {{
|
|
5
|
-
* agentId: string,
|
|
6
|
-
* request: import("./contracts.js").ModelRequest,
|
|
7
|
-
* provider: import("./contracts.js").ModelProvider,
|
|
8
|
-
* store: import("./contracts.js").RunStore,
|
|
9
|
-
* onStarted?: (runId: string) => void,
|
|
10
|
-
* }} options
|
|
11
|
-
*/
|
|
12
|
-
export async function runAgent({ agentId, request, provider, store, onStarted }) {
|
|
13
|
-
const runId = randomUUID();
|
|
14
|
-
/** @param {number} seq */
|
|
15
|
-
const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString() });
|
|
16
|
-
await store.append({
|
|
17
|
-
...envelope(0),
|
|
18
|
-
type: "run.started",
|
|
19
|
-
data: { agentId, model: request.model },
|
|
20
|
-
});
|
|
21
|
-
onStarted?.(runId);
|
|
22
|
-
|
|
23
|
-
/** @type {import("./contracts.js").ModelResult} */
|
|
24
|
-
let result;
|
|
25
|
-
try {
|
|
26
|
-
result = await provider.complete(request);
|
|
27
|
-
} catch {
|
|
28
|
-
const failed = /** @type {const} */ ({
|
|
29
|
-
...envelope(1),
|
|
30
|
-
type: "run.failed",
|
|
31
|
-
data: { message: "Model request failed." },
|
|
32
|
-
});
|
|
33
|
-
await store.append(failed);
|
|
34
|
-
return failed;
|
|
35
|
-
}
|
|
36
|
-
const completed = /** @type {const} */ ({
|
|
37
|
-
...envelope(1),
|
|
38
|
-
type: "run.completed",
|
|
39
|
-
data: { result },
|
|
40
|
-
});
|
|
41
|
-
await store.append(completed);
|
|
42
|
-
return completed;
|
|
43
|
-
}
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {{
|
|
5
|
+
* agentId: string,
|
|
6
|
+
* request: import("./contracts.js").ModelRequest,
|
|
7
|
+
* provider: import("./contracts.js").ModelProvider,
|
|
8
|
+
* store: import("./contracts.js").RunStore,
|
|
9
|
+
* onStarted?: (runId: string) => void,
|
|
10
|
+
* }} options
|
|
11
|
+
*/
|
|
12
|
+
export async function runAgent({ agentId, request, provider, store, onStarted }) {
|
|
13
|
+
const runId = randomUUID();
|
|
14
|
+
/** @param {number} seq */
|
|
15
|
+
const envelope = (seq) => ({ id: randomUUID(), run_id: runId, seq, ts: new Date().toISOString() });
|
|
16
|
+
await store.append({
|
|
17
|
+
...envelope(0),
|
|
18
|
+
type: "run.started",
|
|
19
|
+
data: { agentId, model: request.model },
|
|
20
|
+
});
|
|
21
|
+
onStarted?.(runId);
|
|
22
|
+
|
|
23
|
+
/** @type {import("./contracts.js").ModelResult} */
|
|
24
|
+
let result;
|
|
25
|
+
try {
|
|
26
|
+
result = await provider.complete(request);
|
|
27
|
+
} catch {
|
|
28
|
+
const failed = /** @type {const} */ ({
|
|
29
|
+
...envelope(1),
|
|
30
|
+
type: "run.failed",
|
|
31
|
+
data: { message: "Model request failed." },
|
|
32
|
+
});
|
|
33
|
+
await store.append(failed);
|
|
34
|
+
return failed;
|
|
35
|
+
}
|
|
36
|
+
const completed = /** @type {const} */ ({
|
|
37
|
+
...envelope(1),
|
|
38
|
+
type: "run.completed",
|
|
39
|
+
data: { result },
|
|
40
|
+
});
|
|
41
|
+
await store.append(completed);
|
|
42
|
+
return completed;
|
|
43
|
+
}
|
|
@@ -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>;
|
package/src/standalone/index.js
CHANGED
|
@@ -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";
|
|
@@ -0,0 +1,12 @@
|
|
|
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,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";
|
package/src/standalone/rag.js
CHANGED
|
@@ -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
|
+
}
|
package/src/studio/agent-ui.css
CHANGED
|
@@ -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); }
|
package/src/studio/agent-ui.js
CHANGED
|
@@ -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
|
+
}
|