{"version":3,"sources":["../src/config.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 { logger } from './logging.mjs';\n\nconst CONFIG_KEY = '__GENKIT_RUNTIME_CONFIG__';\n\n/**\n * Runtime configuration for Genkit.\n */\nexport interface GenkitRuntimeConfig {\n  /**\n   * JSON schema validation mode.\n   * - 'compile': Uses `ajv` to compile schema validation functions. This is faster but requires `eval` or `new Function` support.\n   * - 'interpret': Uses `@cfworker/json-schema` to interpret schemas. This is slower but works in environments that restrict code generation (e.g. Cloudflare Workers).\n   */\n  jsonSchemaMode?: 'compile' | 'interpret';\n\n  /**\n   * Whether the runtime is sandboxed.\n   * If true, features that require access to the file system or spawning processes (like the Reflection API) will be disabled.\n   */\n  sandboxedRuntime?: boolean;\n}\n\nfunction getConfig(): GenkitRuntimeConfig {\n  if (!global[CONFIG_KEY]) {\n    global[CONFIG_KEY] = {};\n  }\n  return global[CONFIG_KEY];\n}\n\n/**\n * Sets the runtime configuration for Genkit.\n */\nexport function setGenkitRuntimeConfig(config: GenkitRuntimeConfig) {\n  if (config.jsonSchemaMode === 'interpret') {\n    logger.warn(\n      \"It looks like you're trying to disable schema code generation. Please ensure that the '@cfworker/json-schema' package is installed: `npm i --save @cfworker/json-schema`\"\n    );\n  }\n  const current = getConfig();\n  global[CONFIG_KEY] = { ...current, ...config };\n}\n\n/**\n * Gets the current runtime configuration for Genkit.\n */\nexport function getGenkitRuntimeConfig(): GenkitRuntimeConfig {\n  const config = getConfig();\n  return {\n    jsonSchemaMode: config.jsonSchemaMode ?? 'compile',\n    sandboxedRuntime: config.sandboxedRuntime ?? false,\n  };\n}\n\n/**\n * Resets the current runtime configuration for Genkit.\n */\nexport function resetGenkitRuntimeConfig() {\n  global[CONFIG_KEY] = {};\n}\n"],"mappings":"AAgBA,SAAS,cAAc;AAEvB,MAAM,aAAa;AAoBnB,SAAS,YAAiC;AACxC,MAAI,CAAC,OAAO,UAAU,GAAG;AACvB,WAAO,UAAU,IAAI,CAAC;AAAA,EACxB;AACA,SAAO,OAAO,UAAU;AAC1B;AAKO,SAAS,uBAAuB,QAA6B;AAClE,MAAI,OAAO,mBAAmB,aAAa;AACzC,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AACA,QAAM,UAAU,UAAU;AAC1B,SAAO,UAAU,IAAI,EAAE,GAAG,SAAS,GAAG,OAAO;AAC/C;AAKO,SAAS,yBAA8C;AAC5D,QAAM,SAAS,UAAU;AACzB,SAAO;AAAA,IACL,gBAAgB,OAAO,kBAAkB;AAAA,IACzC,kBAAkB,OAAO,oBAAoB;AAAA,EAC/C;AACF;AAKO,SAAS,2BAA2B;AACzC,SAAO,UAAU,IAAI,CAAC;AACxB;","names":[]}