/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */

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 getContextVars_exports = {};
__export(getContextVars_exports, {
  default: () => getContextVars_default
});
module.exports = __toCommonJS(getContextVars_exports);
var import_ai = require("@nocobase/ai");
var import_zod = require("zod");
var getContextVars_default = (0, import_ai.defineTools)({
  scope: "SPECIFIED",
  execution: "frontend",
  defaultPermission: "ALLOW",
  introduction: {
    title: `{{t("ai.tools.getContextVars.title")}}`,
    about: `{{t("ai.tools.getContextVars.about")}}`
  },
  definition: {
    name: "getContextVars",
    description: `Available variables from context.

Variables are references only and do not contain actual values.
You must explicitly resolve values via \`await ctx.getVar(path)\`.

The \`path\` supports progressive drilling (dot-notation).
When you only need a specific field, prefer a more precise path
instead of fetching the entire object, e.g.
\`await ctx.getVar('ctx.popup.record.id')\` rather than
\`await ctx.getVar('ctx.popup.record')\`.`,
    schema: import_zod.z.object({
      path: import_zod.z.string().optional().describe(
        "Dot-notated variable path. Supports progressive drilling. Prefer the most specific path when only a subset of data is needed."
      ),
      depth: import_zod.z.number().optional().describe(
        "Maximum traversal depth when exploring variables. Default is 3. Use smaller depth when the target structure is known."
      )
    })
  },
  invoke: async (ctx, _args, runtime) => {
    const { toolCallResults } = ctx.action.params.values || {};
    const { result } = (toolCallResults == null ? void 0 : toolCallResults.find((item) => item.id === runtime.toolCallId)) ?? {};
    if (toolCallResults && result) {
      return {
        status: "success",
        content: JSON.stringify(result)
      };
    } else {
      return {
        status: "success",
        content: "{}"
      };
    }
  }
});
