@openliate/liate 0.0.0-stage → 0.1.6
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 -0
- package/README.md +127 -2
- package/README.npm.md +128 -0
- package/dist/bin.js +28745 -0
- package/dist/liate.js +39479 -0
- package/dist/runtime/hono.js +28072 -0
- package/dist/runtime/index.js +28072 -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 +22 -0
- package/package.json +71 -4
- package/src/cli/index.ts +346 -0
- package/src/cli/resolver.ts +153 -0
- package/src/core/aum.ts +137 -0
- package/src/core/om.ts +159 -0
- package/src/core/spec.ts +112 -0
- package/src/core/uuid.ts +8 -0
- package/src/core/version.ts +2 -0
- package/src/layers/agent/harness.ts +118 -0
- package/src/layers/agent/loop.ts +203 -0
- package/src/layers/agent/skills.ts +302 -0
- package/src/layers/agent/types.ts +66 -0
- package/src/layers/environment/sandbox.ts +107 -0
- package/src/layers/environment/types.ts +23 -0
- package/src/layers/integration/knowledge.ts +187 -0
- package/src/layers/integration/lib.ts +167 -0
- package/src/layers/integration/memory.ts +135 -0
- package/src/layers/integration/repo.ts +273 -0
- package/src/layers/integration/types.ts +60 -0
- package/src/layers/llm/model.ts +928 -0
- package/src/layers/llm/types.ts +64 -0
- package/src/layers/tools/mcp.ts +236 -0
- package/src/layers/tools/registry.ts +307 -0
- package/src/layers/tools/server.ts +69 -0
- package/src/layers/tools/types.ts +38 -0
- package/src/liate.ts +65 -0
- 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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AgentContext } from "@/layers/agent/types";
|
|
2
|
+
|
|
3
|
+
export interface LlmToolSchema {
|
|
4
|
+
type: "function";
|
|
5
|
+
function: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface McpServerConfig {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
version?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
transport?: "stdio" | "sse" | "http";
|
|
18
|
+
command?: string;
|
|
19
|
+
args?: string[];
|
|
20
|
+
url?: string;
|
|
21
|
+
env?: Record<string, string>;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ToolExecutorResult {
|
|
26
|
+
toolName: string;
|
|
27
|
+
result: string;
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ParsedToolSpec {
|
|
32
|
+
raw: string;
|
|
33
|
+
isMcp: boolean;
|
|
34
|
+
isBuiltin?: boolean;
|
|
35
|
+
serverName?: string;
|
|
36
|
+
selectedTools?: string[];
|
|
37
|
+
}
|
|
38
|
+
|
package/src/liate.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liate — Open Source AI Agents Framework
|
|
3
|
+
* Built for Sovereign AI Agents From India to the World.
|
|
4
|
+
*
|
|
5
|
+
* Universal Framework Entrypoint & SDK Exports
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { liate } from "@openliate/liate";
|
|
9
|
+
* class MyAgent extends liate { L; I; A; T; E; }
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// 1. The 5 Layers (L · I · A · T · E)
|
|
13
|
+
export * from "@/layers/llm/model";
|
|
14
|
+
export * from "@/layers/integration/memory";
|
|
15
|
+
export * from "@/layers/integration/knowledge";
|
|
16
|
+
export * from "@/layers/integration/repo";
|
|
17
|
+
export * from "@/layers/integration/lib";
|
|
18
|
+
export * from "@/layers/agent/harness";
|
|
19
|
+
export * from "@/layers/agent/loop";
|
|
20
|
+
export * from "@/layers/agent/skills";
|
|
21
|
+
export * from "@/layers/agent/types";
|
|
22
|
+
export * from "@/layers/tools/mcp";
|
|
23
|
+
export * from "@/layers/tools/server";
|
|
24
|
+
export * from "@/layers/tools/registry";
|
|
25
|
+
export * from "@/layers/environment/sandbox";
|
|
26
|
+
export * from "@/layers/environment/types";
|
|
27
|
+
|
|
28
|
+
// Canonical exports to resolve cross-layer duplicates
|
|
29
|
+
export type { AgentTool, ToolCall } from "@/layers/agent/types";
|
|
30
|
+
|
|
31
|
+
// 2. Core Specification, AUM & OM Engine + Scaffolder
|
|
32
|
+
export * from "@/core/spec";
|
|
33
|
+
export * from "@/core/aum";
|
|
34
|
+
export * from "@/core/om";
|
|
35
|
+
export * from "@/core/version";
|
|
36
|
+
export * from "@/core/uuid";
|
|
37
|
+
export * from "@/scaffold/project";
|
|
38
|
+
|
|
39
|
+
// 3. Default Export: The universal base class
|
|
40
|
+
import { liate } from "@/core/om";
|
|
41
|
+
export default liate;
|
|
42
|
+
|
|
43
|
+
// 4. CLI Direct Execution Entrypoint (only if run directly as script)
|
|
44
|
+
if (typeof import.meta !== "undefined" && import.meta.main && process.argv[1] && (process.argv[1].endsWith("liate.ts") || process.argv[1].endsWith("liate.js"))) {
|
|
45
|
+
let rawArgs = process.argv.slice(2);
|
|
46
|
+
if (rawArgs[0] === "run") {
|
|
47
|
+
rawArgs = rawArgs.slice(1);
|
|
48
|
+
}
|
|
49
|
+
const targetFile = rawArgs[0] && !rawArgs[0].startsWith("-") ? rawArgs[0] : "agent.json";
|
|
50
|
+
const prompt = (rawArgs[0] && !rawArgs[0].startsWith("-") ? rawArgs.slice(1) : rawArgs).join(" ") || "Hello! Confirm you are running pure Liate.";
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const agent = await liate.load(targetFile);
|
|
54
|
+
console.log(`[Liate] Running ${targetFile} (Agent: ${agent.A?.name || "Agent"})...`);
|
|
55
|
+
console.log(`[Prompt] "${prompt}"\n`);
|
|
56
|
+
const result = await agent.run(prompt);
|
|
57
|
+
console.log(`[Response]\n${result.text}\n`);
|
|
58
|
+
console.log(`[Stats] Steps: ${result.totalSteps} | Duration: ${result.durationMs}ms | Finish: ${result.finishReason}`);
|
|
59
|
+
await agent.close();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
} catch (err: any) {
|
|
62
|
+
console.error(`[Liate Error] ${err.message}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/routes/skills.ts
|
|
2
|
+
// HTTP endpoints for skills.sh search, listing cached skills, and resolving SKILL.md
|
|
3
|
+
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { SkillResolver } from "@/layers/agent/skills";
|
|
6
|
+
|
|
7
|
+
export const skillsRouter = new Hono();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* GET /skills
|
|
11
|
+
* List all cached skills
|
|
12
|
+
*/
|
|
13
|
+
skillsRouter.get("/", (c) => {
|
|
14
|
+
const cached = SkillResolver.listCached();
|
|
15
|
+
return c.json({
|
|
16
|
+
status: "ok",
|
|
17
|
+
count: cached.length,
|
|
18
|
+
skills: cached.map((s) => ({
|
|
19
|
+
name: s.name,
|
|
20
|
+
slug: s.slug,
|
|
21
|
+
source: s.source,
|
|
22
|
+
cachedAt: s.cachedAt,
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* GET /skills/search?q=react&limit=10
|
|
29
|
+
* Search public skills.sh registry
|
|
30
|
+
*/
|
|
31
|
+
skillsRouter.get("/search", async (c) => {
|
|
32
|
+
const q = c.req.query("q") || "";
|
|
33
|
+
const limit = Number(c.req.query("limit") || 10);
|
|
34
|
+
if (!q.trim()) {
|
|
35
|
+
return c.json({ error: "Missing query parameter 'q'" }, 400);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const skills = await SkillResolver.search(q, Number.isFinite(limit) ? limit : 10);
|
|
39
|
+
return c.json({ status: "ok", query: q, count: skills.length, skills });
|
|
40
|
+
} catch (err: any) {
|
|
41
|
+
return c.json({ error: err.message }, 502);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* POST /skills/resolve
|
|
47
|
+
* Resolve a skills.sh slug, GitHub reference, or HTTPS URL
|
|
48
|
+
*/
|
|
49
|
+
skillsRouter.post("/resolve", async (c) => {
|
|
50
|
+
const body = await c.req.json().catch(() => ({}));
|
|
51
|
+
const slug = body.slug || body.url || body.skill;
|
|
52
|
+
|
|
53
|
+
if (!slug) {
|
|
54
|
+
return c.json({ error: "Missing skill slug or URL in request body." }, 400);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const resolved = await SkillResolver.resolve(slug);
|
|
59
|
+
return c.json({
|
|
60
|
+
status: "ok",
|
|
61
|
+
resolved: {
|
|
62
|
+
name: resolved.name,
|
|
63
|
+
slug: resolved.slug,
|
|
64
|
+
source: resolved.source,
|
|
65
|
+
bytes: resolved.instructions.length,
|
|
66
|
+
instructionsPreview: resolved.instructions.slice(0, 300),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
} catch (err: any) {
|
|
70
|
+
return c.json({ error: err.message }, 500);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// src/runtime/hono.ts
|
|
2
|
+
// Liate v0.0.7 — Edge Runtime Server
|
|
3
|
+
// Endpoints: /health, /run, /chat, /stream
|
|
4
|
+
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { cors } from "hono/cors";
|
|
7
|
+
import { logger } from "hono/logger";
|
|
8
|
+
import { streamSSE } from "hono/streaming";
|
|
9
|
+
import { liate } from "@/core/om";
|
|
10
|
+
import { VERSION } from "@/core/version";
|
|
11
|
+
import { Session } from "@/layers/integration/memory";
|
|
12
|
+
import { LLMRouter } from "@/layers/llm/model";
|
|
13
|
+
import { skillsRouter } from "@/routes/skills";
|
|
14
|
+
import { listLocalHubAgents } from "@/cli/resolver";
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { resolve, join } from "node:path";
|
|
17
|
+
|
|
18
|
+
export const app = new Hono();
|
|
19
|
+
|
|
20
|
+
// Global Middleware
|
|
21
|
+
app.use("*", cors());
|
|
22
|
+
app.use("*", logger());
|
|
23
|
+
app.route("/skills", skillsRouter);
|
|
24
|
+
|
|
25
|
+
// Active agent and session cache
|
|
26
|
+
let activeAgent: liate | null = null;
|
|
27
|
+
const activeSessions = new Map<string, Session>();
|
|
28
|
+
const defaultSpecPath = resolve(process.cwd(), "agent.json");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolves or lazily loads the target agent
|
|
32
|
+
*/
|
|
33
|
+
async function getOrLoadAgent(customSpec?: any, customPath?: string): Promise<liate> {
|
|
34
|
+
if (customSpec) {
|
|
35
|
+
return liate.from(customSpec);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const targetPath = customPath ? resolve(process.cwd(), customPath) : defaultSpecPath;
|
|
39
|
+
|
|
40
|
+
if (activeAgent && !customPath) {
|
|
41
|
+
return activeAgent;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (existsSync(targetPath)) {
|
|
45
|
+
const loaded = await liate.load(targetPath);
|
|
46
|
+
if (!customPath) {
|
|
47
|
+
activeAgent = loaded;
|
|
48
|
+
}
|
|
49
|
+
return loaded;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Ephemeral fallback agent if no agent.json is present
|
|
53
|
+
return liate.from({
|
|
54
|
+
L: "sarvam/sarvam-105b-conversations",
|
|
55
|
+
A: { name: "liate-edge-agent", intent: "Sovereign Indic Edge Agent Runtime" },
|
|
56
|
+
E: { SARVAM_API_KEY: "$SARVAM_API_KEY" }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 1. GET /health
|
|
62
|
+
* Fast liveness probe: uptime, memory, and engine readiness
|
|
63
|
+
*/
|
|
64
|
+
app.get("/health", (c) => {
|
|
65
|
+
const mem = typeof process !== "undefined" && process.memoryUsage ? process.memoryUsage() : null;
|
|
66
|
+
return c.json({
|
|
67
|
+
status: "ok",
|
|
68
|
+
framework: "Liate",
|
|
69
|
+
version: VERSION,
|
|
70
|
+
uptimeSeconds: Math.floor(process.uptime()),
|
|
71
|
+
timestamp: new Date().toISOString(),
|
|
72
|
+
memory: mem ? {
|
|
73
|
+
heapUsedMb: Math.round(mem.heapUsed / 1024 / 1024),
|
|
74
|
+
rssMb: Math.round(mem.rss / 1024 / 1024)
|
|
75
|
+
} : undefined
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* GET /models, /v1/models, /api/v1/models
|
|
81
|
+
* Live dynamic model discovery from Sarvam AI, Neon AI Gateway, and Gnani AI.
|
|
82
|
+
* Zero hardcoded models.
|
|
83
|
+
*/
|
|
84
|
+
const handleGetModels = async (c: any) => {
|
|
85
|
+
const provider = c.req.query("provider");
|
|
86
|
+
const models = await LLMRouter.listModels(provider);
|
|
87
|
+
return c.json({
|
|
88
|
+
object: "list",
|
|
89
|
+
data: models
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
app.get("/models", handleGetModels);
|
|
94
|
+
app.get("/v1/models", handleGetModels);
|
|
95
|
+
app.get("/api/v1/models", handleGetModels);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* GET /hub & GET /hub/agents
|
|
99
|
+
* Lists all sovereign agent templates in the local agent hub
|
|
100
|
+
*/
|
|
101
|
+
app.get("/hub", (c) => {
|
|
102
|
+
const agents = listLocalHubAgents();
|
|
103
|
+
return c.json({
|
|
104
|
+
success: true,
|
|
105
|
+
count: agents.length,
|
|
106
|
+
agents
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
app.get("/hub/agents", (c) => {
|
|
111
|
+
const agents = listLocalHubAgents();
|
|
112
|
+
return c.json({
|
|
113
|
+
success: true,
|
|
114
|
+
count: agents.length,
|
|
115
|
+
agents
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* GET /hub/agents/:id
|
|
121
|
+
* Retrieves the full specification of a local hub agent template
|
|
122
|
+
*/
|
|
123
|
+
app.get("/hub/agents/:id", (c) => {
|
|
124
|
+
const id = c.req.param("id");
|
|
125
|
+
const hubCandidate = resolve(process.cwd(), "hub", "agents", id, "agent.json");
|
|
126
|
+
|
|
127
|
+
if (!existsSync(hubCandidate)) {
|
|
128
|
+
return c.json({
|
|
129
|
+
success: false,
|
|
130
|
+
error: `Hub agent '${id}' not found`
|
|
131
|
+
}, 404);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const raw = JSON.parse(readFileSync(hubCandidate, "utf-8"));
|
|
136
|
+
return c.json({
|
|
137
|
+
success: true,
|
|
138
|
+
id,
|
|
139
|
+
spec: raw
|
|
140
|
+
});
|
|
141
|
+
} catch (err: any) {
|
|
142
|
+
return c.json({
|
|
143
|
+
success: false,
|
|
144
|
+
error: `Failed to parse agent spec for '${id}': ${err.message}`
|
|
145
|
+
}, 500);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 2. POST /run
|
|
151
|
+
* Standard single-shot autonomous agent invocation
|
|
152
|
+
* Body: { input: string, spec?: any, path?: string, options?: any }
|
|
153
|
+
*/
|
|
154
|
+
app.post("/run", async (c) => {
|
|
155
|
+
const start = Date.now();
|
|
156
|
+
try {
|
|
157
|
+
const body = await c.req.json();
|
|
158
|
+
const input = body.input;
|
|
159
|
+
|
|
160
|
+
if (!input || typeof input !== "string") {
|
|
161
|
+
return c.json({
|
|
162
|
+
success: false,
|
|
163
|
+
error: "Missing or invalid 'input' parameter in request body"
|
|
164
|
+
}, 400);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const agent = await getOrLoadAgent(body.spec, body.path);
|
|
168
|
+
const result = await agent.run(input, body.options);
|
|
169
|
+
|
|
170
|
+
return c.json({
|
|
171
|
+
success: true,
|
|
172
|
+
output: result.text,
|
|
173
|
+
thought: result.thought,
|
|
174
|
+
steps: result.steps,
|
|
175
|
+
totalSteps: result.totalSteps,
|
|
176
|
+
model: result.model,
|
|
177
|
+
durationMs: Date.now() - start
|
|
178
|
+
});
|
|
179
|
+
} catch (err: any) {
|
|
180
|
+
return c.json({
|
|
181
|
+
success: false,
|
|
182
|
+
error: err.message || "Agent execution failed",
|
|
183
|
+
durationMs: Date.now() - start
|
|
184
|
+
}, 500);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 3. POST /chat
|
|
190
|
+
* Multi-turn conversational endpoint preserving session memory
|
|
191
|
+
* Body: { message: string, sessionId?: string, spec?: any, path?: string }
|
|
192
|
+
*/
|
|
193
|
+
app.post("/chat", async (c) => {
|
|
194
|
+
const start = Date.now();
|
|
195
|
+
try {
|
|
196
|
+
const body = await c.req.json();
|
|
197
|
+
const message = body.message || body.input;
|
|
198
|
+
const sessionId = body.sessionId || "default-session";
|
|
199
|
+
|
|
200
|
+
if (!message || typeof message !== "string") {
|
|
201
|
+
return c.json({
|
|
202
|
+
success: false,
|
|
203
|
+
error: "Missing or invalid 'message' parameter in request body"
|
|
204
|
+
}, 400);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Retrieve or initialize session memory
|
|
208
|
+
let memory = activeSessions.get(sessionId);
|
|
209
|
+
if (!memory) {
|
|
210
|
+
memory = new Session(sessionId);
|
|
211
|
+
activeSessions.set(sessionId, memory);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const agent = await getOrLoadAgent(body.spec, body.path);
|
|
215
|
+
const runner = await agent.getRunner();
|
|
216
|
+
|
|
217
|
+
// Attach session memory for multi-turn history
|
|
218
|
+
(runner as any).memory = memory;
|
|
219
|
+
|
|
220
|
+
const result = await agent.run(message, body.options);
|
|
221
|
+
|
|
222
|
+
return c.json({
|
|
223
|
+
success: true,
|
|
224
|
+
sessionId,
|
|
225
|
+
reply: result.text,
|
|
226
|
+
thought: result.thought,
|
|
227
|
+
steps: result.totalSteps,
|
|
228
|
+
durationMs: Date.now() - start
|
|
229
|
+
});
|
|
230
|
+
} catch (err: any) {
|
|
231
|
+
return c.json({
|
|
232
|
+
success: false,
|
|
233
|
+
error: err.message || "Chat turn failed",
|
|
234
|
+
durationMs: Date.now() - start
|
|
235
|
+
}, 500);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 4. POST /stream
|
|
241
|
+
* Real-time Server-Sent Events (SSE) streaming
|
|
242
|
+
* Body: { input: string, sessionId?: string, spec?: any, path?: string }
|
|
243
|
+
*/
|
|
244
|
+
app.post("/stream", async (c) => {
|
|
245
|
+
let body: any = {};
|
|
246
|
+
try {
|
|
247
|
+
body = await c.req.json();
|
|
248
|
+
} catch {
|
|
249
|
+
return c.json({ success: false, error: "Invalid JSON body" }, 400);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const input = body.input || body.message;
|
|
253
|
+
if (!input || typeof input !== "string") {
|
|
254
|
+
return c.json({ success: false, error: "Missing 'input' parameter" }, 400);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return streamSSE(c, async (stream) => {
|
|
258
|
+
const start = Date.now();
|
|
259
|
+
try {
|
|
260
|
+
await stream.writeSSE({
|
|
261
|
+
event: "start",
|
|
262
|
+
data: JSON.stringify({
|
|
263
|
+
status: "started",
|
|
264
|
+
timestamp: new Date().toISOString()
|
|
265
|
+
})
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const agent = await getOrLoadAgent(body.spec, body.path);
|
|
269
|
+
const result = await agent.run(input, body.options);
|
|
270
|
+
|
|
271
|
+
// Stream out intermediate ReAct reasoning steps
|
|
272
|
+
if (result.steps && result.steps.length > 0) {
|
|
273
|
+
for (const step of result.steps) {
|
|
274
|
+
await stream.writeSSE({
|
|
275
|
+
event: "step",
|
|
276
|
+
data: JSON.stringify({
|
|
277
|
+
step: step.step,
|
|
278
|
+
thought: step.thought,
|
|
279
|
+
toolCalls: step.toolCalls?.map(t => t.name),
|
|
280
|
+
toolResults: step.toolResults?.map(r => ({ tool: r.toolName, result: r.result }))
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Stream out the final answer
|
|
287
|
+
await stream.writeSSE({
|
|
288
|
+
event: "message",
|
|
289
|
+
data: JSON.stringify({
|
|
290
|
+
text: result.text,
|
|
291
|
+
thought: result.thought
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// Stream completion
|
|
296
|
+
await stream.writeSSE({
|
|
297
|
+
event: "done",
|
|
298
|
+
data: JSON.stringify({
|
|
299
|
+
totalSteps: result.totalSteps,
|
|
300
|
+
durationMs: Date.now() - start,
|
|
301
|
+
model: result.model
|
|
302
|
+
})
|
|
303
|
+
});
|
|
304
|
+
} catch (err: any) {
|
|
305
|
+
await stream.writeSSE({
|
|
306
|
+
event: "error",
|
|
307
|
+
data: JSON.stringify({ error: err.message || "Streaming failed" })
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Port configuration
|
|
314
|
+
const PORT = Number(process.env.PORT || 7071);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Starts the HTTP server on specified port (Bun or Node)
|
|
318
|
+
*/
|
|
319
|
+
export function startServer(port: number = PORT) {
|
|
320
|
+
if (typeof Bun !== "undefined") {
|
|
321
|
+
Bun.serve({
|
|
322
|
+
port,
|
|
323
|
+
fetch: app.fetch
|
|
324
|
+
});
|
|
325
|
+
console.log(`🚀 [Liate] Edge Runtime server active at http://localhost:${port} (Bun)`);
|
|
326
|
+
} else {
|
|
327
|
+
import("@hono/node-server").then(({ serve }) => {
|
|
328
|
+
serve({
|
|
329
|
+
fetch: app.fetch,
|
|
330
|
+
port
|
|
331
|
+
}, (info) => {
|
|
332
|
+
console.log(`🚀 [Liate] Edge Runtime server active at http://localhost:${info.port} (Node)`);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Auto-start if executed directly as entrypoint
|
|
339
|
+
if (typeof Bun !== "undefined" && import.meta.main) {
|
|
340
|
+
startServer(PORT);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export default {
|
|
344
|
+
port: PORT,
|
|
345
|
+
fetch: app.fetch
|
|
346
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liate — WebAssembly / Edge Fetch Runtime Entrypoint
|
|
3
|
+
*
|
|
4
|
+
* Native Web Standards: Request, Response, Fetch API (Fastly Compute WASM / Workers).
|
|
5
|
+
*/
|
|
6
|
+
import { app } from "@/runtime/hono";
|
|
7
|
+
|
|
8
|
+
declare const addEventListener: (type: string, handler: (event: any) => void) => void;
|
|
9
|
+
|
|
10
|
+
if (typeof addEventListener !== "undefined") {
|
|
11
|
+
try {
|
|
12
|
+
addEventListener("fetch", (event: any) => {
|
|
13
|
+
event.respondWith(app.fetch(event.request));
|
|
14
|
+
});
|
|
15
|
+
} catch {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
fetch(request: Request, env?: any, ctx?: any) {
|
|
20
|
+
return app.fetch(request, env, ctx);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|