UNPKG

@graphteon/juricode

Version:

We are forging the future with lines of digital steel

241 lines 9.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = require("axios"); const axios_config_1 = require("./axios-config"); class OpenHands { static getCurrentConversation() { return this.currentConversation; } static setCurrentConversation(currentConversation) { this.currentConversation = currentConversation; } static getConversationUrl(conversationId) { if (this.currentConversation?.conversation_id === conversationId) { if (this.currentConversation.url) { return this.currentConversation.url; } } return `/api/conversations/${conversationId}`; } static async getModels() { const { data } = await axios_config_1.openHands.get("/api/options/models"); return data; } static async getAgents() { const { data } = await axios_config_1.openHands.get("/api/options/agents"); return data; } static async getSecurityAnalyzers() { const { data } = await axios_config_1.openHands.get("/api/options/security-analyzers"); return data; } static async getConfig() { const { data } = await axios_config_1.openHands.get("/api/options/config"); return data; } static getConversationHeaders() { const headers = new axios_1.AxiosHeaders(); const sessionApiKey = this.currentConversation?.session_api_key; if (sessionApiKey) { headers.set("X-Session-API-Key", sessionApiKey); } return headers; } static async submitFeedback(conversationId, feedback) { const url = `/api/conversations/${conversationId}/submit-feedback`; const { data } = await axios_config_1.openHands.post(url, feedback); return data; } static async submitConversationFeedback(conversationId, rating, eventId, reason) { const url = `/feedback/conversation`; const payload = { conversation_id: conversationId, event_id: eventId, rating, reason, metadata: { source: "likert-scale" }, }; const { data } = await axios_config_1.openHands.post(url, payload); return data; } static async checkFeedbackExists(conversationId, eventId) { try { const url = `/feedback/conversation/${conversationId}/${eventId}`; const { data } = await axios_config_1.openHands.get(url); return data; } catch (error) { return { exists: false }; } } static async authenticate(appMode) { if (appMode === "oss") return true; await axios_config_1.openHands.post("/api/authenticate"); return true; } static async getWorkspaceZip(conversationId) { const url = `${this.getConversationUrl(conversationId)}/zip-directory`; const response = await axios_config_1.openHands.get(url, { responseType: "blob", headers: this.getConversationHeaders(), }); return response.data; } static async getWebHosts(conversationId) { const url = `${this.getConversationUrl(conversationId)}/web-hosts`; const response = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return Object.keys(response.data.hosts); } static async getGitHubAccessToken(code) { const { data } = await axios_config_1.openHands.post("/api/keycloak/callback", { code, }); return data; } static async getVSCodeUrl(conversationId) { const url = `${this.getConversationUrl(conversationId)}/vscode-url`; const { data } = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return data; } static async getRuntimeId(conversationId) { const url = `${this.getConversationUrl(conversationId)}/config`; const { data } = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return data; } static async getUserConversations() { const { data } = await axios_config_1.openHands.get("/api/conversations?limit=20"); return data.results; } static async deleteUserConversation(conversationId) { await axios_config_1.openHands.delete(`/api/conversations/${conversationId}`); } static async createConversation(selectedRepository, git_provider, initialUserMsg, imageUrls, replayJson, selected_branch) { const body = { repository: selectedRepository, git_provider, selected_branch, initial_user_msg: initialUserMsg, image_urls: imageUrls, replay_json: replayJson, }; const { data } = await axios_config_1.openHands.post("/api/conversations", body); return data; } static async getSuggestedTasks() { const { data } = await axios_config_1.openHands.get("/api/user/suggested-tasks"); return data; } static async createConversationFromSuggestedTask(suggestedTask) { const body = { repository: suggestedTask.repo, git_provider: suggestedTask.git_provider, image_urls: [], suggested_task: suggestedTask }; const { data } = await axios_config_1.openHands.post("/api/conversations", body); return data; } static async getConversation(conversationId) { const { data } = await axios_config_1.openHands.get(`/api/conversations/${conversationId}`); return data; } static async startConversation(conversationId, providers) { const { data } = await axios_config_1.openHands.post(`/api/conversations/${conversationId}/start`, providers ? { providers_set: providers } : {}); return data; } static async stopConversation(conversationId) { const { data } = await axios_config_1.openHands.post(`/api/conversations/${conversationId}/stop`); return data; } static async getSettings() { const { data } = await axios_config_1.openHands.get("/api/settings"); return data; } static async saveSettings(settings) { const data = await axios_config_1.openHands.post("/api/settings", settings); return data.status === 200; } static async getGitUser() { const response = await axios_config_1.openHands.get("/api/user/info"); const { data } = response; const user = { id: data.id, login: data.login, avatar_url: data.avatar_url, company: data.company, name: data.name, email: data.email, }; return user; } static async searchGitRepositories(query, per_page = 5) { const response = await axios_config_1.openHands.get("/api/user/search/repositories", { params: { query, per_page, }, }); return response.data; } static async getTrajectory(conversationId) { const url = `${this.getConversationUrl(conversationId)}/trajectory`; const { data } = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return data; } static async logout(appMode) { const endpoint = appMode === "saas" ? "/api/logout" : "/api/unset-provider-tokens"; await axios_config_1.openHands.post(endpoint); } static async getGitChanges(conversationId) { const url = `${this.getConversationUrl(conversationId)}/git/changes`; const { data } = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return data; } static async getGitChangeDiff(conversationId, path) { const url = `${this.getConversationUrl(conversationId)}/git/diff`; const { data } = await axios_config_1.openHands.get(url, { params: { path }, headers: this.getConversationHeaders(), }); return data; } static async retrieveUserGitRepositories() { const { data } = await axios_config_1.openHands.get("/api/user/repositories", { params: { sort: "pushed", }, }); return data; } static async getRepositoryBranches(repository) { const { data } = await axios_config_1.openHands.get(`/api/user/repository/branches?repository=${encodeURIComponent(repository)}`); return data; } static async getMicroagents(conversationId) { const url = `${this.getConversationUrl(conversationId)}/microagents`; const { data } = await axios_config_1.openHands.get(url, { headers: this.getConversationHeaders(), }); return data; } static async getMicroagentPrompt(conversationId, eventId) { const { data } = await axios_config_1.openHands.get(`/api/conversations/${conversationId}/remember_prompt`, { params: { event_id: eventId }, }); return data.prompt; } } OpenHands.currentConversation = null; exports.default = OpenHands; //# sourceMappingURL=open-hands.js.map