mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-26 15:34:26 +00:00
e9dd584792
* feat(api): support global API key from config.yaml (api.global_api_key) Accept a config-defined global API key anywhere a web-UI key is accepted (X-API-Key / Bearer), with no login session and no DB record. Useful for automated deployments and AI agents (HTTP API + MCP). Defaults to empty (disabled); does not require the lbk_ prefix. - templates/config.yaml: add api.global_api_key with security notes - service/apikey.py: verify_api_key checks global key first (constant-time) - docs/API_KEY_AUTH.md: document the global key + security guidance - tests: cover global-key match, prefix-free, fallback-to-db, disabled * feat(mcp): expose LangBot management as an MCP server at /mcp Add an MCP (Model Context Protocol) server so external AI agents can manage a LangBot instance. Reuses the same API-key auth as the HTTP API (including the config.yaml global API key). - pkg/api/mcp/server.py: FastMCP server wrapping the service layer; 21 curated tools across system/bots/pipelines/models/knowledge/mcp-servers/skills - pkg/api/mcp/mount.py: ASGI dispatcher fronting Quart; authenticates /mcp requests with an API key, runs the streamable-HTTP session manager lifespan - controller/main.py: serve the wrapped ASGI app via hypercorn (was run_task) - web: new 'MCP' tab in the API integration dialog showing endpoint, auth, and client config; i18n for 8 locales - tests/manual/mcp_smoke.py: e2e check (401 unauth, list tools, call tools) Tool surface is intentionally curated (not all ~25 route groups) to keep the agent surface small, safe, and maintainable. Extend deliberately. * feat(skills): add in-repo skills/ as the single source of truth Migrate the agent skills + QA/e2e test harness from the (now archived) langbot-app/langbot-skills repo into LangBot/skills/, and add four new skills. Migrated: - langbot-plugin-dev, langbot-testing (e2e), langbot-env-setup, langbot-skills-maintenance, langbot-eba-adapter-dev - the bin/lbs CLI (src/, test/, scripts/, schemas/, qa-agent-docs/) New: - langbot-dev core backend + web development - langbot-deploy Docker/K8s deployment + config.yaml + global API key - langbot-mcp-ops operating the LangBot MCP server (/mcp) - langbot-space-ops operating the Space marketplace MCP server - src/cli.ts repoRoot(): recognize the skills assets root (skills.index.json + bin/lbs) so the CLI works when nested inside the LangBot repo - README.md: unified skill catalog; skills.index.json regenerated Parity with source verified: bin/lbs validate + node test suite match the source repo (only the uncommitted .lbpkg build-artifact fixture differs). * docs(agents): document agent-facing surfaces + API/MCP/skills sync rule * docs(readme): add 'Built for AI Agents' section across all locales Highlight MCP server, in-repo skills (single source of truth), AGENTS.md sync rule, and llms.txt. Cross-link LangBot Space MCP marketplace. * style(mcp): fix ruff format + prettier lint in MCP server and API panel * style(web): prettier format MCP i18n locale entries * docs(skills): note MCP instance control in dev/testing skills All development-guidance skills now point to the LangBot instance MCP server (/mcp) and the Space marketplace MCP server, reusing API keys.
133 lines
4.7 KiB
TypeScript
133 lines
4.7 KiB
TypeScript
import type { CommandContext } from "../types.ts";
|
|
import { parseOptions } from "../cli.ts";
|
|
import { loadFixtureItems } from "../fixtures.ts";
|
|
import { dirname, join } from "node:path";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
|
|
function fixtureRows(root: string, skill: string | undefined): ReturnType<typeof loadFixtureItems> {
|
|
return loadFixtureItems(root, skill);
|
|
}
|
|
|
|
function qaAgentRunnerSourceFindings(item: ReturnType<typeof loadFixtureItems>["items"][number]) {
|
|
if (!item.checks.includes("qa_agent_runner_source") || !item.exists) return [];
|
|
const root = dirname(item.absolute_path);
|
|
const required = [
|
|
"main.py",
|
|
"components/agent_runner/default.yaml",
|
|
"components/agent_runner/default.py",
|
|
"assets/icon.svg",
|
|
];
|
|
const missing = required
|
|
.filter((path) => !existsSync(join(root, path)))
|
|
.map((path) => ({
|
|
severity: "fail",
|
|
kind: "fixture_check_missing_file",
|
|
id: item.id,
|
|
path: `${item.path.replace(/\/[^/]+$/, "")}/${path}`,
|
|
}));
|
|
if (missing.length > 0) return missing;
|
|
|
|
const manifest = readFileSync(item.absolute_path, "utf8");
|
|
const runnerYaml = readFileSync(join(root, "components/agent_runner/default.yaml"), "utf8");
|
|
const runnerPy = readFileSync(join(root, "components/agent_runner/default.py"), "utf8");
|
|
const requiredText = [
|
|
[manifest, "AgentRunner", "manifest.yaml"],
|
|
[manifest, "QAAgentRunnerPlugin", "manifest.yaml"],
|
|
[runnerYaml, "kind: AgentRunner", "components/agent_runner/default.yaml"],
|
|
[runnerYaml, "DefaultAgentRunner", "components/agent_runner/default.yaml"],
|
|
[runnerPy, "QA_AGENT_RUNNER_OK", "components/agent_runner/default.py"],
|
|
[runnerPy, "QA_AGENT_RUNNER_CONTROLLED_FAILURE", "components/agent_runner/default.py"],
|
|
];
|
|
return requiredText
|
|
.filter(([text, needle]) => !text.includes(needle))
|
|
.map(([, needle, relativePath]) => ({
|
|
severity: "fail",
|
|
kind: "fixture_check_missing_text",
|
|
id: item.id,
|
|
path: `${item.path.replace(/\/[^/]+$/, "")}/${relativePath}`,
|
|
detail: `missing ${needle}`,
|
|
}));
|
|
}
|
|
|
|
function zipPackageFindings(item: ReturnType<typeof loadFixtureItems>["items"][number]) {
|
|
if (!item.checks.includes("zip_package") || !item.exists) return [];
|
|
const header = readFileSync(item.absolute_path).subarray(0, 4).toString("binary");
|
|
if (header === "PK\u0003\u0004" || header === "PK\u0005\u0006") return [];
|
|
return [{
|
|
severity: "fail",
|
|
kind: "fixture_check_invalid_zip",
|
|
id: item.id,
|
|
path: item.path,
|
|
}];
|
|
}
|
|
|
|
export function commandFixtureList(ctx: CommandContext): number {
|
|
const { positional, options } = parseOptions(ctx.args.slice(2));
|
|
const skill = positional[0];
|
|
const result = fixtureRows(ctx.root, skill);
|
|
|
|
if (options.json === true) {
|
|
console.log(JSON.stringify(result.items, null, 2));
|
|
return result.errors.length > 0 ? 1 : 0;
|
|
}
|
|
|
|
for (const item of result.items) {
|
|
console.log([
|
|
item.skill,
|
|
item.id,
|
|
item.kind,
|
|
item.exists ? "present" : "missing",
|
|
item.path,
|
|
item.title,
|
|
].join("\t"));
|
|
}
|
|
for (const error of result.errors) console.error(`ERROR: ${error}`);
|
|
return result.errors.length > 0 ? 1 : 0;
|
|
}
|
|
|
|
export function commandFixtureCheck(ctx: CommandContext): number {
|
|
const { positional, options } = parseOptions(ctx.args.slice(2));
|
|
const skill = positional[0];
|
|
const result = fixtureRows(ctx.root, skill);
|
|
const findings = [
|
|
...result.errors.map((error) => ({ severity: "fail", kind: "invalid_manifest", detail: error })),
|
|
...result.items
|
|
.filter((item) => !item.exists)
|
|
.map((item) => ({
|
|
severity: "fail",
|
|
kind: "missing_fixture",
|
|
id: item.id,
|
|
path: item.path,
|
|
absolute_path: item.absolute_path,
|
|
})),
|
|
...result.items.flatMap(qaAgentRunnerSourceFindings),
|
|
...result.items.flatMap(zipPackageFindings),
|
|
];
|
|
const report = {
|
|
status: findings.some((finding) => finding.severity === "fail") ? "fail" : "pass",
|
|
fixture_count: result.items.length,
|
|
findings,
|
|
fixtures: result.items,
|
|
};
|
|
|
|
if (options.json === true) {
|
|
console.log(JSON.stringify(report, null, 2));
|
|
} else {
|
|
console.log(`# Fixture Check`);
|
|
console.log("");
|
|
console.log(`status: ${report.status}`);
|
|
console.log(`fixture_count: ${report.fixture_count}`);
|
|
console.log("");
|
|
console.log("## Fixtures");
|
|
for (const item of result.items) {
|
|
console.log(`- ${item.id}: ${item.exists ? "present" : "missing"} (${item.path})`);
|
|
}
|
|
console.log("");
|
|
console.log("## Findings");
|
|
if (findings.length === 0) console.log("- None.");
|
|
else for (const finding of findings) console.log(`- [${finding.severity}] ${finding.kind}: ${"detail" in finding ? finding.detail : finding.id}`);
|
|
}
|
|
|
|
return report.status === "pass" ? 0 : 1;
|
|
}
|