mycomesh-consumer 0.1.31 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,223 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -Eeuo pipefail
3
-
4
- SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
5
- COMPOSE_FILE="$SCRIPT_DIR/../consumer.compose.yml"
6
- PROJECT_NAME="mycomesh-consumer"
7
- NODE_IMAGE="${MYCOMESH_NODE_IMAGE:-}"
8
- CODEX_COMMAND="${MYCOMESH_CODEX_COMMAND:-codex}"
9
- READY_TIMEOUT="${MYCOMESH_CONSUMER_READY_TIMEOUT_SECONDS:-1800}"
10
- CONSUMER_VERSION="${MYCOMESH_CONSUMER_PROTOCOL_VERSION:-8}"
11
- PROXY_URL="${MYCOMESH_CONSUMER_PROXY:-}"
12
- NO_BROWSER=0
13
- NO_CODEX=0
14
- STOP=0
15
- RESET_LOCAL=0
16
- DRY_RUN=0
17
- CODEX_ARGS=()
18
-
19
- die() {
20
- printf 'error: %s\n' "$*" >&2
21
- exit 64
22
- }
23
-
24
- is_docker_cli() {
25
- local candidate="${1-}" version_output
26
- [[ -n "$candidate" && -x "$candidate" && ! -d "$candidate" ]] || return 1
27
- case "$candidate" in */node_modules/*) return 1 ;; esac
28
- version_output="$("$candidate" --version 2>/dev/null)" || return 1
29
- [[ "$version_output" == "Docker version "* ]] || return 1
30
- "$candidate" compose version >/dev/null 2>&1 || return 1
31
- }
32
-
33
- find_docker_cli() {
34
- local configured="${MYCOMESH_DOCKER_CLI:-}" path_entry candidate name fallback old_ifs="$IFS"
35
- if [[ -n "$configured" ]]; then
36
- candidate="$configured"
37
- [[ "$candidate" == */* ]] || candidate="$(command -v "$candidate" 2>/dev/null || true)"
38
- is_docker_cli "$candidate" || die "MYCOMESH_DOCKER_CLI is not a Docker CLI with Compose V2"
39
- printf '%s' "$candidate"
40
- return
41
- fi
42
- IFS=:
43
- for path_entry in ${PATH:-}; do
44
- [[ -n "$path_entry" ]] || path_entry=.
45
- for name in docker docker.exe; do
46
- candidate="$path_entry/$name"
47
- if is_docker_cli "$candidate"; then
48
- IFS="$old_ifs"
49
- printf '%s' "$candidate"
50
- return
51
- fi
52
- done
53
- done
54
- IFS="$old_ifs"
55
- for fallback in /usr/local/bin/docker /opt/homebrew/bin/docker /usr/bin/docker \
56
- /Applications/Docker.app/Contents/Resources/bin/docker \
57
- '/c/Program Files/Docker/Docker/resources/bin/docker.exe'; do
58
- if is_docker_cli "$fallback"; then
59
- printf '%s' "$fallback"
60
- return
61
- fi
62
- done
63
- die "Docker Desktop/Engine with Compose V2 is required"
64
- }
65
-
66
- rewrite_loopback_proxy() {
67
- local value="${1-}" scheme authority suffix userinfo host_port tail=""
68
- case "$value" in *$'\n'*|*$'\r'*) die "Consumer proxy URLs must be single-line values" ;; esac
69
- if [[ ! "$value" =~ ^([A-Za-z][A-Za-z0-9+.-]*://)([^/?#]*)(.*)$ ]]; then
70
- printf '%s' "$value"
71
- return
72
- fi
73
- scheme="${BASH_REMATCH[1]}"; authority="${BASH_REMATCH[2]}"; suffix="${BASH_REMATCH[3]}"
74
- userinfo=""; host_port="$authority"
75
- if [[ "$authority" == *@* ]]; then userinfo="${authority%@*}@"; host_port="${authority##*@}"; fi
76
- if [[ "$host_port" == "127.0.0.1" ]]; then :
77
- elif [[ "$host_port" == 127.0.0.1:* ]]; then tail="${host_port#127.0.0.1}"
78
- elif [[ "$host_port" == "[::1]" ]]; then :
79
- elif [[ "$host_port" == "[::1]:"* ]]; then tail="${host_port#\[::1\]}"
80
- elif [[ "$host_port" =~ ^[Ll][Oo][Cc][Aa][Ll][Hh][Oo][Ss][Tt](:.*)?$ ]]; then tail="${BASH_REMATCH[1]}"
81
- else printf '%s' "$value"; return
82
- fi
83
- printf '%s' "${scheme}${userinfo}host.docker.internal${tail}${suffix}"
84
- }
85
-
86
- prepare_proxy_env() {
87
- local all_proxy_value no_proxy_value
88
- all_proxy_value="${MYCOMESH_CONSUMER_ALL_PROXY:-}"
89
- export MYCOMESH_CONSUMER_HTTP_PROXY="$(rewrite_loopback_proxy "${MYCOMESH_CONSUMER_HTTP_PROXY:-$PROXY_URL}")"
90
- export MYCOMESH_CONSUMER_HTTPS_PROXY="$(rewrite_loopback_proxy "${MYCOMESH_CONSUMER_HTTPS_PROXY:-$PROXY_URL}")"
91
- export MYCOMESH_CONSUMER_ALL_PROXY="$(rewrite_loopback_proxy "$all_proxy_value")"
92
- no_proxy_value="${MYCOMESH_CONSUMER_NO_PROXY:-}"
93
- export MYCOMESH_CONSUMER_NO_PROXY="${no_proxy_value:+${no_proxy_value},}127.0.0.1,localhost,::1"
94
- export NO_PROXY="$MYCOMESH_CONSUMER_NO_PROXY"
95
- export no_proxy="$MYCOMESH_CONSUMER_NO_PROXY"
96
- }
97
-
98
- run() {
99
- if ((DRY_RUN)); then printf '+'; printf ' %q' "$@"; printf '\n'; else "$@"; fi
100
- }
101
-
102
- compose() {
103
- run "$DOCKER" compose --project-name "$PROJECT_NAME" --file "$COMPOSE_FILE" "$@"
104
- }
105
-
106
- open_browser() {
107
- local url="$1" opener=""
108
- printf 'MycoMesh Consumer credentials: %s\n' "$url"
109
- ((NO_BROWSER)) && return
110
- case "$(uname -s 2>/dev/null || printf unknown)" in
111
- Darwin) opener=open ;;
112
- Linux*) command -v xdg-open >/dev/null 2>&1 && opener=xdg-open ;;
113
- MINGW*|MSYS*|CYGWIN*)
114
- if command -v cmd.exe >/dev/null 2>&1; then cmd.exe /c start "" "$url" >/dev/null 2>&1 & return; fi ;;
115
- esac
116
- if [[ -n "$opener" ]]; then "$opener" "$url" >/dev/null 2>&1 &
117
- else printf '%s\n' "Open this URL in a browser to connect a wallet and add prepaid access."; fi
118
- }
119
-
120
- while (($#)); do
121
- case "$1" in
122
- --node-image) (($# >= 2)) || die "--node-image requires a value"; NODE_IMAGE="$2"; shift 2 ;;
123
- --codex-command) (($# >= 2)) || die "--codex-command requires a value"; CODEX_COMMAND="$2"; shift 2 ;;
124
- --ready-timeout) (($# >= 2)) || die "--ready-timeout requires a value"; READY_TIMEOUT="$2"; shift 2 ;;
125
- --proxy) (($# >= 2)) || die "--proxy requires a value"; PROXY_URL="$2"; shift 2 ;;
126
- --no-browser) NO_BROWSER=1; shift ;;
127
- --no-codex) NO_CODEX=1; shift ;;
128
- --stop) STOP=1; shift ;;
129
- --reset-local) RESET_LOCAL=1; shift ;;
130
- --dry-run) DRY_RUN=1; shift ;;
131
- --) shift; CODEX_ARGS=("$@"); break ;;
132
- *) die "unknown option: $1" ;;
133
- esac
134
- done
135
-
136
- [[ -f "$COMPOSE_FILE" ]] || die "bundled Consumer Compose file is missing"
137
- [[ "$NODE_IMAGE" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*@sha256:[a-f0-9]{64}$ ]] || die "Consumer image must be pinned by digest"
138
- [[ "$READY_TIMEOUT" =~ ^[1-9][0-9]*$ ]] || die "--ready-timeout must be a positive integer"
139
- ((READY_TIMEOUT <= 86400)) || die "--ready-timeout must not exceed 86400 seconds"
140
- case "$CONSUMER_VERSION" in
141
- 7|8) ;;
142
- *) die "MYCOMESH_CONSUMER_PROTOCOL_VERSION must be 7 or 8" ;;
143
- esac
144
-
145
- DOCKER="$(find_docker_cli)"
146
- if ((!DRY_RUN)); then "$DOCKER" info >/dev/null 2>&1 || die "Docker Engine/Desktop is not running"; fi
147
- prepare_proxy_env
148
- if [[ -n "$MYCOMESH_CONSUMER_HTTP_PROXY$MYCOMESH_CONSUMER_HTTPS_PROXY$MYCOMESH_CONSUMER_ALL_PROXY" ]]; then
149
- printf '%s\n' "Consumer network: explicit proxy"
150
- else
151
- printf '%s\n' "Consumer network: direct"
152
- fi
153
- export MYCOMESH_NODE_IMAGE="$NODE_IMAGE"
154
-
155
- if ((STOP)); then
156
- compose stop consumer
157
- printf '%s\n' "MycoMesh Consumer stopped. Its wallet and payment state remain in the Docker volume."
158
- exit 0
159
- fi
160
-
161
- if ((RESET_LOCAL)); then
162
- if ((DRY_RUN)); then
163
- printf '%s\n' "Would remove the Consumer containers, network, and protected local volume."
164
- exit 0
165
- fi
166
- printf '%s\n' "This removes the local API key, Consumer identity, wallet metadata and local payment records."
167
- printf '%s' 'Type RESET to continue: '
168
- read -r confirmation
169
- [[ "$confirmation" == RESET ]] || die "local Consumer reset cancelled"
170
- compose down --volumes --remove-orphans
171
- printf '%s\n' "Local Consumer state removed. Any pending payment authorization remains managed separately."
172
- exit 0
173
- fi
174
-
175
- compose pull consumer-volume-init consumer
176
- if ! compose up -d --wait --wait-timeout 90 consumer; then
177
- printf '%s\n' "Consumer startup failed. Check whether another process owns 127.0.0.1:8110." >&2
178
- "$DOCKER" compose --project-name "$PROJECT_NAME" --file "$COMPOSE_FILE" logs --tail=120 consumer >&2 || true
179
- exit 1
180
- fi
181
- url="http://127.0.0.1:8110/"
182
- open_browser "$url"
183
-
184
- if ((DRY_RUN || NO_CODEX)); then
185
- printf '%s\n' "MycoMesh Consumer is running at http://127.0.0.1:8110/v1"
186
- ((DRY_RUN)) && printf '%s\n' "Dry run complete; no container or Codex process was started."
187
- exit 0
188
- fi
189
-
190
- printf '%s\n' "Waiting for a healthy Settlement V${CONSUMER_VERSION} Relay..."
191
- command -v curl >/dev/null 2>&1 || die "curl is required while waiting for wallet onboarding"
192
- started_at="$(date +%s)"
193
- while ! curl --noproxy '*' --fail --silent --max-time 3 http://127.0.0.1:8110/ready >/dev/null 2>&1; do
194
- if (( $(date +%s) - started_at >= READY_TIMEOUT )); then
195
- die "timed out waiting for prepaid access; reopen $url"
196
- fi
197
- sleep 2
198
- done
199
-
200
- if ! codex_env="$("$DOCKER" compose --project-name "$PROJECT_NAME" --file "$COMPOSE_FILE" exec -T consumer sh -ec 'if [ "${MYCOMESH_CONSUMER_PROTOCOL_VERSION:-8}" = 8 ]; then exec python -m gateway.consumer_v8 codex-env; else exec python -m gateway.consumer_v7 codex-env; fi')"; then
201
- die "could not load Codex credentials from the local Consumer"
202
- fi
203
- eval "$codex_env"
204
- unset codex_env
205
- if ! command -v "$CODEX_COMMAND" >/dev/null 2>&1; then
206
- printf "error: Consumer is ready, but '%s' is not installed on this host\n" "$CODEX_COMMAND" >&2
207
- exit 127
208
- fi
209
-
210
- printf '%s\n' "Opening Codex through the local MycoMesh Consumer."
211
- codex_command=(
212
- "$CODEX_COMMAND"
213
- -c 'model="gpt-5.5"' \
214
- -c 'model_provider="mycomesh"' \
215
- -c 'model_providers.mycomesh.name="MycoMesh"' \
216
- -c 'model_providers.mycomesh.base_url="http://127.0.0.1:8110/v1"' \
217
- -c 'model_providers.mycomesh.env_key="OPENAI_API_KEY"' \
218
- -c 'model_providers.mycomesh.wire_api="responses"'
219
- )
220
- if ((${#CODEX_ARGS[@]})); then
221
- codex_command+=("${CODEX_ARGS[@]}")
222
- fi
223
- exec "${codex_command[@]}"