Update CLI scripts to enhance functionality and error handling. Change shebang in cli-ink.js for improved compatibility with TypeScript. Modify websearch.js to utilize EXA_API_KEY from environment variables, adding error handling for missing keys. Refactor wget.js to use ES module syntax and improve filename generation for downloaded content.
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
module.exports = async function wget(params) {
|
||||
|
||||
export async function run(args){
|
||||
const { url } = params;
|
||||
if (!url) throw new Error('missing url');
|
||||
const res = await fetch(url);
|
||||
const buffer = await res.buffer();
|
||||
const filename = url.split('/').filter(Boolean).pop() || 'index.html';
|
||||
const filename = new Date().getTime() + '.' + url.split('.').pop();
|
||||
const content = buffer.slice(0, 500).toString('utf8');
|
||||
return { filename, content };
|
||||
};
|
||||
|
||||
// metadata for the tool runner
|
||||
module.exports.meta = {
|
||||
export default {
|
||||
type: 'function',
|
||||
name: 'wget',
|
||||
description: 'Download URL to filesystem',
|
||||
|
||||
Reference in New Issue
Block a user