diff --git a/cli-ink.js b/cli-ink.js old mode 100644 new mode 100755 index 64ea5f1..37e530d --- a/cli-ink.js +++ b/cli-ink.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --import tsx import 'dotenv/config'; import React from 'react'; import { render } from 'ink'; diff --git a/cli.js b/cli.js index 157b8d8..cdcc65b 100644 --- a/cli.js +++ b/cli.js @@ -87,7 +87,8 @@ list_files - (no/empty path means root) patch_files - (zum anlegen, ändern und löschen von Dateien) read_file - (nach zeilen) ripgrep - suchmusater und dateimuster -websearch - eine Google Suche machen mit Schlüsselwörtern` +websearch - eine Google Suche machen mit Schlüsselwörtern +` }]}; const input = [{"role": "user", "content": [ {"type": "input_text","text": userText } ]}]; diff --git a/scripts/jsx-loader.mjs b/scripts/jsx-loader.mjs new file mode 100644 index 0000000..a3250d2 --- /dev/null +++ b/scripts/jsx-loader.mjs @@ -0,0 +1,43 @@ +// ESM loader to transpile .jsx files on the fly using esbuild +// Usage: node --loader ./scripts/jsx-loader.mjs cli-ink.js + +import { readFile } from 'node:fs/promises'; +import { pathToFileURL, fileURLToPath } from 'node:url'; +import { transform } from 'esbuild'; + +/** @typedef {import('node:module').LoadHook} LoadHook */ +/** @typedef {import('node:module').ResolveHook} ResolveHook */ + +/** @type {ResolveHook} */ +export async function resolve(specifier, context, nextResolve) { + // Defer to Node's default resolver for most cases + return nextResolve(specifier, context, nextResolve); +} + +/** @type {LoadHook} */ +export async function load(url, context, nextLoad) { + // Handle .jsx sources + if (url.endsWith('.jsx')) { + const filename = fileURLToPath(url); + const source = await readFile(filename, 'utf8'); + + const result = await transform(source, { + loader: 'jsx', + format: 'esm', + jsx: 'automatic', + sourcefile: filename, + }); + + return { + format: 'module', + source: result.code, + shortCircuit: true, + }; + } + + // Fallback to default loader for everything else + return nextLoad(url, context, nextLoad); +} + + + diff --git a/scripts/register-jsx-loader.mjs b/scripts/register-jsx-loader.mjs new file mode 100644 index 0000000..f325202 --- /dev/null +++ b/scripts/register-jsx-loader.mjs @@ -0,0 +1,9 @@ +// Registers our custom JSX ESM loader using Node's stable register() API +import { register } from 'node:module'; +import { pathToFileURL } from 'node:url'; + +// Resolve relative to project root cwd +register('./scripts/jsx-loader.mjs', pathToFileURL('./')); + + + diff --git a/tools/websearch.js b/tools/websearch.js index 583f751..964c8c2 100644 --- a/tools/websearch.js +++ b/tools/websearch.js @@ -1,5 +1,11 @@ +import 'dotenv/config'; import Exa from "exa-js"; -const exa = new Exa("1513ba88-5280-402b-9da3-e060d38f96d8"); + +const exaApiKey = process.env.EXA_API_KEY; +if (!exaApiKey) { + throw new Error("Missing EXA_API_KEY environment variable for websearch"); +} +const exa = new Exa(exaApiKey); export default { type: 'function', diff --git a/tools/wget.js b/tools/wget.js index fa55cf8..dab99ae 100644 --- a/tools/wget.js +++ b/tools/wget.js @@ -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',