makima-ts
Version:
Typescript SDK for Makima.
72 lines (71 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolAPI = void 0;
/**
* Class representing the Tool API.
*/
class ToolAPI {
constructor(baseUrl) {
this.baseUrl = baseUrl;
}
/**
* Get all tools in the system.
* @returns A promise resolving to the list of tools.
*/
async getAll() {
const response = await fetch(`${this.baseUrl}/tool/`, {
method: 'GET',
});
return response.json();
}
/**
* Get the details of a tool by its name.
* @param name The name of the tool.
* @returns A promise resolving to the tool details.
*/
async get(name) {
const response = await fetch(`${this.baseUrl}/tool/${encodeURIComponent(name)}`, {
method: 'GET',
});
return response.json();
}
/**
* Create a new tool with the provided details.
* @param params The tool details.
* @returns A promise resolving to the created tool.
*/
async create(params) {
const response = await fetch(`${this.baseUrl}/tool/create`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params),
});
return response.json();
}
/**
* Update the details of an existing tool by its name.
* @param name The name of the tool.
* @param params The tool details to update.
* @returns A promise resolving to the updated tool.
*/
async update(name, params) {
const response = await fetch(`${this.baseUrl}/tool/${encodeURIComponent(name)}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params),
});
return response.json();
}
/**
* Delete a tool by its name.
* @param name The name of the tool.
* @returns A promise resolving to the result of the deletion.
*/
async delete(name) {
const response = await fetch(`${this.baseUrl}/tool/${encodeURIComponent(name)}`, {
method: 'DELETE',
});
return response.json();
}
}
exports.ToolAPI = ToolAPI;