Skip to main content
Glama
before.ts1.16 kB
import { Debug } from "../debug.ts"; import { failureExecution, Func, ResultFailure, ResultSuccess, } from "../function.ts"; import { runCode } from "../execution.ts"; import { RequestCtx } from "../request.ts"; import { FunctionKind } from "../function.ts"; const debug = Debug("langJs:before"); export interface BeforeFunc extends Func { arg: unknown; } export type BeforeResultSuccess = ResultSuccess; export type BeforeResultFailure = ResultFailure; export type BeforeResult = BeforeResultSuccess | BeforeResultFailure; async function execute( { executionId }: RequestCtx, { arg, handler }: BeforeFunc, code: string, timeout: number, ): Promise<BeforeResult> { try { await runCode( code, handler, FunctionKind.Before, executionId, timeout, arg as Record<string, unknown>, ); } catch (err) { return failureExecution(err as Error, executionId); } return { protocol: "result", status: "success", executionId, }; } const wrapCode = (code: string, handler: string) => ` ${code} export { ${handler} }; `; export default { debug, execute, wrapCode, };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server