genkit-cli
Version:
CLI for interacting with the Google Genkit AI framework
50 lines • 2.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineTraceTools = defineTraceTools;
const manager_1 = require("@genkit-ai/tools-common/manager");
const utils_1 = require("@genkit-ai/tools-common/utils");
const zod_1 = __importDefault(require("zod"));
const analytics_js_1 = require("./analytics.js");
const utils_js_1 = require("./utils.js");
function defineTraceTools(server, options) {
server.registerTool('get_trace', {
title: 'Get Genkit Trace',
description: 'Returns the trace details.',
inputSchema: (0, utils_js_1.getCommonSchema)(options.explicitProjectRoot, {
traceId: zod_1.default
.string()
.describe('trace id (typically returned after running a flow or other actions); type: string'),
}),
}, async (opts) => {
await (0, utils_1.record)(new analytics_js_1.McpRunToolEvent('get_trace'));
const rootOrError = (0, utils_js_1.resolveProjectRoot)(options.explicitProjectRoot, opts, options.projectRoot);
if (typeof rootOrError !== 'string')
return rootOrError;
const { traceId } = opts;
try {
const runtimeManager = await options.manager.getManager(rootOrError);
const response = await runtimeManager.getTrace({ traceId });
return {
content: [
{ type: 'text', text: JSON.stringify(response, undefined, 2) },
],
};
}
catch (e) {
const errStr = e instanceof manager_1.GenkitToolsError ? e.formatError() : JSON.stringify(e);
return {
isError: true,
content: [
{
type: 'text',
text: `Error: ${errStr}`,
},
],
};
}
});
}
//# sourceMappingURL=trace.js.map