From 703cedb3f521bf6a098208e285ddf405b13c6e76 Mon Sep 17 00:00:00 2001 From: lalalal Date: Sun, 24 Aug 2025 17:44:38 -0300 Subject: [PATCH 1/6] add web_fetch_exa.sh --- tools/web_fetch_exa.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tools/web_fetch_exa.sh diff --git a/tools/web_fetch_exa.sh b/tools/web_fetch_exa.sh new file mode 100755 index 0000000..ff8f63c --- /dev/null +++ b/tools/web_fetch_exa.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -e + +# @describe Fetch contents of a URI using Exa API. +# Use this when you need to get contents of a link, where you think is relevant info to be found. + +# @option --url! The query to search for. + +# @env EXA_API_KEY! The api key +# @env LLM_OUTPUT=/dev/stdout The output path The output path + +main() { +curl -X POST 'https://api.exa.ai/contents' \ + -H "x-api-key: $EXA_API_KEY" \ + -H 'Content-Type: application/json' \ + -d '{ + "urls": ["'"$argc_url"'"], + "text": true, + "type": "keyword", + "numResults": 1 + }' | \ + jq -r '.results[0].text' >> "$LLM_OUTPUT" +} + +eval "$(argc --argc-eval "$0" "$@")" From 18915badf9ac683ec82c8d136ce003746ab25018 Mon Sep 17 00:00:00 2001 From: lalalal Date: Sun, 24 Aug 2025 17:44:49 -0300 Subject: [PATCH 2/6] add web_search_exa.sh --- tools/web_search_exa.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 tools/web_search_exa.sh diff --git a/tools/web_search_exa.sh b/tools/web_search_exa.sh new file mode 100755 index 0000000..158990a --- /dev/null +++ b/tools/web_search_exa.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -e + +# @describe Perform a web search using Exa API to get up-to-date information or additional context. +# Use this when you need current information or feel a search could provide a better answer. +# Construct the query out of keywords, not human sentences, sorted by relevance - just like a good Google query. +# This returns text, then URL. Print that URL so that it's transparent where you got the info from. + +# @option --query! The query to search for. + +# @env EXA_API_KEY! The api key +# @env LLM_OUTPUT=/dev/stdout The output path The output path + +main() { +curl -X POST 'https://api.exa.ai/search' \ + -H "x-api-key: $EXA_API_KEY" \ + -H 'Content-Type: application/json' \ + -d '{ + "query": "'"$argc_query"'", + "text": true, + "type": "keyword", + "numResults": 1 + }' | \ + jq -r '.results[0] | (.text, .url)' >> "$LLM_OUTPUT" +} + +eval "$(argc --argc-eval "$0" "$@")" From 79cb61da0685ac6ac7f6c0e93c62e6bbde455e4f Mon Sep 17 00:00:00 2001 From: lalalal Date: Sun, 24 Aug 2025 18:25:20 -0300 Subject: [PATCH 3/6] update exa tools --- tools/web_fetch_exa.sh | 8 +++----- tools/web_search_exa.sh | 11 +++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tools/web_fetch_exa.sh b/tools/web_fetch_exa.sh index ff8f63c..2026df3 100755 --- a/tools/web_fetch_exa.sh +++ b/tools/web_fetch_exa.sh @@ -2,7 +2,7 @@ set -e # @describe Fetch contents of a URI using Exa API. -# Use this when you need to get contents of a link, where you think is relevant info to be found. +# Use this when you need to get contents of a link, where you think relevant info is to be found. # @option --url! The query to search for. @@ -10,14 +10,12 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path The output path main() { -curl -X POST 'https://api.exa.ai/contents' \ +curl -fsS -X POST 'https://api.exa.ai/contents' \ -H "x-api-key: $EXA_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "urls": ["'"$argc_url"'"], - "text": true, - "type": "keyword", - "numResults": 1 + "text": true }' | \ jq -r '.results[0].text' >> "$LLM_OUTPUT" } diff --git a/tools/web_search_exa.sh b/tools/web_search_exa.sh index 158990a..76793b8 100755 --- a/tools/web_search_exa.sh +++ b/tools/web_search_exa.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash set -e -# @describe Perform a web search using Exa API to get up-to-date information or additional context. +# @describe Perform a web search using Exa API to get a list of links to fetch. # Use this when you need current information or feel a search could provide a better answer. # Construct the query out of keywords, not human sentences, sorted by relevance - just like a good Google query. -# This returns text, then URL. Print that URL so that it's transparent where you got the info from. +# This returns text, then URL for every result found. Judging by the title of the page, fetch relevant info. # @option --query! The query to search for. @@ -12,16 +12,15 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path The output path main() { -curl -X POST 'https://api.exa.ai/search' \ +curl -fsS -X POST 'https://api.exa.ai/search' \ -H "x-api-key: $EXA_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "query": "'"$argc_query"'", - "text": true, "type": "keyword", - "numResults": 1 + "numResults": 20 }' | \ - jq -r '.results[0] | (.text, .url)' >> "$LLM_OUTPUT" + jq -r '.results[] | (.title, .url, "")' >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" From 2ecae50babd2c792f582a7edcec00e180c438a4e Mon Sep 17 00:00:00 2001 From: lalalal Date: Sun, 24 Aug 2025 19:07:26 -0300 Subject: [PATCH 4/6] fix prompt of web_fetch_exa --- tools/web_fetch_exa.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/web_fetch_exa.sh b/tools/web_fetch_exa.sh index 2026df3..a132b88 100755 --- a/tools/web_fetch_exa.sh +++ b/tools/web_fetch_exa.sh @@ -3,6 +3,7 @@ set -e # @describe Fetch contents of a URI using Exa API. # Use this when you need to get contents of a link, where you think relevant info is to be found. +# If you have several sources for a subject to fetch, prioritize personal blogs, PDF files, official documentation, science articles. # @option --url! The query to search for. From 688a1b0ff7c5dc3eeb758ec010fc62f0467d40ea Mon Sep 17 00:00:00 2001 From: lalalal Date: Wed, 3 Sep 2025 16:35:21 -0300 Subject: [PATCH 5/6] rename exa fetch tool to match other files --- tools/{web_fetch_exa.sh => fetch_url_via_exa.sh} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename tools/{web_fetch_exa.sh => fetch_url_via_exa.sh} (93%) diff --git a/tools/web_fetch_exa.sh b/tools/fetch_url_via_exa.sh similarity index 93% rename from tools/web_fetch_exa.sh rename to tools/fetch_url_via_exa.sh index a132b88..196ddf6 100755 --- a/tools/web_fetch_exa.sh +++ b/tools/fetch_url_via_exa.sh @@ -16,7 +16,8 @@ curl -fsS -X POST 'https://api.exa.ai/contents' \ -H 'Content-Type: application/json' \ -d '{ "urls": ["'"$argc_url"'"], - "text": true + "text": true, + "livecrawlTimeout": 10000 }' | \ jq -r '.results[0].text' >> "$LLM_OUTPUT" } From 315377dfdeef31b52cd5191247240a057fa18919 Mon Sep 17 00:00:00 2001 From: lalalal Date: Wed, 3 Sep 2025 16:35:21 -0300 Subject: [PATCH 6/6] rename exa fetch tool to match other files --- agents/openscader/index.yaml | 14 +++++++++++++ agents/openscader/tools.txt | 5 +++++ tools/execute_openscad.sh | 18 ++++++++++++++++ tools/fetch_url_via_exa.sh | 40 ++++++++++++++++++++++++++++-------- tools/web_search_exa.sh | 36 ++++++++++++++++++++++++-------- 5 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 agents/openscader/index.yaml create mode 100644 agents/openscader/tools.txt create mode 100755 tools/execute_openscad.sh diff --git a/agents/openscader/index.yaml b/agents/openscader/index.yaml new file mode 100644 index 0000000..46252ea --- /dev/null +++ b/agents/openscader/index.yaml @@ -0,0 +1,14 @@ +name: Openscader +description: openscader +version: 0.1.0 +instructions: | + You are a professional 3d designer, openscad user. You consult this cheatsheet often - https://openscad.org/cheatsheet/ + + + {{__tools__}} + + + + cwd: {{__cwd__}} + + diff --git a/agents/openscader/tools.txt b/agents/openscader/tools.txt new file mode 100644 index 0000000..01e1717 --- /dev/null +++ b/agents/openscader/tools.txt @@ -0,0 +1,5 @@ +web_search_exa.sh +fetch_url_via_exa.sh +fs_cat.sh +fs_write.sh +execute_openscad.sh diff --git a/tools/execute_openscad.sh b/tools/execute_openscad.sh new file mode 100755 index 0000000..e7b4f56 --- /dev/null +++ b/tools/execute_openscad.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +# @describe Execute the openscad file. +# @option --path! Path of the file to execute. + +# @meta require-tools openscad + +# @env LLM_OUTPUT=/dev/stdout The output path + +ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" + +main() { + openscad "$argc_path" -o /tmp/aichat_openscad.echo || true + cat /tmp/aichat_openscad.echo >> "$LLM_OUTPUT" +} + +eval "$(argc --argc-eval "$0" "$@")" diff --git a/tools/fetch_url_via_exa.sh b/tools/fetch_url_via_exa.sh index 196ddf6..839fb60 100755 --- a/tools/fetch_url_via_exa.sh +++ b/tools/fetch_url_via_exa.sh @@ -10,16 +10,38 @@ set -e # @env EXA_API_KEY! The api key # @env LLM_OUTPUT=/dev/stdout The output path The output path + main() { -curl -fsS -X POST 'https://api.exa.ai/contents' \ - -H "x-api-key: $EXA_API_KEY" \ - -H 'Content-Type: application/json' \ - -d '{ - "urls": ["'"$argc_url"'"], - "text": true, - "livecrawlTimeout": 10000 - }' | \ - jq -r '.results[0].text' >> "$LLM_OUTPUT" + # Make the API request and capture the full response + response=$(curl -fsS -X POST 'https://api.exa.ai/contents' \ + -H "x-api-key: $EXA_API_KEY" \ + -H 'Content-Type: application/json' \ + -d '{ + "urls": ["'"$argc_url"'"], + "text": true, + "livecrawlTimeout": 10000 + }') + + # Check if curl command succeeded + if [ $? -ne 0 ]; then + echo "Error: Failed to make API request" >> "$LLM_OUTPUT" + exit 0 + fi + + # Extract the status information + status=$(echo "$response" | jq -r '.statuses[0].status') + error_tag=$(echo "$response" | jq -r '.statuses[0].error.tag // "none"') + http_status=$(echo "$response" | jq -r '.statuses[0].error.httpStatusCode // 200') + + # Check if the status indicates an error + if [ "$status" = "error" ] || [ "$http_status" != "200" ]; then + echo "Error: This page is unavailable" >> "$LLM_OUTPUT" + exit 0 + fi + + # If successful, extract and output the text + echo "$response" | jq -r '.results[0].text' >> "$LLM_OUTPUT" } eval "$(argc --argc-eval "$0" "$@")" + diff --git a/tools/web_search_exa.sh b/tools/web_search_exa.sh index 76793b8..aa64b27 100755 --- a/tools/web_search_exa.sh +++ b/tools/web_search_exa.sh @@ -12,15 +12,33 @@ set -e # @env LLM_OUTPUT=/dev/stdout The output path The output path main() { -curl -fsS -X POST 'https://api.exa.ai/search' \ - -H "x-api-key: $EXA_API_KEY" \ - -H 'Content-Type: application/json' \ - -d '{ - "query": "'"$argc_query"'", - "type": "keyword", - "numResults": 20 - }' | \ - jq -r '.results[] | (.title, .url, "")' >> "$LLM_OUTPUT" + json_escaped_query=$(jq -R -s . <<< "$argc_query") + + response=$(curl -fsS -X POST 'https://api.exa.ai/search' \ + -H "x-api-key: $EXA_API_KEY" \ + -H 'Content-Type: application/json' \ + -d "{ + \"query\": $json_escaped_query, + \"type\": \"keyword\", + \"numResults\": 20 + }") + + # Check if curl command succeeded + if [ $? -ne 0 ]; then + echo "Error: Failed to execute search request" >> "$LLM_OUTPUT" + return 0 + fi + + # Check if response contains results + results_count=$(echo "$response" | jq -r '.results | length') + + if [ "$results_count" -eq 0 ]; then + echo "No results found for query: $argc_query" >> "$LLM_OUTPUT" + else + # Process results normally + echo "$response" | jq -r '.results[] | (.title, .url, "")' >> "$LLM_OUTPUT" + fi } + eval "$(argc --argc-eval "$0" "$@")"