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,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
|
+
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/scaffold/project.ts
|
|
2
|
+
// Liate v0.1.2 — Project Scaffolder (TypeScript & Python L·I·A·T·E Agent Templates)
|
|
3
|
+
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
export interface ScaffoldOptions {
|
|
8
|
+
name: string;
|
|
9
|
+
targetDir?: string;
|
|
10
|
+
lang?: "ts" | "py";
|
|
11
|
+
skills?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ScaffoldResult {
|
|
15
|
+
projectName: string;
|
|
16
|
+
className: string;
|
|
17
|
+
lang: "ts" | "py";
|
|
18
|
+
projectDir: string;
|
|
19
|
+
files: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toPascalCase(str: string): string {
|
|
23
|
+
return str
|
|
24
|
+
.split(/[-_]+/)
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
27
|
+
.join("");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function scaffoldProject(options: ScaffoldOptions): ScaffoldResult {
|
|
31
|
+
const rawName = options.name.trim();
|
|
32
|
+
if (!rawName) {
|
|
33
|
+
throw new Error("Agent project name is required.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cleanName = rawName
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.replace(/[^a-z0-9_-]/g, "-")
|
|
39
|
+
.replace(/^-+|-+$/g, "");
|
|
40
|
+
|
|
41
|
+
if (!cleanName) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Invalid agent project name '${rawName}'. Use alphanumeric characters and hyphens.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const className =
|
|
48
|
+
toPascalCase(cleanName) + (cleanName.toLowerCase().endsWith("agent") ? "" : "Agent");
|
|
49
|
+
const targetDir = options.targetDir
|
|
50
|
+
? path.resolve(options.targetDir)
|
|
51
|
+
: path.resolve(process.cwd(), cleanName);
|
|
52
|
+
const lang: "ts" | "py" = options.lang === "py" ? "py" : "ts";
|
|
53
|
+
const skills = options.skills?.length ? options.skills : ["vercel-labs/skills/find-skills"];
|
|
54
|
+
|
|
55
|
+
if (fs.existsSync(targetDir)) {
|
|
56
|
+
const existing = fs.readdirSync(targetDir);
|
|
57
|
+
if (existing.length > 0) {
|
|
58
|
+
throw new Error(`Target directory '${targetDir}' already exists and is not empty.`);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let filesToWrite: Record<string, string>;
|
|
65
|
+
|
|
66
|
+
if (lang === "py") {
|
|
67
|
+
const pyprojectContent = `[project]
|
|
68
|
+
name = "${cleanName}"
|
|
69
|
+
version = "0.1.0"
|
|
70
|
+
description = "AI Agent built with Liate"
|
|
71
|
+
requires-python = ">=3.9"
|
|
72
|
+
dependencies = [
|
|
73
|
+
"liate>=0.1.0"
|
|
74
|
+
]
|
|
75
|
+
`;
|
|
76
|
+
|
|
77
|
+
const agentPyContent = `import os
|
|
78
|
+
import sys
|
|
79
|
+
from liate import liate
|
|
80
|
+
|
|
81
|
+
class ${className}(liate):
|
|
82
|
+
"""${className} — Sovereign AI Agent (L · I · A · T · E)"""
|
|
83
|
+
|
|
84
|
+
L = "sarvam/sarvam-105b-conversations"
|
|
85
|
+
I = { "memory": "sessions/${cleanName}" }
|
|
86
|
+
A = {
|
|
87
|
+
"name": "${cleanName}",
|
|
88
|
+
"intent": "AI Agent built with OpenLiate",
|
|
89
|
+
"max_steps": 5,
|
|
90
|
+
"skills": ${JSON.stringify(skills)},
|
|
91
|
+
}
|
|
92
|
+
T = {}
|
|
93
|
+
E = { "SARVAM_API_KEY": os.environ.get("SARVAM_API_KEY", "$SARVAM_API_KEY") }
|
|
94
|
+
|
|
95
|
+
def main():
|
|
96
|
+
agent = ${className}()
|
|
97
|
+
prompt = sys.argv[1] if len(sys.argv) > 1 else "Namaste, who are you?"
|
|
98
|
+
result = agent.run(prompt)
|
|
99
|
+
print(result)
|
|
100
|
+
|
|
101
|
+
if __name__ == "__main__":
|
|
102
|
+
main()
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
filesToWrite = {
|
|
106
|
+
"pyproject.toml": pyprojectContent,
|
|
107
|
+
"agent.py": agentPyContent,
|
|
108
|
+
".env.example": "SARVAM_API_KEY=your_sarvam_api_key_here\n",
|
|
109
|
+
"README.md": `# ${cleanName}\n\nAI Agent scaffolded with **Liate**.\n\n\`\`\`bash\npython agent.py "Hello!"\n\`\`\`\n`,
|
|
110
|
+
};
|
|
111
|
+
} else {
|
|
112
|
+
const pkgJson = {
|
|
113
|
+
name: cleanName,
|
|
114
|
+
version: "0.1.0",
|
|
115
|
+
private: true,
|
|
116
|
+
type: "module",
|
|
117
|
+
scripts: {
|
|
118
|
+
start: "bun run agent.ts",
|
|
119
|
+
serve: "liate serve agent.json --port 7071",
|
|
120
|
+
},
|
|
121
|
+
dependencies: {
|
|
122
|
+
"@openliate/liate": "^0.1.0",
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const agentJson = {
|
|
127
|
+
L: "sarvam/sarvam-105b-conversations",
|
|
128
|
+
I: { memory: `sessions/${cleanName}` },
|
|
129
|
+
A: {
|
|
130
|
+
name: cleanName,
|
|
131
|
+
intent: "Sovereign AI Agent built with Liate",
|
|
132
|
+
maxSteps: 5,
|
|
133
|
+
skills,
|
|
134
|
+
},
|
|
135
|
+
T: {},
|
|
136
|
+
E: { SARVAM_API_KEY: "$SARVAM_API_KEY" },
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const agentTsContent = `import { liate } from "@openliate/liate";
|
|
140
|
+
|
|
141
|
+
export class ${className} extends liate {
|
|
142
|
+
L = "sarvam/sarvam-105b-conversations";
|
|
143
|
+
I = { memory: "sessions/${cleanName}" };
|
|
144
|
+
A = {
|
|
145
|
+
name: "${cleanName}",
|
|
146
|
+
intent: "Sovereign AI Agent built with Liate",
|
|
147
|
+
maxSteps: 5,
|
|
148
|
+
skills: ${JSON.stringify(skills)},
|
|
149
|
+
};
|
|
150
|
+
T = {};
|
|
151
|
+
E = { SARVAM_API_KEY: "$SARVAM_API_KEY" };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (import.meta.main) {
|
|
155
|
+
const agent = new ${className}();
|
|
156
|
+
const prompt = process.argv.slice(2).join(" ") || "Namaste, confirm you are running Liate.";
|
|
157
|
+
const result = await agent.run(prompt);
|
|
158
|
+
console.log(result.text);
|
|
159
|
+
await agent.close();
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
|
|
163
|
+
filesToWrite = {
|
|
164
|
+
"package.json": JSON.stringify(pkgJson, null, 2) + "\n",
|
|
165
|
+
"agent.json": JSON.stringify(agentJson, null, 2) + "\n",
|
|
166
|
+
"agent.ts": agentTsContent,
|
|
167
|
+
".env.example": "SARVAM_API_KEY=your_sarvam_api_key_here\n",
|
|
168
|
+
"README.md": `# ${cleanName}\n\nAI Agent scaffolded with **Liate**.\n\n\`\`\`bash\nliate run agent.json "Hello!"\n\`\`\`\n`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const createdFiles: string[] = [];
|
|
173
|
+
for (const [relPath, content] of Object.entries(filesToWrite)) {
|
|
174
|
+
const fullPath = path.join(targetDir, relPath);
|
|
175
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
176
|
+
fs.writeFileSync(fullPath, content, "utf-8");
|
|
177
|
+
createdFiles.push(relPath);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
projectName: cleanName,
|
|
182
|
+
className,
|
|
183
|
+
lang,
|
|
184
|
+
projectDir: targetDir,
|
|
185
|
+
files: createdFiles,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
package/dist/engine/engine.zip
DELETED
|
Binary file
|