/**
 * 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 suggestions_exports = {};
__export(suggestions_exports, {
  default: () => suggestions_default
});
module.exports = __toCommonJS(suggestions_exports);
var import_ai = require("@nocobase/ai");
var import_zod = require("zod");
var suggestions_default = (0, import_ai.defineTools)({
  scope: "GENERAL",
  introduction: {
    title: '{{t("Suggestions")}}',
    about: '{{t("Provide a list of suggested prompts for the user to choose from.")}}'
  },
  definition: {
    name: "suggestions",
    description: "Provide a list of suggested prompts for the user to choose from.",
    schema: import_zod.z.object({
      option: import_zod.z.string().describe("user selected option, ignore this param").optional(),
      options: import_zod.z.array(import_zod.z.string()).describe(
        "A list of suggested prompts that can be presented to the user as selectable options.Each option represents a possible next user message."
      )
    })
  },
  invoke: async (ctx, args, id) => {
    var _a, _b;
    const { messageId } = ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) || {};
    if (messageId) {
      const messageRepo = ctx.app.db.getRepository("aiMessages");
      const message = await messageRepo.findOne({
        filterByTk: messageId
      });
      const toolCalls = (message == null ? void 0 : message.toolCalls) || [];
      const index = toolCalls.findIndex((toolCall) => toolCall.id === id);
      if (index !== -1) {
        toolCalls[index] = {
          ...toolCalls[index],
          selectedSuggestion: args == null ? void 0 : args.option
        };
        await messageRepo.update({
          filter: { messageId },
          values: {
            toolCalls
          }
        });
      }
    }
    return {
      status: "success",
      content: args == null ? void 0 : args.option
    };
  }
});
