genkit
Version:
Genkit AI framework
178 lines • 5.58 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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 genkit_beta_exports = {};
__export(genkit_beta_exports, {
FileSessionStore: () => import_session_stores.FileSessionStore,
GenkitBeta: () => GenkitBeta,
InMemorySessionStore: () => import_session_stores.InMemorySessionStore,
SessionRunner: () => import_ai.SessionRunner,
applyPatch: () => import_json_patch.applyPatch,
diff: () => import_json_patch.diff,
genkit: () => genkit
});
module.exports = __toCommonJS(genkit_beta_exports);
var import_ai = require("@genkit-ai/ai");
var import_formats = require("@genkit-ai/ai/formats");
var import_session_stores = require("@genkit-ai/ai/session-stores");
var import_json_patch = require("@genkit-ai/ai/json-patch");
var import_genkit = require("./genkit.js");
function genkit(options) {
return new GenkitBeta(options);
}
class GenkitBeta extends import_genkit.Genkit {
constructor(options) {
super(options);
this.registry.apiStability = "beta";
}
/**
* Defines and registers a custom agent with a custom handler function.
*
* @beta
*/
defineCustomAgent(config, fn) {
return (0, import_ai.defineCustomAgent)(this.registry, config, fn);
}
/**
* Defines and registers an agent from an existing Prompt template.
*
* @beta
*/
definePromptAgent(config) {
return (0, import_ai.definePromptAgent)(this.registry, config);
}
/**
* Defines and registers an agent by creating a prompt and wiring it into a
* multi-turn agent in one step.
*
* This is a convenience shortcut that combines `definePrompt` and
* `definePromptAgent` into a single call.
*
* ```ts
* const myAgent = ai.defineAgent({
* name: 'myAgent',
* model: 'googleai/gemini-2.5-flash',
* system: 'Talk like a pirate.',
* tools: [weatherTool],
* store: new FileSessionStore('./.snapshots'),
* });
* ```
*
* @beta
*/
defineAgent(config) {
return (0, import_ai.defineAgent)(this.registry, config);
}
/**
* Defines and registers a custom model output formatter.
*
* Here's an example of a custom JSON output formatter:
*
* ```ts
* import { extractJson } from 'genkit/extract';
*
* ai.defineFormat(
* { name: 'customJson' },
* (schema) => {
* let instructions: string | undefined;
* if (schema) {
* instructions = `Output should be in JSON format and conform to the following schema:
* \`\`\`
* ${JSON.stringify(schema)}
* \`\`\`
* `;
* }
* return {
* parseChunk: (chunk) => extractJson(chunk.accumulatedText),
* parseMessage: (message) => extractJson(message.text),
* instructions,
* };
* }
* );
*
* const { output } = await ai.generate({
* prompt: 'Invent a menu item for a pirate themed restaurant.',
* output: { format: 'customJson', schema: MenuItemSchema },
* });
* ```
*
* @beta
*/
defineFormat(options, handler) {
return (0, import_formats.defineFormat)(this.registry, options, handler);
}
/**
* Defines and registers an interrupt.
*
* Interrupts are special tools that halt model processing and return control back to the caller. Interrupts make it simpler to implement
* "human-in-the-loop" and out-of-band processing patterns that require waiting on external actions to complete.
*
* @beta
*/
defineInterrupt(config) {
return (0, import_ai.defineInterrupt)(this.registry, config);
}
/**
* Starts a generate operation for long running generation models, typically for
* video and complex audio generation.
*
* See {@link GenerateOptions} for detailed information about available options.
*
* ```ts
* const operation = await ai.generateOperation({
* model: googleAI.model('veo-2.0-generate-001'),
* prompt: 'A banana riding a bicycle.',
* });
* ```
*
* The status of the operation and final result can be obtained using {@link Genkit.checkOperation}.
*/
generateOperation(opts) {
return (0, import_ai.generateOperation)(this.registry, opts);
}
/**
* Defines a resource. Resources can then be accessed from a generate call.
*
* ```ts
* ai.defineResource({
* uri: 'my://resource/{param}',
* description: 'provides my resource',
* }, async ({param}) => {
* return [{ text: `resource ${param}` }]
* });
*
* await ai.generate({
* prompt: [{ resource: 'my://resource/value' }]
* })
* ```
*/
defineResource(opts, fn) {
return (0, import_ai.defineResource)(this.registry, opts, fn);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
FileSessionStore,
GenkitBeta,
InMemorySessionStore,
SessionRunner,
applyPatch,
diff,
genkit
});
//# sourceMappingURL=genkit-beta.js.map