const { Tool } = require("@langchain/core/tools"); const { JLINCTracer } = require("../tracer/index.js"); const { authDecide, authInvoke, getDescription, getName } = require("./common.js"); /** * @typedef {import('./common').JLINCConfig} JLINCConfig */ /** * @typedef {Object} JLINCAuthToolFields * @property {JLINCConfig} config * @property {Tool} jlincAuthDecision * @property {Tool} targetAuthorized * @property {Tool|null} targetNotAuthorized */ class JLINCAuthTool extends Tool { /** * @param {JLINCAuthToolFields} fields */ constructor({ config, jlincAuthDecision, targetAuthorized, targetNotAuthorized }) { super({ name: "jlinc_auth_tool", description: "", // overridden dynamically }); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: getName(targetAuthorized, targetNotAuthorized) }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: getDescription(targetAuthorized, targetNotAuthorized, 'Tool') }); /** @type {JLINCConfig} */ this.config = config; /** @type {Tool} */ this.jlincAuthDecision = jlincAuthDecision; /** @type {Tool} */ this.targetAuthorized = targetAuthorized; /** @type {Tool|null} */ this.targetNotAuthorized = targetNotAuthorized; /** @type {JLINCTracer} */ this.tracer = new JLINCTracer(config); /** @type {string} */ this.authType = 'Tool'; } /** * @template TInput * @template {undefined | ToolRunnableConfig} TConfig * @template TOutput * * @param {TInput} input * @param {TConfig} [config] * @returns {Promise>} */ async invoke(input, runManager) { return await authInvoke(this, input); } } module.exports = { JLINCAuthTool, };