UNPKG

@genkit-ai/dotprompt

Version:

Genkit AI framework `.prompt` file format and management library.

143 lines 4.86 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var metadata_exports = {}; __export(metadata_exports, { PromptFrontmatterSchema: () => PromptFrontmatterSchema, toFrontmatter: () => toFrontmatter, toMetadata: () => toMetadata }); module.exports = __toCommonJS(metadata_exports); var import_model = require("@genkit-ai/ai/model"); var import_core = require("@genkit-ai/core"); var import_schema = require("@genkit-ai/core/schema"); var import_picoschema = require("./picoschema.js"); const PromptFrontmatterSchema = import_core.z.object({ name: import_core.z.string().optional(), description: import_core.z.string().optional(), variant: import_core.z.string().optional(), model: import_core.z.string().optional(), tools: import_core.z.array(import_core.z.string()).optional(), config: import_model.GenerationCommonConfigSchema.passthrough().optional(), input: import_core.z.object({ default: import_core.z.any(), schema: import_core.z.unknown() }).optional(), output: import_core.z.object({ format: import_core.z.enum(["json", "text", "media"]).optional(), schema: import_core.z.unknown().optional() }).optional(), metadata: import_core.z.record(import_core.z.unknown()).optional() }); function stripUndefinedOrNull(obj) { if (typeof obj !== "object" || obj === null) { return obj; } for (const key in obj) { if (obj[key] === void 0 || obj[key] === null) { delete obj[key]; } else if (typeof obj[key] === "object") { stripUndefinedOrNull(obj[key]); } } return obj; } function fmSchemaToSchema(registry, fmSchema) { if (!fmSchema) return {}; if (typeof fmSchema === "string") return registry.lookupSchema(fmSchema); return { jsonSchema: (0, import_picoschema.picoschema)(fmSchema) }; } function toMetadata(registry, attributes) { const fm = (0, import_schema.parseSchema)(attributes, { schema: PromptFrontmatterSchema }); let input; if (fm.input) { input = __spreadValues({ default: fm.input.default }, fmSchemaToSchema(registry, fm.input.schema)); } let output; if (fm.output) { output = __spreadValues({ format: fm.output.format }, fmSchemaToSchema(registry, fm.output.schema)); } return stripUndefinedOrNull({ name: fm.name, description: fm.description, variant: fm.variant, model: fm.model, config: fm.config, input, output, metadata: fm.metadata, tools: fm.tools }); } function toFrontmatter(md) { var _a, _b; return stripUndefinedOrNull({ name: md.name, variant: md.variant, model: typeof md.model === "string" ? md.model : (_a = md.model) == null ? void 0 : _a.name, config: md.config, input: md.input ? { default: md.input.default, schema: (0, import_schema.toJsonSchema)({ schema: md.input.schema, jsonSchema: md.input.jsonSchema }) } : void 0, output: md.output ? { format: md.output.format, schema: (0, import_schema.toJsonSchema)({ schema: md.output.schema, jsonSchema: md.output.jsonSchema }) } : void 0, metadata: md.metadata, tools: (_b = md.tools) == null ? void 0 : _b.map( (t) => { var _a2; return typeof t === "string" ? t : ((_a2 = t.__action) == null ? void 0 : _a2.name) || t.name; } ) }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PromptFrontmatterSchema, toFrontmatter, toMetadata }); //# sourceMappingURL=metadata.js.map