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

154 lines (153 loc) 6.92 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.updateTask = exports.getTasks = exports.createTask = exports.submitToolOutputs = exports.updateHostInfo = exports.queryAgent = exports.updateAgent = exports.getAgent = exports.createAgent = exports.sendTelemetry = exports.initAxios = void 0; exports.indexFiles = indexFiles; const axios_1 = __importDefault(require("axios")); const formdata_node_1 = require("formdata-node"); const constants_1 = require("../constants"); const configManager_1 = require("../managers/configManager"); const plugins_1 = require("../utils/plugins"); const FIVE_MINUTES_MS = 5 * 60 * 1000; const TEN_MINUTES_MS = 10 * 60 * 1000; let isInitialized = false; const initAxios = () => __awaiter(void 0, void 0, void 0, function* () { const apiKey = configManager_1.ConfigManager.instance.get('api_key'); if (!apiKey) { throw new Error('API key must be set.'); } axios_1.default.defaults.baseURL = `${constants_1.API_HOST}${constants_1.API_VERSION}`; axios_1.default.defaults.timeout = TEN_MINUTES_MS; axios_1.default.defaults.headers.common['Authorization'] = `Bearer ${apiKey}`; isInitialized = true; }); exports.initAxios = initAxios; const sendTelemetry = (payload) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f; try { if (!isInitialized) { if (process.env.TFZO_DEBUG === 'true') { console.debug('[Telemetry] Not initialized, skipping send'); } return; } yield axios_1.default.post('/telemetry', payload, { timeout: 3000 }); } catch (error) { if (process.env.TFZO_DEBUG === 'true') { const axiosError = error; console.error('[Telemetry] Failed to send:', { payload: JSON.stringify(payload), request: { url: (_a = axiosError.config) === null || _a === void 0 ? void 0 : _a.url, method: (_b = axiosError.config) === null || _b === void 0 ? void 0 : _b.method, data: (_c = axiosError.config) === null || _c === void 0 ? void 0 : _c.data, }, response: { status: (_d = axiosError.response) === null || _d === void 0 ? void 0 : _d.status, statusText: (_e = axiosError.response) === null || _e === void 0 ? void 0 : _e.statusText, data: JSON.stringify(((_f = axiosError.response) === null || _f === void 0 ? void 0 : _f.data) || 'no data'), }, message: error.message, }); } } }); exports.sendTelemetry = sendTelemetry; const createAgent = (workspace, selected_config, sysinfo, engine, hostInfo) => __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, sysinfo, host: hostInfo, }); return createResponse; }); exports.createAgent = createAgent; const getAgent = (agentId) => __awaiter(void 0, void 0, void 0, function* () { const { data } = yield axios_1.default.get(`/agents/${agentId}`); return data; }); exports.getAgent = getAgent; const updateAgent = (agentId, data) => __awaiter(void 0, void 0, void 0, function* () { yield axios_1.default.put(`/agents/${agentId}`, data); }); exports.updateAgent = updateAgent; 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, }, { responseType: stream ? 'stream' : 'json', timeout: TEN_MINUTES_MS, }); return data; }); exports.queryAgent = queryAgent; const updateHostInfo = (agentId, hostInfo) => __awaiter(void 0, void 0, void 0, function* () { yield axios_1.default.put(`/agents/${agentId}/host`, hostInfo); }); exports.updateHostInfo = updateHostInfo; 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_MS : FIVE_MINUTES_MS, 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([new Uint8Array(files[i].data)]), name); } yield axios_1.default.post(`/agents/${agentId}/files/index`, data); }); } 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, status) => __awaiter(void 0, void 0, void 0, function* () { if (!agentId) throw new Error('Agent ID is required'); const response = yield axios_1.default.get(`/agents/${agentId}/tasks/${status}`); if (response.status !== 200) { throw new Error('Failed to get tasks'); } return response.data.tasks; }); exports.getTasks = getTasks; const updateTask = (agentId, taskId, data) => __awaiter(void 0, void 0, void 0, function* () { const response = yield axios_1.default.put(`/agents/${agentId}/tasks/${taskId}`, data); return response.data; }); exports.updateTask = updateTask;