@elevenlabs/convai-cli
Version:
CLI tool to manage ElevenLabs conversational AI agents
234 lines • 7.13 kB
JavaScript
;
/**
* Tool management for conversational AI agents
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDefaultWebhookTool = createDefaultWebhookTool;
exports.createDefaultClientTool = createDefaultClientTool;
exports.readToolConfig = readToolConfig;
exports.writeToolConfig = writeToolConfig;
exports.readToolsConfig = readToolsConfig;
exports.writeToolsConfig = writeToolsConfig;
exports.loadToolsLockFile = loadToolsLockFile;
exports.saveToolsLockFile = saveToolsLockFile;
exports.updateToolInLock = updateToolInLock;
exports.getToolFromLock = getToolFromLock;
exports.calculateToolHash = calculateToolHash;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const utils_1 = require("./utils");
/**
* Creates a default webhook tool configuration
*/
function createDefaultWebhookTool(name) {
return {
name,
description: `${name} webhook tool`,
type: 'webhook',
api_schema: {
url: 'https://api.example.com/webhook',
method: 'POST',
path_params_schema: [],
query_params_schema: [],
request_body_schema: {
id: 'body',
type: 'object',
value_type: 'llm_prompt',
description: 'Request body for the webhook',
dynamic_variable: '',
constant_value: '',
required: true,
properties: []
},
request_headers: [
{
type: 'value',
name: 'Content-Type',
value: 'application/json'
}
],
auth_connection: null
},
response_timeout_secs: 30,
dynamic_variables: {
dynamic_variable_placeholders: {}
}
};
}
/**
* Creates a default client tool configuration
*/
function createDefaultClientTool(name) {
return {
name,
description: `${name} client tool`,
type: 'client',
expects_response: false,
response_timeout_secs: 30,
parameters: [
{
id: 'input',
type: 'string',
value_type: 'llm_prompt',
description: 'Input parameter for the client tool',
dynamic_variable: '',
constant_value: '',
required: true
}
],
dynamic_variables: {
dynamic_variable_placeholders: {}
}
};
}
/**
* Reads a tool configuration file
*/
async function readToolConfig(filePath) {
try {
const data = await fs.readFile(filePath, 'utf-8');
return JSON.parse(data);
}
catch (error) {
if (error.code === 'ENOENT') {
throw new Error(`Tool configuration file not found at ${filePath}`);
}
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON in tool configuration file ${filePath}`);
}
throw error;
}
}
/**
* Writes a tool configuration to a file
*/
async function writeToolConfig(filePath, config) {
try {
const directory = path.dirname(filePath);
if (directory) {
await fs.ensureDir(directory);
}
await fs.writeFile(filePath, JSON.stringify(config, null, 4), 'utf-8');
}
catch (error) {
throw new Error(`Could not write tool configuration file to ${filePath}: ${error}`);
}
}
/**
* Reads the tools configuration file
*/
async function readToolsConfig(filePath) {
try {
const data = await fs.readFile(filePath, 'utf-8');
return JSON.parse(data);
}
catch (error) {
if (error.code === 'ENOENT') {
return { tools: [] };
}
throw error;
}
}
/**
* Writes the tools configuration file
*/
async function writeToolsConfig(filePath, config) {
try {
const directory = path.dirname(filePath);
if (directory) {
await fs.ensureDir(directory);
}
await fs.writeFile(filePath, JSON.stringify(config, null, 4), 'utf-8');
}
catch (error) {
throw new Error(`Could not write tools configuration file to ${filePath}: ${error}`);
}
}
/**
* Loads the tools lock file
*/
async function loadToolsLockFile(lockFilePath) {
try {
const exists = await fs.pathExists(lockFilePath);
if (!exists) {
return { tools: {} };
}
const data = await fs.readFile(lockFilePath, 'utf-8');
const parsed = JSON.parse(data);
return parsed;
}
catch (error) {
console.warn(`Warning: Could not read tools lock file ${lockFilePath}. Initializing with empty tool list.`);
return { tools: {} };
}
}
/**
* Saves the tools lock file
*/
async function saveToolsLockFile(lockFilePath, lockData) {
try {
const directory = path.dirname(lockFilePath);
if (directory) {
await fs.ensureDir(directory);
}
await fs.writeFile(lockFilePath, JSON.stringify(lockData, null, 4), 'utf-8');
}
catch (error) {
throw new Error(`Could not write tools lock file to ${lockFilePath}: ${error}`);
}
}
/**
* Updates a tool in the lock file
*/
function updateToolInLock(lockData, toolName, toolId, configHash) {
lockData.tools[toolName] = {
id: toolId,
hash: configHash
};
}
/**
* Gets a tool from the lock file
*/
function getToolFromLock(lockData, toolName) {
return lockData.tools[toolName];
}
/**
* Calculates the hash of a tool configuration
*/
function calculateToolHash(tool) {
return (0, utils_1.calculateConfigHash)(tool);
}
//# sourceMappingURL=tools.js.map