{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ActionMetadata } from '@genkit-ai/core';\nimport { Genkit } from './genkit.js';\nimport { ActionType } from './registry.js';\n\nexport interface PluginProvider {\n name: string;\n initializer: () => void | Promise;\n resolver?: (action: ActionType, target: string) => Promise;\n listActions?: () => Promise;\n}\n\nexport type GenkitPlugin = (genkit: Genkit) => PluginProvider;\n\nexport type PluginInit = (genkit: Genkit) => void | Promise;\n\nexport type PluginActionResolver = (\n genkit: Genkit,\n action: ActionType,\n target: string\n) => Promise;\n\n/**\n * Defines a Genkit plugin.\n */\nexport function genkitPlugin(\n pluginName: string,\n initFn: T,\n resolveFn?: PluginActionResolver,\n listActionsFn?: () => Promise\n): GenkitPlugin {\n return (genkit: Genkit) => ({\n name: pluginName,\n initializer: async () => {\n await initFn(genkit);\n },\n resolver: async (action: ActionType, target: string): Promise => {\n if (resolveFn) {\n return await resolveFn(genkit, action, target);\n }\n },\n listActions: async (): Promise => {\n if (listActionsFn) {\n return await listActionsFn();\n }\n return [];\n },\n });\n}\n"],"mappings":"AAwCO,SAAS,aACd,YACA,QACA,WACA,eACc;AACd,SAAO,CAAC,YAAoB;AAAA,IAC1B,MAAM;AAAA,IACN,aAAa,YAAY;AACvB,YAAM,OAAO,MAAM;AAAA,IACrB;AAAA,IACA,UAAU,OAAO,QAAoB,WAAkC;AACrE,UAAI,WAAW;AACb,eAAO,MAAM,UAAU,QAAQ,QAAQ,MAAM;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,aAAa,YAAuC;AAClD,UAAI,eAAe;AACjB,eAAO,MAAM,cAAc;AAAA,MAC7B;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF;","names":[]}