openliate 0.0.1 → 0.1.5
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 +73 -241
- package/README.npm.md +128 -0
- package/dist/bin.js +24634 -42274
- package/dist/liate.js +39468 -0
- package/dist/runtime/hono.js +28061 -0
- package/dist/runtime/index.js +28061 -0
- package/hub/agents/docgyan-agent/agent.json +27 -0
- package/hub/agents/docgyan-agent/agent.ts +39 -0
- package/hub/agents/gnani-agent/agent.json +17 -0
- package/hub/agents/neon-agent/agent.json +18 -0
- package/hub/agents/prism-agent/agent.json +17 -0
- package/hub/agents/sarvam-agent/agent.json +1 -3
- package/package.json +33 -21
- package/src/cli/index.ts +346 -0
- package/src/cli/resolver.ts +153 -0
- package/src/core/aum.ts +87 -28
- package/src/core/om.ts +159 -0
- package/src/core/spec.ts +112 -0
- package/src/core/uuid.ts +5 -16
- package/src/core/version.ts +2 -0
- package/src/layers/agent/harness.ts +118 -0
- package/src/{agent → layers/agent}/loop.ts +44 -24
- package/src/layers/agent/skills.ts +302 -0
- package/src/{agent → layers/agent}/types.ts +14 -1
- package/src/{environment/environment.ts → layers/environment/sandbox.ts} +24 -5
- package/src/{environment → layers/environment}/types.ts +8 -0
- package/src/layers/integration/knowledge.ts +187 -0
- package/src/layers/integration/lib.ts +167 -0
- package/src/{integration → layers/integration}/memory.ts +49 -67
- package/src/layers/integration/repo.ts +273 -0
- package/src/{integration → layers/integration}/types.ts +60 -31
- package/src/layers/llm/model.ts +916 -0
- package/src/layers/llm/types.ts +64 -0
- package/src/{tools → layers/tools}/mcp.ts +24 -10
- package/src/layers/tools/registry.ts +307 -0
- package/src/{tools → layers/tools}/server.ts +12 -13
- package/src/{tools → layers/tools}/types.ts +3 -2
- package/src/liate.ts +64 -24
- package/src/routes/skills.ts +73 -0
- package/src/runtime/hono.ts +346 -0
- package/src/runtime/wasm.ts +23 -0
- package/src/scaffold/project.ts +188 -0
- package/dist/engine/engine.zip +0 -0
- package/dist/engine/index.js +0 -36790
- package/hub/agents/email-agent/agent.json +0 -19
- package/hub/agents/general-agent/agent.json +0 -18
- package/hub/agents/identity-agent/agent.json +0 -19
- package/hub/agents/research-agent/agent.json +0 -18
- package/hub/llm/sarvam.json +0 -27
- package/hub/mcp/agentmail.json +0 -10
- package/hub/mcp/fetch.json +0 -9
- package/hub/mcp/neon.json +0 -12
- package/hub/mcp/sarvam.json +0 -12
- package/hub/mcp/supabase.json +0 -12
- package/hub/mcp/vercel.json +0 -12
- package/src/agent/agent.ts +0 -165
- package/src/cli.ts +0 -272
- package/src/engine/types.ts +0 -104
- package/src/integration/integration.ts +0 -37
- package/src/link/index.ts +0 -317
- package/src/link/neon.ts +0 -646
- package/src/link/supabase.ts +0 -567
- package/src/link/vercel.ts +0 -633
- package/src/llm/config.ts +0 -46
- package/src/llm/hub.ts +0 -59
- package/src/llm/llm.ts +0 -60
- package/src/llm/sarvam.ts +0 -136
- package/src/server/engine.ts +0 -277
- package/src/server/index.ts +0 -32
- package/src/tools/builtin/fetch.ts +0 -66
- package/src/tools/builtin/identity.ts +0 -131
- package/src/tools/registry.ts +0 -218
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ReActLoop } from "@/layers/agent/loop";
|
|
2
|
+
import { SkillResolver } from "@/layers/agent/skills";
|
|
3
|
+
import type {
|
|
4
|
+
AgentTool,
|
|
5
|
+
AgentContext,
|
|
6
|
+
AgentRunResult,
|
|
7
|
+
AgentExecutionOptions,
|
|
8
|
+
AgentConfig
|
|
9
|
+
} from "@/layers/agent/types";
|
|
10
|
+
import type { MemoryProvider } from "@/layers/integration/types";
|
|
11
|
+
import { Session } from "@/layers/integration/memory";
|
|
12
|
+
import { LLMRouter } from "@/layers/llm/model";
|
|
13
|
+
|
|
14
|
+
export interface AgentOptions extends AgentConfig {
|
|
15
|
+
memory?: MemoryProvider | string;
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Layer [A] Agent Harness
|
|
21
|
+
* Jensen Huang's 3rd Element: The execution engine running the agent's autonomous ReAct loop.
|
|
22
|
+
*/
|
|
23
|
+
export class Agent {
|
|
24
|
+
public readonly name: string;
|
|
25
|
+
public readonly intent: string;
|
|
26
|
+
public readonly model: string;
|
|
27
|
+
public readonly maxSteps: number;
|
|
28
|
+
public readonly skills: string[];
|
|
29
|
+
private memory: MemoryProvider;
|
|
30
|
+
private tools: Map<string, AgentTool> = new Map();
|
|
31
|
+
private apiKey?: string;
|
|
32
|
+
private extraOptions: Record<string, any>;
|
|
33
|
+
|
|
34
|
+
constructor(options: AgentOptions = { name: "agent" }) {
|
|
35
|
+
this.name = options.name || "agent";
|
|
36
|
+
this.intent = options.intent || "Autonomous AI Agent";
|
|
37
|
+
this.model = options.model || "sarvam/sarvam-105b-conversations";
|
|
38
|
+
this.maxSteps = options.maxSteps ?? 10;
|
|
39
|
+
this.skills = options.skills || [];
|
|
40
|
+
this.apiKey = options.apiKey;
|
|
41
|
+
this.extraOptions = { ...(options as any) };
|
|
42
|
+
|
|
43
|
+
// Resolve Layer [I] Session Memory
|
|
44
|
+
if (!options.memory) {
|
|
45
|
+
this.memory = new Session("ephemeral");
|
|
46
|
+
} else if (typeof options.memory === "string") {
|
|
47
|
+
this.memory = new Session(options.memory);
|
|
48
|
+
} else {
|
|
49
|
+
this.memory = options.memory;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.tools) {
|
|
53
|
+
for (const t of options.tools) {
|
|
54
|
+
this.tools.set(t.name, t);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Registers a tool dynamically
|
|
61
|
+
*/
|
|
62
|
+
public addTool(tool: AgentTool): this {
|
|
63
|
+
this.tools.set(tool.name, tool);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Executes the agent on a user prompt via the autonomous ReAct reasoning loop
|
|
69
|
+
*/
|
|
70
|
+
public async run(
|
|
71
|
+
prompt: string,
|
|
72
|
+
options?: AgentExecutionOptions
|
|
73
|
+
): Promise<AgentRunResult> {
|
|
74
|
+
const skillSlugs = [...new Set([...this.skills, ...(options?.skills || [])])];
|
|
75
|
+
const resolvedSkills = skillSlugs.length > 0 ? await SkillResolver.resolveAll(skillSlugs) : [];
|
|
76
|
+
const skillPromptBlock = SkillResolver.formatSystemPrompt(resolvedSkills);
|
|
77
|
+
|
|
78
|
+
const context: AgentContext = {
|
|
79
|
+
agentName: this.name,
|
|
80
|
+
intent: this.intent + skillPromptBlock,
|
|
81
|
+
sessionId: this.memory.sessionId,
|
|
82
|
+
state: { skills: resolvedSkills.map((s) => s.slug) }
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const combinedTools = [
|
|
86
|
+
...Array.from(this.tools.values()),
|
|
87
|
+
...(options?.tools || [])
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
return ReActLoop.execute(
|
|
91
|
+
prompt,
|
|
92
|
+
LLMRouter,
|
|
93
|
+
this.memory,
|
|
94
|
+
combinedTools,
|
|
95
|
+
context,
|
|
96
|
+
{
|
|
97
|
+
...this.extraOptions,
|
|
98
|
+
model: options?.model || this.model,
|
|
99
|
+
maxSteps: options?.maxSteps ?? this.maxSteps,
|
|
100
|
+
temperature: options?.temperature,
|
|
101
|
+
systemPrompt: options?.systemPrompt
|
|
102
|
+
? options.systemPrompt + skillPromptBlock
|
|
103
|
+
: undefined,
|
|
104
|
+
apiKey: options?.apiKey || this.apiKey,
|
|
105
|
+
...(options as any)
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public getMemory(): MemoryProvider {
|
|
111
|
+
return this.memory;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Clean Aliases
|
|
116
|
+
export const Harness = Agent;
|
|
117
|
+
export const AgentHarness = Agent;
|
|
118
|
+
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AgentTool,
|
|
3
|
+
AgentContext,
|
|
4
|
+
AgentStep,
|
|
5
|
+
AgentRunResult,
|
|
6
|
+
AgentExecutionOptions,
|
|
7
|
+
ToolCall,
|
|
8
|
+
ToolResult
|
|
9
|
+
} from "@/layers/agent/types";
|
|
10
|
+
import type { MemoryProvider } from "@/layers/integration/types";
|
|
11
|
+
import type { LlmMessage, LlmChatResponse } from "@/layers/llm/model";
|
|
4
12
|
|
|
5
13
|
export interface LLMFunctionCaller {
|
|
6
|
-
chat(messages:
|
|
14
|
+
chat(messages: LlmMessage[], options?: any): Promise<LlmChatResponse & { toolCalls?: ToolCall[] }>;
|
|
7
15
|
}
|
|
8
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Layer [A] Autonomous ReAct Reasoning Loop
|
|
19
|
+
* Orchestrates: User Query -> Reason -> Tool Action -> Observation -> Final Answer
|
|
20
|
+
*/
|
|
9
21
|
export class ReActLoop {
|
|
10
22
|
public static async execute(
|
|
11
23
|
userInput: string,
|
|
@@ -18,9 +30,9 @@ export class ReActLoop {
|
|
|
18
30
|
const startTime = Date.now();
|
|
19
31
|
const maxSteps = options.maxSteps ?? 10;
|
|
20
32
|
const steps: AgentStep[] = [];
|
|
21
|
-
const toolMap = new Map<string, AgentTool>(tools.map(t => [t.name, t]));
|
|
33
|
+
const toolMap = new Map<string, AgentTool>(tools.map((t) => [t.name, t]));
|
|
22
34
|
|
|
23
|
-
const formattedTools = tools.length > 0 ? tools.map(t => ({
|
|
35
|
+
const formattedTools = tools.length > 0 ? tools.map((t) => ({
|
|
24
36
|
type: "function",
|
|
25
37
|
function: {
|
|
26
38
|
name: t.name,
|
|
@@ -39,28 +51,30 @@ export class ReActLoop {
|
|
|
39
51
|
let currentStep = 1;
|
|
40
52
|
let finalOutput = "";
|
|
41
53
|
let finalThought: string | undefined = undefined;
|
|
54
|
+
let finalAudioBase64: string | undefined = undefined;
|
|
42
55
|
let finishReason: "stop" | "max_steps_reached" | "error" = "max_steps_reached";
|
|
43
56
|
let usedModel = options.model || "unknown";
|
|
44
57
|
|
|
45
|
-
// Build system
|
|
58
|
+
// 2. Build system instruction from Intent & Name (Intent IS the system prompt)
|
|
46
59
|
const systemInstruction = options.systemPrompt ??
|
|
47
|
-
`You are ${context.agentName}
|
|
48
|
-
Your
|
|
49
|
-
Follow the ReAct methodology: Reason
|
|
60
|
+
`You are ${context.agentName}.
|
|
61
|
+
Your intent: ${context.intent || "Autonomous AI Agent"}.
|
|
62
|
+
Follow the ReAct methodology: Reason carefully, invoke tools when needed, observe results, and provide a clear final answer.`;
|
|
50
63
|
|
|
64
|
+
// 3. ReAct Step Loop
|
|
51
65
|
while (currentStep <= maxSteps) {
|
|
52
66
|
const stepStartTime = Date.now();
|
|
53
67
|
|
|
54
|
-
// Retrieve full history from
|
|
55
|
-
const conversationHistory:
|
|
56
|
-
const item:
|
|
68
|
+
// Retrieve full accumulated conversation history from Layer [I]
|
|
69
|
+
const conversationHistory: LlmMessage[] = memory.getMessages().map((m) => {
|
|
70
|
+
const item: LlmMessage = {
|
|
57
71
|
role: m.role as "system" | "user" | "assistant" | "tool",
|
|
58
72
|
content: m.content
|
|
59
73
|
};
|
|
60
74
|
if (m.name) item.name = m.name;
|
|
61
75
|
if (m.toolCallId) item.tool_call_id = m.toolCallId;
|
|
62
76
|
if (m.toolCalls && m.toolCalls.length > 0) {
|
|
63
|
-
item.tool_calls = m.toolCalls.map(tc => ({
|
|
77
|
+
item.tool_calls = m.toolCalls.map((tc) => ({
|
|
64
78
|
id: tc.id,
|
|
65
79
|
type: "function",
|
|
66
80
|
function: {
|
|
@@ -72,30 +86,34 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
72
86
|
return item;
|
|
73
87
|
});
|
|
74
88
|
|
|
75
|
-
const messages:
|
|
89
|
+
const messages: LlmMessage[] = [
|
|
76
90
|
{ role: "system", content: systemInstruction },
|
|
77
91
|
...conversationHistory
|
|
78
92
|
];
|
|
79
93
|
|
|
80
|
-
// Query
|
|
94
|
+
// Query Layer [L] Model
|
|
81
95
|
const response = await llm.chat(messages, {
|
|
96
|
+
...(options as any),
|
|
82
97
|
model: options.model,
|
|
83
98
|
maxTokens: options.maxTokens,
|
|
84
99
|
temperature: options.temperature ?? 0.2,
|
|
85
|
-
tools: formattedTools
|
|
100
|
+
tools: formattedTools,
|
|
101
|
+
apiKey: options.apiKey
|
|
86
102
|
});
|
|
87
103
|
|
|
88
104
|
usedModel = response.model || usedModel;
|
|
105
|
+
if (response.audioBase64) {
|
|
106
|
+
finalAudioBase64 = response.audioBase64;
|
|
107
|
+
}
|
|
89
108
|
const thought = response.reasoningContent;
|
|
90
109
|
if (thought) {
|
|
91
110
|
finalThought = thought;
|
|
92
111
|
}
|
|
93
112
|
|
|
94
|
-
// Check if LLM requested tool calling
|
|
95
113
|
const requestedToolCalls: ToolCall[] = response.toolCalls || [];
|
|
96
114
|
|
|
115
|
+
// Case A: Model requested tool execution
|
|
97
116
|
if (requestedToolCalls.length > 0) {
|
|
98
|
-
// Record assistant tool request in session history
|
|
99
117
|
await memory.append({
|
|
100
118
|
role: "assistant",
|
|
101
119
|
content: response.text || "",
|
|
@@ -111,7 +129,7 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
111
129
|
let resultStr: string;
|
|
112
130
|
|
|
113
131
|
if (!tool) {
|
|
114
|
-
resultStr = `Error: Tool '${tc.name}' not found. Available
|
|
132
|
+
resultStr = `Error: Tool '${tc.name}' not found. Available: ${Array.from(toolMap.keys()).join(", ")}`;
|
|
115
133
|
} else {
|
|
116
134
|
try {
|
|
117
135
|
const res = await tool.execute(tc.arguments, context);
|
|
@@ -127,7 +145,7 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
127
145
|
result: resultStr
|
|
128
146
|
});
|
|
129
147
|
|
|
130
|
-
// Append tool observation to
|
|
148
|
+
// Append tool observation to Layer [I] session memory
|
|
131
149
|
await memory.append({
|
|
132
150
|
role: "tool",
|
|
133
151
|
name: tc.name,
|
|
@@ -147,7 +165,7 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
147
165
|
|
|
148
166
|
currentStep++;
|
|
149
167
|
} else {
|
|
150
|
-
//
|
|
168
|
+
// Case B: Final text answer produced
|
|
151
169
|
finalOutput = response.text;
|
|
152
170
|
finishReason = "stop";
|
|
153
171
|
|
|
@@ -158,7 +176,7 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
158
176
|
timestamp: stepStartTime
|
|
159
177
|
});
|
|
160
178
|
|
|
161
|
-
// Append final assistant
|
|
179
|
+
// Append final assistant reply to Layer [I] session memory
|
|
162
180
|
await memory.append({
|
|
163
181
|
role: "assistant",
|
|
164
182
|
content: finalOutput,
|
|
@@ -177,7 +195,9 @@ Follow the ReAct methodology: Reason about the user's request, select tools if n
|
|
|
177
195
|
totalSteps: steps.length,
|
|
178
196
|
model: usedModel,
|
|
179
197
|
durationMs: Date.now() - startTime,
|
|
180
|
-
finishReason
|
|
198
|
+
finishReason,
|
|
199
|
+
audioBase64: finalAudioBase64
|
|
181
200
|
};
|
|
182
201
|
}
|
|
183
202
|
}
|
|
203
|
+
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// src/layers/agent/skills.ts
|
|
2
|
+
// Layer [A] Dynamic Skill Resolver (skills.sh 1.26M+ skills, GitHub, HTTPS & Local SKILL.md)
|
|
3
|
+
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, resolve as resolvePath } from "node:path";
|
|
6
|
+
|
|
7
|
+
export interface SkillSearchResult {
|
|
8
|
+
id: string;
|
|
9
|
+
source: string;
|
|
10
|
+
skillId: string;
|
|
11
|
+
name: string;
|
|
12
|
+
installs?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ResolvedSkill {
|
|
16
|
+
name: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
instructions: string;
|
|
19
|
+
source: "skills.sh" | "github" | "local" | "inline";
|
|
20
|
+
cachedAt?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type EdgeSkill = ResolvedSkill;
|
|
24
|
+
|
|
25
|
+
const skillMemoryCache = new Map<string, ResolvedSkill>();
|
|
26
|
+
|
|
27
|
+
export class SkillResolver {
|
|
28
|
+
/**
|
|
29
|
+
* Dynamically fetch and resolve a skills.sh slug, GitHub reference, HTTPS URL, or local SKILL.md path.
|
|
30
|
+
*/
|
|
31
|
+
public static async resolve(slugOrUrl: string): Promise<ResolvedSkill> {
|
|
32
|
+
const cleanSlug = slugOrUrl.trim();
|
|
33
|
+
|
|
34
|
+
if (skillMemoryCache.has(cleanSlug)) {
|
|
35
|
+
return skillMemoryCache.get(cleanSlug)!;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 1. Local file path fallback
|
|
39
|
+
if (
|
|
40
|
+
cleanSlug.startsWith("./") ||
|
|
41
|
+
cleanSlug.startsWith("../") ||
|
|
42
|
+
cleanSlug.startsWith("/") ||
|
|
43
|
+
cleanSlug.endsWith(".md")
|
|
44
|
+
) {
|
|
45
|
+
const fullPath = resolvePath(process.cwd(), cleanSlug);
|
|
46
|
+
if (existsSync(fullPath)) {
|
|
47
|
+
const text = readFileSync(fullPath, "utf-8");
|
|
48
|
+
const skill: ResolvedSkill = {
|
|
49
|
+
name: cleanSlug.split(/[\\/]/).pop()?.replace(/\.md$/i, "") || "local-skill",
|
|
50
|
+
slug: cleanSlug,
|
|
51
|
+
instructions: text,
|
|
52
|
+
source: "local",
|
|
53
|
+
cachedAt: Date.now(),
|
|
54
|
+
};
|
|
55
|
+
skillMemoryCache.set(cleanSlug, skill);
|
|
56
|
+
return skill;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 2. Direct HTTPS URL
|
|
61
|
+
if (cleanSlug.startsWith("http://") || cleanSlug.startsWith("https://")) {
|
|
62
|
+
try {
|
|
63
|
+
const res = await fetch(cleanSlug, { signal: AbortSignal.timeout(6000) });
|
|
64
|
+
if (res.ok) {
|
|
65
|
+
const text = await res.text();
|
|
66
|
+
const skill: ResolvedSkill = {
|
|
67
|
+
name: cleanSlug.split("/").pop()?.replace(/\.md$/i, "") || "remote-skill",
|
|
68
|
+
slug: cleanSlug,
|
|
69
|
+
instructions: text,
|
|
70
|
+
source: "skills.sh",
|
|
71
|
+
cachedAt: Date.now(),
|
|
72
|
+
};
|
|
73
|
+
skillMemoryCache.set(cleanSlug, skill);
|
|
74
|
+
return skill;
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
// Continue to fallback
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 3. skills.sh / GitHub slug (e.g. "vercel-labs/find-skills" or "skills.sh/vercel-labs/find-skills")
|
|
82
|
+
const id = cleanSlug.replace(/^skills\.sh\//, "").replace(/^github:/, "");
|
|
83
|
+
const idParts = id.split("/").filter(Boolean);
|
|
84
|
+
|
|
85
|
+
if (idParts.length >= 2) {
|
|
86
|
+
// 3a. skills.sh API
|
|
87
|
+
try {
|
|
88
|
+
const apiUrl = `https://skills.sh/api/v1/skills/${id}`;
|
|
89
|
+
const res = await fetch(apiUrl, { signal: AbortSignal.timeout(6000) });
|
|
90
|
+
if (res.ok) {
|
|
91
|
+
const data: any = await res.json();
|
|
92
|
+
const skillFile =
|
|
93
|
+
data.files?.find((f: any) => f.path === "SKILL.md" || f.path?.endsWith(".md")) ||
|
|
94
|
+
data.files?.[0];
|
|
95
|
+
const contents = skillFile?.contents || data.instructions || data.content;
|
|
96
|
+
if (contents) {
|
|
97
|
+
const skill: ResolvedSkill = {
|
|
98
|
+
name: idParts.slice(1).join("-"),
|
|
99
|
+
slug: id,
|
|
100
|
+
instructions: contents,
|
|
101
|
+
source: "skills.sh",
|
|
102
|
+
cachedAt: Date.now(),
|
|
103
|
+
};
|
|
104
|
+
skillMemoryCache.set(cleanSlug, skill);
|
|
105
|
+
return skill;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
// Fallback to GitHub raw
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 3b. GitHub Raw common paths
|
|
113
|
+
const owner = idParts[0];
|
|
114
|
+
const repo = idParts[1];
|
|
115
|
+
const targetSkill = idParts.slice(2).join("/") || repo;
|
|
116
|
+
|
|
117
|
+
const candidateUrls = [
|
|
118
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/skills/${targetSkill}/SKILL.md`,
|
|
119
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/${targetSkill}/SKILL.md`,
|
|
120
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/skills/productivity/${targetSkill}/SKILL.md`,
|
|
121
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/skills/engineering/${targetSkill}/SKILL.md`,
|
|
122
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/skills/design/${targetSkill}/SKILL.md`,
|
|
123
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/skills/${repo}/SKILL.md`,
|
|
124
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/main/SKILL.md`,
|
|
125
|
+
`https://raw.githubusercontent.com/${owner}/${repo}/master/SKILL.md`,
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
for (const url of candidateUrls) {
|
|
129
|
+
try {
|
|
130
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
|
|
131
|
+
if (res.ok) {
|
|
132
|
+
const text = await res.text();
|
|
133
|
+
if (text && !text.includes("404: Not Found")) {
|
|
134
|
+
const skill: ResolvedSkill = {
|
|
135
|
+
name: targetSkill || `${owner}/${repo}`,
|
|
136
|
+
slug: id,
|
|
137
|
+
instructions: text,
|
|
138
|
+
source: "github",
|
|
139
|
+
cachedAt: Date.now(),
|
|
140
|
+
};
|
|
141
|
+
skillMemoryCache.set(cleanSlug, skill);
|
|
142
|
+
return skill;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// Try next candidate
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 3c. Dynamic GitHub Tree discovery
|
|
151
|
+
try {
|
|
152
|
+
const treeRes = await fetch(
|
|
153
|
+
`https://api.github.com/repos/${owner}/${repo}/git/trees/main?recursive=1`,
|
|
154
|
+
{
|
|
155
|
+
headers: { "User-Agent": "OpenLiate" },
|
|
156
|
+
signal: AbortSignal.timeout(6000),
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
if (treeRes.ok) {
|
|
160
|
+
const treeData: any = await treeRes.json();
|
|
161
|
+
const shortTarget = targetSkill.replace(/^[a-z0-9]+-/i, "").toLowerCase();
|
|
162
|
+
const matchedPath = treeData.tree?.find((item: any) => {
|
|
163
|
+
const p = String(item.path || "").toLowerCase();
|
|
164
|
+
const isSkill = p.endsWith("skill.md") || p.endsWith("skill");
|
|
165
|
+
return (
|
|
166
|
+
isSkill &&
|
|
167
|
+
(p.includes(targetSkill.toLowerCase()) ||
|
|
168
|
+
(shortTarget.length > 4 && p.includes(shortTarget)))
|
|
169
|
+
);
|
|
170
|
+
})?.path;
|
|
171
|
+
|
|
172
|
+
if (matchedPath) {
|
|
173
|
+
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/main/${matchedPath}`;
|
|
174
|
+
const fileRes = await fetch(rawUrl, { signal: AbortSignal.timeout(5000) });
|
|
175
|
+
if (fileRes.ok) {
|
|
176
|
+
const text = await fileRes.text();
|
|
177
|
+
const skill: ResolvedSkill = {
|
|
178
|
+
name: targetSkill || `${owner}/${repo}`,
|
|
179
|
+
slug: id,
|
|
180
|
+
instructions: text,
|
|
181
|
+
source: "github",
|
|
182
|
+
cachedAt: Date.now(),
|
|
183
|
+
};
|
|
184
|
+
skillMemoryCache.set(cleanSlug, skill);
|
|
185
|
+
return skill;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} catch {
|
|
190
|
+
// Fallback to inline slug
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const resolvedName =
|
|
195
|
+
idParts[idParts.length - 1] || cleanSlug.split("/").pop()?.replace(/\.md$/i, "") || "skill";
|
|
196
|
+
return {
|
|
197
|
+
name: resolvedName,
|
|
198
|
+
slug: cleanSlug,
|
|
199
|
+
instructions: cleanSlug,
|
|
200
|
+
source: "inline",
|
|
201
|
+
cachedAt: Date.now(),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public static async resolveAll(skills: string[]): Promise<ResolvedSkill[]> {
|
|
206
|
+
if (!skills || skills.length === 0) return [];
|
|
207
|
+
return Promise.all(skills.map((s) => this.resolve(s)));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public static formatSystemPrompt(skills: ResolvedSkill[]): string {
|
|
211
|
+
if (!skills || skills.length === 0) return "";
|
|
212
|
+
const blocks = skills.map(
|
|
213
|
+
(s) => `### Skill: ${s.name} (${s.source}: ${s.slug})\n${s.instructions.trim()}`
|
|
214
|
+
);
|
|
215
|
+
return `\n\n<skills>\n${blocks.join("\n\n")}\n</skills>`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Search the public skills.sh registry (Algolia-backed, no auth required).
|
|
220
|
+
*/
|
|
221
|
+
public static async search(query: string, limit = 10): Promise<SkillSearchResult[]> {
|
|
222
|
+
const q = query.trim();
|
|
223
|
+
if (!q) return [];
|
|
224
|
+
const url = `https://skills.sh/api/search?q=${encodeURIComponent(q)}&limit=${Math.min(Math.max(limit, 1), 25)}`;
|
|
225
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(6000) });
|
|
226
|
+
if (!res.ok) {
|
|
227
|
+
throw new Error(`skills.sh search failed (${res.status})`);
|
|
228
|
+
}
|
|
229
|
+
const data = (await res.json()) as { skills?: SkillSearchResult[] };
|
|
230
|
+
return (data.skills || []).slice(0, limit);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Resolve a skill from skills.sh/GitHub, save SKILL.md to .liate/skills/, and add to agent.json A.skills.
|
|
235
|
+
*/
|
|
236
|
+
public static async add(
|
|
237
|
+
slugOrUrl: string,
|
|
238
|
+
options: { cwd?: string; agentFile?: string } = {}
|
|
239
|
+
): Promise<{ skill: ResolvedSkill; savedPath: string; updatedAgentJson: boolean }> {
|
|
240
|
+
const cwd = options.cwd || process.cwd();
|
|
241
|
+
const skill = await this.resolve(slugOrUrl);
|
|
242
|
+
if (skill.source === "inline") {
|
|
243
|
+
throw new Error(`Could not fetch SKILL.md for '${slugOrUrl}' from skills.sh or GitHub.`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const safeSlug = skill.slug.replace(/[^a-zA-Z0-9_/-]/g, "-").replace(/^\/+|\/+$/g, "");
|
|
247
|
+
const savedPath = resolvePath(cwd, ".liate", "skills", safeSlug, "SKILL.md");
|
|
248
|
+
mkdirSync(dirname(savedPath), { recursive: true });
|
|
249
|
+
writeFileSync(savedPath, skill.instructions, "utf-8");
|
|
250
|
+
|
|
251
|
+
let updatedAgentJson = false;
|
|
252
|
+
const agentPath = resolvePath(cwd, options.agentFile || "agent.json");
|
|
253
|
+
if (existsSync(agentPath)) {
|
|
254
|
+
const raw = JSON.parse(readFileSync(agentPath, "utf-8"));
|
|
255
|
+
const aKey = raw.A ? "A" : raw.Agent ? "Agent" : raw.agent ? "agent" : "A";
|
|
256
|
+
raw[aKey] = typeof raw[aKey] === "object" && raw[aKey] ? raw[aKey] : { name: String(raw[aKey] || "agent") };
|
|
257
|
+
const existing: string[] = Array.isArray(raw[aKey].skills) ? raw[aKey].skills : [];
|
|
258
|
+
if (!existing.includes(slugOrUrl)) {
|
|
259
|
+
raw[aKey].skills = [...existing, slugOrUrl];
|
|
260
|
+
writeFileSync(agentPath, JSON.stringify(raw, null, 2) + "\n", "utf-8");
|
|
261
|
+
updatedAgentJson = true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return { skill, savedPath, updatedAgentJson };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Refresh all skills listed in agent.json from upstream GitHub / HTTPS sources.
|
|
270
|
+
*/
|
|
271
|
+
public static async update(
|
|
272
|
+
options: { cwd?: string; agentFile?: string } = {}
|
|
273
|
+
): Promise<{ updated: { slug: string; source: string; bytes: number }[] }> {
|
|
274
|
+
const cwd = options.cwd || process.cwd();
|
|
275
|
+
const agentPath = resolvePath(cwd, options.agentFile || "agent.json");
|
|
276
|
+
if (!existsSync(agentPath)) {
|
|
277
|
+
return { updated: [] };
|
|
278
|
+
}
|
|
279
|
+
const raw = JSON.parse(readFileSync(agentPath, "utf-8"));
|
|
280
|
+
const aObj = raw.A || raw.Agent || raw.agent || {};
|
|
281
|
+
const slugs: string[] = Array.isArray(aObj.skills) ? aObj.skills : [];
|
|
282
|
+
|
|
283
|
+
this.clearCache();
|
|
284
|
+
const updated: { slug: string; source: string; bytes: number }[] = [];
|
|
285
|
+
for (const slug of slugs) {
|
|
286
|
+
const { skill } = await this.add(slug, { cwd, agentFile: options.agentFile });
|
|
287
|
+
updated.push({ slug, source: skill.source, bytes: skill.instructions.length });
|
|
288
|
+
}
|
|
289
|
+
return { updated };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public static listCached(): ResolvedSkill[] {
|
|
293
|
+
return Array.from(skillMemoryCache.values());
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public static clearCache(): void {
|
|
297
|
+
skillMemoryCache.clear();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export const EdgeSkillResolver = SkillResolver;
|
|
302
|
+
|
|
@@ -19,7 +19,7 @@ export interface AgentTool {
|
|
|
19
19
|
|
|
20
20
|
export interface AgentContext {
|
|
21
21
|
agentName: string;
|
|
22
|
-
|
|
22
|
+
intent: string;
|
|
23
23
|
sessionId?: string;
|
|
24
24
|
state: Record<string, any>;
|
|
25
25
|
}
|
|
@@ -41,6 +41,7 @@ export interface AgentRunResult {
|
|
|
41
41
|
model: string;
|
|
42
42
|
durationMs: number;
|
|
43
43
|
finishReason: "stop" | "max_steps_reached" | "error";
|
|
44
|
+
audioBase64?: string;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export interface AgentExecutionOptions {
|
|
@@ -50,4 +51,16 @@ export interface AgentExecutionOptions {
|
|
|
50
51
|
systemPrompt?: string;
|
|
51
52
|
temperature?: number;
|
|
52
53
|
tools?: AgentTool[];
|
|
54
|
+
skills?: string[];
|
|
55
|
+
apiKey?: string;
|
|
53
56
|
}
|
|
57
|
+
|
|
58
|
+
export interface AgentConfig {
|
|
59
|
+
name: string;
|
|
60
|
+
intent?: string;
|
|
61
|
+
model?: string;
|
|
62
|
+
maxSteps?: number;
|
|
63
|
+
tools?: AgentTool[];
|
|
64
|
+
skills?: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
@@ -1,21 +1,40 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import os from "os";
|
|
4
|
-
import type { SandboxConfig } from "
|
|
4
|
+
import type { SandboxConfig } from "@/layers/environment/types";
|
|
5
5
|
|
|
6
6
|
export class EnvironmentResolver {
|
|
7
7
|
/**
|
|
8
|
-
* Automatically loads .env and .env.local files from cwd,
|
|
8
|
+
* Automatically loads .env and .env.local files from cwd, module dir, parent dirs, and home dir
|
|
9
9
|
*/
|
|
10
10
|
public static loadEnv(targetPath?: string): void {
|
|
11
|
+
// 1. Load keys from ~/.liate/config.json if available
|
|
12
|
+
try {
|
|
13
|
+
const configPath = path.resolve(os.homedir(), ".liate", "config.json");
|
|
14
|
+
if (fs.existsSync(configPath)) {
|
|
15
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
16
|
+
const parsed = JSON.parse(raw);
|
|
17
|
+
if (parsed.keys && typeof parsed.keys === "object") {
|
|
18
|
+
for (const [k, v] of Object.entries(parsed.keys)) {
|
|
19
|
+
if (!process.env[k]) {
|
|
20
|
+
process.env[k] = String(v);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
} catch {}
|
|
26
|
+
|
|
27
|
+
// 2. Load .env files from candidate locations
|
|
11
28
|
const candidates = [
|
|
12
29
|
path.resolve(process.cwd(), ".env"),
|
|
13
30
|
path.resolve(process.cwd(), ".env.local"),
|
|
31
|
+
path.resolve(process.cwd(), ".liate", ".env"),
|
|
14
32
|
path.resolve(process.cwd(), "..", ".env"),
|
|
15
33
|
path.resolve(process.cwd(), "..", ".env.local"),
|
|
16
34
|
targetPath ? path.resolve(path.dirname(targetPath), ".env") : "",
|
|
17
35
|
targetPath ? path.resolve(path.dirname(targetPath), ".env.local") : "",
|
|
18
36
|
path.resolve(os.homedir(), ".liate", ".env"),
|
|
37
|
+
path.resolve(os.homedir(), ".liate", "config.env"),
|
|
19
38
|
path.resolve(os.homedir(), ".env")
|
|
20
39
|
].filter(Boolean);
|
|
21
40
|
|
|
@@ -40,7 +59,7 @@ export class EnvironmentResolver {
|
|
|
40
59
|
* Expands variable references (e.g. "$API_KEY" -> process.env.API_KEY)
|
|
41
60
|
*/
|
|
42
61
|
public static resolve(
|
|
43
|
-
declaredEnv: Record<string, string>,
|
|
62
|
+
declaredEnv: Record<string, string | undefined>,
|
|
44
63
|
systemEnv: Record<string, string | undefined> = process.env
|
|
45
64
|
): Record<string, string> {
|
|
46
65
|
const resolved: Record<string, string> = {};
|
|
@@ -73,13 +92,13 @@ export class EnvironmentResolver {
|
|
|
73
92
|
* Constructs an isolated sandbox configuration
|
|
74
93
|
*/
|
|
75
94
|
public static createSandbox(
|
|
76
|
-
env: Record<string, string>,
|
|
95
|
+
env: Record<string, string | undefined>,
|
|
77
96
|
options: Partial<SandboxConfig> = {}
|
|
78
97
|
): SandboxConfig {
|
|
79
98
|
const resolvedEnv = this.resolve(env);
|
|
80
99
|
|
|
81
100
|
return {
|
|
82
|
-
allowedDomains: options.allowedDomains || [
|
|
101
|
+
allowedDomains: options.allowedDomains || [],
|
|
83
102
|
denyNetwork: options.denyNetwork ?? false,
|
|
84
103
|
timeoutMs: options.timeoutMs ?? 30000,
|
|
85
104
|
env: resolvedEnv
|