]> git.ekhem.eu.org Git - guix.git/commitdiff
[proxy] Refine claude-proxy: drop duplicate timestamps, simplify, add detail. main
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 11 Aug 2026 14:53:10 +0000 (14:53 +0000)
committerJakub Czajka <jakub@ekhem.eu.org>
Mon, 24 Aug 2026 15:04:50 +0000 (15:04 +0000)
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>
conf/common/claude-proxy.scm

index 5aeb52f007a4307180ba1e085becc8b4c7f6f8de..f2346db0d52a594033cafdb390e23eeb6f1208fa 100644 (file)
         (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"))
         (define blocks
         (define blocks
-          (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))))
-                            (log "~a ~a [~a]"
+                            (log "~a ~a [~a~a]"
                                  'POST path
                                  'POST path
-                                 (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))
                                                        '())))
-                                       (log " -> ~d~%" code)
+                                       (log " -> ~d" code)
                                        (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 "error: ~a~%" k)
+                          (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