Add built-in read-only Langfuse trace domain
This commit is contained in:
1 parent
e2410e6923
commit
45011c8333
31 files changed
+2823
-47
No files matched your search
@@ -3,6 +3,9 @@ import { resolveCorpConfig } from "../core/config/manager.js";
|
||||
import { recordCorpUsage } from "../core/stats/usage-tracker.js";
|
||||
import { createSealClient } from "../core/http/factory.js";
|
||||
import { sealCapabilities, parseCapabilityParams, type SealCapability } from "../domains/seal/capabilities.js";
|
||||
import { createLangfuseService, findLangfuseCapability } from "../domains/langfuse/capabilities.js";
|
||||
import type { LangfuseService } from "../domains/langfuse/service.js";
|
||||
import { validationError } from "../core/errors.js";
|
||||
import type { CorpConfig, GlobalConfig } from "../core/config/types.js";
|
||||
import { printJson } from "./printer.js";
|
||||
import type { OutputOptions } from "./types.js";
|
||||
@@ -67,3 +70,34 @@ export async function runCapabilityResult(
|
||||
const handler = tool.handler as SealCapability["handler"];
|
||||
return handler(client, compactParams as never, { corp });
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches one read-only Langfuse capability and prints its JSON payload.
|
||||
*
|
||||
* Same contract as `runCapability` minus the tenant: no Seal client, no
|
||||
* corp — Langfuse access relies solely on the compile-time injected key pair.
|
||||
* Params are gated by the capability's Zod schema (missing/invalid → exit 13)
|
||||
* before the handler sees them.
|
||||
*/
|
||||
export async function runLangfuseCapability(
|
||||
name: string,
|
||||
params: Record<string, unknown>,
|
||||
options: OutputOptions = {}
|
||||
) {
|
||||
const tool = findLangfuseCapability(name);
|
||||
if (!tool) throw new Error(`Unknown Langfuse tool: ${name}`);
|
||||
|
||||
const compactParams = Object.fromEntries(
|
||||
Object.entries(params).filter(([, value]) => value !== undefined)
|
||||
);
|
||||
const parsed = tool.parameters.safeParse(compactParams);
|
||||
if (!parsed.success) {
|
||||
const detail = parsed.error.issues
|
||||
.map((issue) => `${issue.path.length ? issue.path.join(".") : "(root)"}: ${issue.message}`)
|
||||
.join("; ");
|
||||
throw validationError(`Invalid parameters for ${tool.name}: ${detail}`);
|
||||
}
|
||||
|
||||
const handler = tool.handler as (params: never, service: LangfuseService) => Promise<unknown>;
|
||||
printJson(await handler(compactParams as never, createLangfuseService()), options);
|
||||
}
|
||||
Reference in new issue
Block a user