stoa/apps/web/lib/safe-skills.ts
stoa 1a9b5f90a5 feat(web): live skill playground — run read-only skills server-side
- /playground page: pick a runnable skill, edit JSON input, see live result
- /api/run (list runnable skills) + /api/run/[skill] (execute pure/market-data skills)
- lib/safe-skills.ts: allowlist of keyless/read-only domains (pure + marketdata)
- next.config transpilePackages so routes can import @stoa/skills
- dashboard nav links all pages (agents/playground/connect added)
- web app: 8 pages + 8 API routes
2026-06-12 09:57:46 +03:00

60 lines
1.5 KiB
TypeScript

import "server-only";
import catalogJson from "./skills-catalog.json";
// Domains whose skills are safe to run in the public playground: pure/computational helpers and
// read-only market-data lookups. They need no private key and move no funds. Write skills,
// key-generation, and on-chain mutations are intentionally excluded.
const SAFE_DOMAINS = new Set<string>([
"utils",
"math",
"format",
"convert",
"bytes",
"encoding",
"hashing",
"abitools",
"base64",
"duration",
"pricemath",
"amm",
"units",
"validate",
"marketdata",
"chainreg",
"memo",
"addressutils",
"sigutils",
"agentcard",
"time",
]);
interface CatalogJson {
domains: Array<{ domain: string; skills: Array<{ name: string; description: string }> }>;
}
const CATALOG = catalogJson as CatalogJson;
export interface RunnableSkill {
name: string;
domain: string;
description: string;
}
/// Every skill that can be executed in the playground (no keys, no writes).
export function getRunnableSkills(): RunnableSkill[] {
const out: RunnableSkill[] = [];
for (const d of CATALOG.domains ?? []) {
if (!SAFE_DOMAINS.has(d.domain)) continue;
for (const s of d.skills ?? []) {
out.push({ name: s.name, domain: d.domain, description: s.description });
}
}
return out.sort((a, b) => a.name.localeCompare(b.name));
}
const RUNNABLE = new Set(getRunnableSkills().map((s) => s.name));
export function isRunnable(name: string): boolean {
return RUNNABLE.has(name.toUpperCase());
}