UNPKG

@2501-ai/cli

Version:

[![npm version](https://img.shields.io/npm/v/@2501-ai/cli.svg)](https://www.npmjs.com/package/@2501-ai/cli) [![HumanEval Score](https://img.shields.io/badge/HumanEval-96.95%25-brightgreen.svg)](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic

99 lines (98 loc) 4.56 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTasks = exports.createTask = exports.indexFiles = exports.submitToolOutputs = exports.queryAgent = exports.createAgent = exports.initAxios = void 0; const axios_1 = __importDefault(require("axios")); const constants_1 = require("../constants"); const conf_1 = require("../utils/conf"); const formdata_node_1 = require("formdata-node"); const init_1 = require("../commands/init"); const plugins_1 = require("../utils/plugins"); const FIVE_MINUTES_MILLIS = 5 * 60 * 1000; const TEN_MINUTES_MILLIS = 10 * 60 * 1000; const initAxios = () => __awaiter(void 0, void 0, void 0, function* () { const config = (0, conf_1.readConfig)(); if (!(config === null || config === void 0 ? void 0 : config.api_key)) { throw new Error('API key must be set.'); } axios_1.default.defaults.headers.common['Authorization'] = `Bearer ${config === null || config === void 0 ? void 0 : config.api_key}`; axios_1.default.defaults.baseURL = `${constants_1.API_HOST}${constants_1.API_VERSION}`; axios_1.default.defaults.timeout = FIVE_MINUTES_MILLIS; }); exports.initAxios = initAxios; const createAgent = (workspace, selected_config, sysinfo, engine) => __awaiter(void 0, void 0, void 0, function* () { const { data: createResponse } = yield axios_1.default.post('/agents', { workspace, configuration: selected_config.id, prompt: selected_config.prompt, engine: engine || init_1.DEFAULT_ENGINE, sysinfo, }); return createResponse; }); exports.createAgent = createAgent; const queryAgent = (agentId, changed, taskId, workspaceTree, stream) => __awaiter(void 0, void 0, void 0, function* () { const plugins = plugins_1.pluginService.getPlugins(); const { data } = yield axios_1.default.post(`/agents/${agentId}/query`, { taskId, changed, workspaceTree, stream, plugins: Object.keys(plugins).length > 0 ? JSON.stringify(plugins) : undefined, }, { responseType: stream ? 'stream' : 'json', timeout: stream ? TEN_MINUTES_MILLIS : FIVE_MINUTES_MILLIS, }); return data; }); exports.queryAgent = queryAgent; const submitToolOutputs = (agentId, taskId, toolOutputs, stream) => __awaiter(void 0, void 0, void 0, function* () { const { data } = yield axios_1.default.post(`/agents/${agentId}/submitOutput`, { taskId, tool_outputs: toolOutputs, stream, }, { timeout: stream ? TEN_MINUTES_MILLIS : FIVE_MINUTES_MILLIS, responseType: stream ? 'stream' : 'json', }); return data; }); exports.submitToolOutputs = submitToolOutputs; function indexFiles(agentId, files) { return __awaiter(this, void 0, void 0, function* () { const data = new formdata_node_1.FormData(); for (let i = 0; i < files.length; i++) { const name = files[i].path.split('/').pop(); data.set('file' + i, new Blob([files[i].data]), name); } yield axios_1.default.post(`/agents/${agentId}/files/index`, data); }); } exports.indexFiles = indexFiles; const createTask = (agentId, description) => __awaiter(void 0, void 0, void 0, function* () { if (!agentId) throw new Error('Agent ID is required'); const { data } = yield axios_1.default.post(`/agents/${agentId}/tasks`, { description, }); return data; }); exports.createTask = createTask; const getTasks = (agentId) => __awaiter(void 0, void 0, void 0, function* () { if (!agentId) throw new Error('Agent ID is required'); const { data } = yield axios_1.default.get(`/agents/${agentId}/tasks`); return data; }); exports.getTasks = getTasks;