refactor(configs): simplify OpenCode Go auth and update defaults

This commit is contained in:
kj
2026-11-21 21:46:09 -03:00
parent 7be8455bcf
commit 67eacb1c15
+10 -40
View File
@@ -40,40 +40,7 @@
"qwen3-coder-next:cloud"))
;; Backend opencode-go: suscripción OpenCode Go vía endpoint OpenAI-compatible.
;; Las versiones actuales de opencode guardan el login de consola en su base
;; de datos SQLite (token OAuth + organización activa), no en auth.json.
(defconst kj-opencode-db-file
(expand-file-name "~/.local/share/opencode/opencode.db")
"Ruta de la base de datos SQLite de opencode.")
(defun kj-opencode-console-credentials ()
"Return (TOKEN . ORG-ID) for opencode's active console account."
(when (and (fboundp 'sqlite-select)
(file-readable-p kj-opencode-db-file))
(ignore-errors
(let ((db (sqlite-open kj-opencode-db-file t)))
(unwind-protect
(when-let* ((row (car (sqlite-select
db
"select a.access_token, s.active_org_id \
from account_state s join account a on a.id = s.active_account_id \
limit 1"))))
(cons (nth 0 row) (nth 1 row)))
(sqlite-close db))))))
(defun kj-opencode-go-key ()
"Return the credential to use for the OpenCode Go backend."
(or (car (kj-opencode-console-credentials))
(getenv "OPENCODE_CONSOLE_TOKEN")
(let ((auth (with-temp-buffer
(insert-file-contents "~/.local/share/opencode/auth.json")
(json-parse-buffer :object-type 'alist))))
(alist-get 'key (alist-get 'opencode-go auth)))))
(defun kj-opencode-go-org-id ()
"Return opencode's active workspace id, when available."
(or (cdr (kj-opencode-console-credentials))
(getenv "OPENCODE_ORG_ID")))
;; La credencial vive en la variable de entorno OPENCODE_API_KEY.
(defvar-local kj-opencode-session-id nil
"Stable OpenCode session id for this conversation buffer.")
@@ -93,18 +60,16 @@ limit 1"))))
(kj-opencode-go-new-session-id))))
(defun kj-opencode-go-header (info)
"Auth, workspace and per-conversation session headers for OpenCode Go."
"Auth and per-conversation session headers for OpenCode Go."
(append
(when-let* ((key (gptel--get-api-key)))
`(("Authorization" . ,(concat "Bearer " key))))
(when-let* ((org (kj-opencode-go-org-id)))
`(("x-opencode-org-id" . ,org)))
`(("x-opencode-session" . ,(kj-opencode-go-session-id info)))))
(gptel-make-openai "OpenCode Go"
:host "opencode.ai"
:endpoint "/zen/go/v1/chat/completions"
:key #'kj-opencode-go-key
:key (getenv "OPENCODE_API_KEY")
:header #'kj-opencode-go-header
:stream t
:models '(deepseek-v4.1-flash deepseek-v4-pro
@@ -241,7 +206,12 @@ content do not break gptel-magit."
:config
(setq agent-shell-opencode-authentication
(agent-shell-opencode-make-authentication :none t))
(setq agent-shell-opencode-default-model-id "opencode-go/qwen3.8-flash")
;; (setq agent-shell-opencode-default-model-id "opencode-go/qwen3.8-flash")
(setq agent-shell-opencode-default-model-id "opencode-go/deepseek-v4.1-flash")
(setq agent-shell-opencode-default-config-options
'(("effort" . "high")))
;; (setq agent-shell-opencode-default-model-id "openrouter/qwen/qwen3.8-flash")
;; (setq agent-shell-opencode-default-model-id "openrouter/deepseek/deepseek-v4-flash-0731")
;; Header compacto
(setq agent-shell-header-style 'text)
@@ -265,7 +235,7 @@ content do not break gptel-magit."
(add-hook 'agent-shell-mode-hook
(lambda ()
(remove-hook 'completion-at-point-functions #'cape-dabbrev t)
(remove-hook 'completion-at-point-functions #'cape-history t)
;; (remove-hook 'completion-at-point-functions #'cape-history t)
(remove-hook 'completion-at-point-functions #'comint-completion-at-point t)
(setq-local completion-at-point-functions
(delq t completion-at-point-functions))