Skip to content

Commit 6abe67a

Browse files
committed
init version
1 parent a96ac1c commit 6abe67a

12 files changed

+1267
-0
lines changed

.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Example environment variables for ai-toolboxx
2+
# Copy this file to .env and fill in your secrets. Do NOT commit .env with real keys.
3+
# Example:
4+
# API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
5+
6+
# API key used by endpoints' list_models commands
7+
# You can provide per-endpoint keys. If a per-endpoint key is set it will be used;
8+
# otherwise `API_KEY` will be used as a fallback.
9+
API_KEY=
10+
11+
# Per-endpoint API keys (optional)
12+
API_KEY_LITELLM=
13+
API_KEY_COPILOT=

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
.env.local
3+
# token files
4+
*token*
5+
.serena
6+
endpoints.conf

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
# ai-toolboxx
22
ai toolboxx
3+
4+
This repository contains small utilities and shell aliases for working with AI providers.
5+
6+
Files of interest:
7+
- show_gh_copilot_models.py: script to fetch GitHub Copilot "internal" token and list Copilot models (requires GITHUB_TOKEN env var).
8+
- models_server.py: small local-only HTTP server that exposes /models on 127.0.0.1:5000 and returns the Copilot models JSON. It reads GITHUB_TOKEN from the environment or from MODELS_TOKEN_FILE (file must be owner-readable only). Do not expose this server to the public internet.
9+
- claude_aliases.sh, codex_aliases.sh: shell helper scripts that set provider URLs and models list for local testing.
10+
- endpoints.conf: configuration file for AI endpoints with support for dynamic model listing.
11+
12+
## Configuration
13+
14+
### endpoints.conf
15+
16+
Configure AI endpoints in INI format with the following keys:
17+
18+
```ini
19+
[endpoint-name]
20+
endpoint=https://your-endpoint-url
21+
api_key=your-api-key # Optional, prefer using environment variables
22+
api_key_env=API_KEY_NAME # Optional, specify environment variable name for API key
23+
list_models_cmd=command-to-list-models # Optional shell command to fetch models
24+
keep_proxy_config=true # Optional, preserve proxy settings when running list_models_cmd (default: false)
25+
```
26+
27+
The `list_models_cmd` supports multiple output formats:
28+
- **Space-separated**: `echo gpt-5-mini gpt-5`
29+
- **Newline-separated**: `printf "model1\nmodel2\nmodel3"`
30+
- **JSON**: curl commands returning `{"data": [{"id": "model1"}, ...]}` or `[{"id": "model1"}, ...]`
31+
32+
#### Proxy Configuration
33+
34+
The `keep_proxy_config` setting controls how HTTP proxy environment variables are handled when executing `list_models_cmd`:
35+
36+
- **`keep_proxy_config=true`**: Proxy environment variables (`http_proxy`, `https_proxy`, `HTTP_PROXY`, `HTTPS_PROXY`, `no_proxy`, `NO_PROXY`, `all_proxy`, `ALL_PROXY`) are preserved when running the command. Use this when your model listing command needs to go through a proxy.
37+
38+
- **`keep_proxy_config=false` or not set** (default): All proxy environment variables are explicitly unset before running the command. Use this when your endpoint is directly accessible and you want to bypass any configured proxies.
39+
40+
Example:
41+
```ini
42+
[litellm]
43+
endpoint=https://10.189.8.10:4142
44+
api_key_env=API_KEY_LITELLM
45+
list_models_cmd=curl -sS -k "$endpoint/v1/models"
46+
keep_proxy_config=false # Direct access, no proxy
47+
48+
[copilot-api]
49+
endpoint=https://10.189.8.10:5000
50+
api_key_env=API_KEY_COPILOT
51+
list_models_cmd=python list_gh_copilot_models.py
52+
keep_proxy_config=true # Needs proxy to reach GitHub
53+
```
54+
55+
When executing, the scripts will display the command being run for transparency.
56+
57+
Note: Only the 'claude' and 'codex' helper scripts support selecting models via the endpoints.conf file (using the @endpoint-name notation). Other providers do not currently support model selection through endpoints.conf.
58+
59+
Quickstart
60+
1. Provide a GitHub token with repo access via environment variable:
61+
export GITHUB_TOKEN=ghp_...
62+
2. Run the local models server (binds to 127.0.0.1:5000):
63+
python3 models_server.py
64+
3. Fetch models:
65+
curl -s http://127.0.0.1:5000/models | jq .
66+
67+
Security and token handling
68+
- Never commit your GITHUB_TOKEN or MODELS_TOKEN_FILE to git. Add a .env to .gitignore.
69+
- Prefer storing the token in an OS keyring or a file readable only by the owner (chmod 600).
70+
- The server will not accept tokens over HTTP requests. It only reads tokens from environment variables or a server-side file.
71+
72+
I have included a models_server.py, a .env.example, and a .gitignore entry to help keep tokens out of version control. If you want me to create a git commit for these changes, tell me and I will create one.
73+
74+
Security reminder: Do not run the models server on a public host. It is intended for local development only.
75+
76+
Last updated on 2023-10-18 by Droid.

ai_tool_setup.sh

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env bash
2+
# ai_tool_setup.sh
3+
# Source this file from your ~/.bashrc to enable interactive claude/codex wrapper functions
4+
# Usage: source /path/to/ai_tool_setup.sh
5+
# Security: This script sources claude_aliases.sh and codex_aliases.sh which provide the full
6+
# interactive experience. API keys should be stored in endpoints.conf (see endpoints.conf.example).
7+
8+
# Resolve script directory
9+
__AI_TOOLBOXX_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
10+
CONFIG_FILE="$__AI_TOOLBOXX_DIR/endpoints.conf"
11+
12+
# Export the toolbox directory so alias scripts can use it
13+
export __AI_TOOLBOXX_DIR
14+
15+
# Load environment variables from .env via load_env.sh if available
16+
if [ -f "$__AI_TOOLBOXX_DIR/load_env.sh" ]; then
17+
# shellcheck disable=SC1091
18+
. "$__AI_TOOLBOXX_DIR/load_env.sh" >/dev/null 2>&1 || true
19+
fi
20+
21+
# Helper: list sections in endpoints.conf
22+
_ai_list_sections() {
23+
[ -f "$CONFIG_FILE" ] || return 1
24+
awk '/^\s*\[/{gsub(/\[|\]/,"",$0); print $0}' "$CONFIG_FILE"
25+
}
26+
27+
# Helper: get a key value for a section
28+
_ai_get_value() {
29+
local section="$1" key="$2"
30+
[ -f "$CONFIG_FILE" ] || return 1
31+
awk -v sec="$section" -v key="$key" '
32+
BEGIN{insec=0}
33+
/^\s*\[/{s=$0; gsub(/\[|\]/,"",s); insec=(s==sec)}
34+
insec && $0 ~ "^[ \t]*"key"[ \t]*=" { val=substr($0, index($0, "=")+1); gsub(/^[ \t]+|[ \t]+$/,"",val); print val; exit }
35+
' "$CONFIG_FILE"
36+
}
37+
38+
# If the simple awk above fails on some shells, provide a fallback parser
39+
_ai_get_value_fallback() {
40+
local section="$1" key="$2" line insec=0 val
41+
while IFS= read -r line; do
42+
# trim
43+
line="${line%%\#*}"
44+
[[ -z "$line" ]] && continue
45+
if [[ "$line" =~ ^\s*\[(.+)\]\s*$ ]]; then
46+
[[ "${BASH_REMATCH[1]}" == "$section" ]] && insec=1 || insec=0
47+
continue
48+
fi
49+
if [[ $insec -eq 1 && "$line" =~ ^\s*([^=]+)=\s*(.*)\s*$ ]]; then
50+
k="${BASH_REMATCH[1]// /}"
51+
v="${BASH_REMATCH[2]}"
52+
if [[ "$k" == "$key" ]]; then
53+
printf "%s" "$v"
54+
return 0
55+
fi
56+
fi
57+
done < "$CONFIG_FILE"
58+
return 1
59+
}
60+
61+
# Choose parser based on availability
62+
_ai_get() {
63+
local val
64+
val=$(_ai_get_value "$@" 2>/dev/null) || val=$(_ai_get_value_fallback "$@" 2>/dev/null)
65+
printf "%s" "$val"
66+
}
67+
68+
# Export helper functions so alias scripts can use them
69+
export -f _ai_list_sections
70+
export -f _ai_get_value
71+
export -f _ai_get_value_fallback
72+
export -f _ai_get
73+
74+
# Source the claude interactive helper
75+
if [ -f "$__AI_TOOLBOXX_DIR/claude_aliases.sh" ]; then
76+
# shellcheck disable=SC1091
77+
source "$__AI_TOOLBOXX_DIR/claude_aliases.sh"
78+
else
79+
echo "Warning: claude_aliases.sh not found at $__AI_TOOLBOXX_DIR/claude_aliases.sh" >&2
80+
fi
81+
82+
# Source the codex interactive helper
83+
if [ -f "$__AI_TOOLBOXX_DIR/codex_aliases.sh" ]; then
84+
# shellcheck disable=SC1091
85+
source "$__AI_TOOLBOXX_DIR/codex_aliases.sh"
86+
else
87+
echo "Warning: codex_aliases.sh not found at $__AI_TOOLBOXX_DIR/codex_aliases.sh" >&2
88+
fi
89+
90+
# Source the copilot CLI setup helper
91+
if [ -f "$__AI_TOOLBOXX_DIR/copilot_cli_setup.sh" ]; then
92+
# shellcheck disable=SC1091
93+
source "$__AI_TOOLBOXX_DIR/copilot_cli_setup.sh"
94+
else
95+
echo "Warning: copilot_cli_setup.sh not found at $__AI_TOOLBOXX_DIR/copilot_cli_setup.sh" >&2
96+
fi
97+
98+
# Source the gemini CLI setup helper
99+
if [ -f "$__AI_TOOLBOXX_DIR/gemini_cli_setup.sh" ]; then
100+
# shellcheck disable=SC1091
101+
source "$__AI_TOOLBOXX_DIR/gemini_cli_setup.sh"
102+
else
103+
echo "Warning: gemini_cli_setup.sh not found at $__AI_TOOLBOXX_DIR/gemini_cli_setup.sh" >&2
104+
fi
105+
106+
# Source the droid CLI setup helper
107+
if [ -f "$__AI_TOOLBOXX_DIR/droid_cli_setup.sh" ]; then
108+
# shellcheck disable=SC1091
109+
source "$__AI_TOOLBOXX_DIR/droid_cli_setup.sh"
110+
else
111+
echo "Warning: droid_cli_setup.sh not found at $__AI_TOOLBOXX_DIR/droid_cli_setup.sh" >&2
112+
fi
113+
114+
# If endpoints.conf doesn't exist, create an example copy next to this script
115+
if [ ! -f "$CONFIG_FILE" ] && [ -f "$__AI_TOOLBOXX_DIR/endpoints.conf.example" ]; then
116+
cp "$__AI_TOOLBOXX_DIR/endpoints.conf.example" "$CONFIG_FILE"
117+
echo "Created example config at $CONFIG_FILE. Edit it and replace placeholder api_key values."
118+
fi
119+
120+
# Prevent direct execution (only allow sourcing)
121+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
122+
echo "Error: This script must be sourced, not executed." >&2
123+
echo "Usage: source ${BASH_SOURCE[0]}" >&2
124+
exit 1
125+
fi
126+
127+
# Usage instructions
128+
cat <<USAGE
129+
130+
✓ AI Toolboxx loaded successfully!
131+
132+
To enable claude/codex wrappers automatically, add this to your ~/.bashrc:
133+
134+
source "$__AI_TOOLBOXX_DIR/ai_tool_setup.sh"
135+
136+
Available commands:
137+
- claude : Interactive Claude CLI wrapper with model selection
138+
- codex : Interactive Codex CLI wrapper with model selection
139+
- copilot : Setup and start GitHub Copilot CLI
140+
- gemini : Setup and start Google Gemini CLI
141+
- droid : Setup and start Factory.ai Droid CLI
142+
143+
Configuration:
144+
- Edit $CONFIG_FILE to configure endpoints and API keys
145+
- Use load_env.sh to set per-endpoint API key variables (API_KEY_LITELLM, API_KEY_COPILOT, etc.)
146+
147+
Security note:
148+
- API keys should be stored in endpoints.conf or environment variables
149+
- Do not commit secrets to version control
150+
151+
USAGE

0 commit comments

Comments
 (0)