Remove the (ts) helper from log — Shepherd's #:log-file already
timestamps each line. Auto-append ~% in log so callers do not need
to remember. Simplify classifier? with or+and=> for the vector->list
fallback. Add classifier and thinking-disabled status to the request
log line, and include the request path in error logs.
Co-Authored-By: Claude <noreply@anthropic.com>
(string->uri (or (getenv "CLAUDE_PROXY_UPSTREAM")
"https://api.deepseek.com/anthropic")))
(string->uri (or (getenv "CLAUDE_PROXY_UPSTREAM")
"https://api.deepseek.com/anthropic")))
- (define (ts)
- (strftime "%Y-%m-%dT%H:%M:%S%z"
- (localtime (current-time))))
-
(define (log fmt . args)
(apply format
(current-error-port)
(define (log fmt . args)
(apply format
(current-error-port)
- (string-append "[claude-proxy] "
- (ts) " " fmt) args)
+ (string-append "[claude-proxy] " fmt "~%") args)
(force-output (current-error-port)))
(define (classifier? json)
(force-output (current-error-port)))
(define (classifier? json)
- (define sys
- (assoc-ref json "system"))
- (if sys
- (vector->list sys)
+ (or (and=> (assoc-ref json "system") vector->list)
'()))
(define (has? prefix)
(any (lambda (b)
'()))
(define (has? prefix)
(any (lambda (b)
(hdrs (list (list 'content-type
'application/json)
(cons 'x-api-key auth))))
(hdrs (list (list 'content-type
'application/json)
(cons 'x-api-key auth))))
- (if is? "classifier" "pass"))
+ (if is? "classifier" "pass")
+ (if is? ", thinking-disabled" ""))
(receive (rsp body-port)
(http-request url
#:method 'POST
(receive (rsp body-port)
(http-request url
#:method 'POST
(list (cons 'content-type
ct))
'())))
(list (cons 'content-type
ct))
'())))
(values (build-response #:code code
#:headers rhdrs)
body-port)))))
(lambda (k . a)
(values (build-response #:code code
#:headers rhdrs)
body-port)))))
(lambda (k . a)
+ (log "~a ~a error: ~a"
+ 'POST
+ (uri-path (request-uri req)) k)
(ok 502 "{\"error\":\"upstream unavailable\"}"))))
(_ (ok 405 "{\"error\":\"method not allowed\"}"))))
(ok 502 "{\"error\":\"upstream unavailable\"}"))))
(_ (ok 405 "{\"error\":\"method not allowed\"}"))))
- (log "listening on 127.0.0.1:~d~%" port)
+ (log "listening on 127.0.0.1:~d" port)
(run-server handler
'http
`(#:port ,port
(run-server handler
'http
`(#:port ,port