refactor(configs): simplify OpenCode Go auth and update defaults
This commit is contained in:
+10
-40
@@ -40,40 +40,7 @@
|
|||||||
"qwen3-coder-next:cloud"))
|
"qwen3-coder-next:cloud"))
|
||||||
|
|
||||||
;; Backend opencode-go: suscripción OpenCode Go vía endpoint OpenAI-compatible.
|
;; 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
|
;; La credencial vive en la variable de entorno OPENCODE_API_KEY.
|
||||||
;; 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")))
|
|
||||||
|
|
||||||
(defvar-local kj-opencode-session-id nil
|
(defvar-local kj-opencode-session-id nil
|
||||||
"Stable OpenCode session id for this conversation buffer.")
|
"Stable OpenCode session id for this conversation buffer.")
|
||||||
@@ -93,18 +60,16 @@ limit 1"))))
|
|||||||
(kj-opencode-go-new-session-id))))
|
(kj-opencode-go-new-session-id))))
|
||||||
|
|
||||||
(defun kj-opencode-go-header (info)
|
(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
|
(append
|
||||||
(when-let* ((key (gptel--get-api-key)))
|
(when-let* ((key (gptel--get-api-key)))
|
||||||
`(("Authorization" . ,(concat "Bearer " 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)))))
|
`(("x-opencode-session" . ,(kj-opencode-go-session-id info)))))
|
||||||
|
|
||||||
(gptel-make-openai "OpenCode Go"
|
(gptel-make-openai "OpenCode Go"
|
||||||
:host "opencode.ai"
|
:host "opencode.ai"
|
||||||
:endpoint "/zen/go/v1/chat/completions"
|
:endpoint "/zen/go/v1/chat/completions"
|
||||||
:key #'kj-opencode-go-key
|
:key (getenv "OPENCODE_API_KEY")
|
||||||
:header #'kj-opencode-go-header
|
:header #'kj-opencode-go-header
|
||||||
:stream t
|
:stream t
|
||||||
:models '(deepseek-v4.1-flash deepseek-v4-pro
|
:models '(deepseek-v4.1-flash deepseek-v4-pro
|
||||||
@@ -241,7 +206,12 @@ content do not break gptel-magit."
|
|||||||
:config
|
:config
|
||||||
(setq agent-shell-opencode-authentication
|
(setq agent-shell-opencode-authentication
|
||||||
(agent-shell-opencode-make-authentication :none t))
|
(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
|
;; Header compacto
|
||||||
(setq agent-shell-header-style 'text)
|
(setq agent-shell-header-style 'text)
|
||||||
@@ -265,7 +235,7 @@ content do not break gptel-magit."
|
|||||||
(add-hook 'agent-shell-mode-hook
|
(add-hook 'agent-shell-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(remove-hook 'completion-at-point-functions #'cape-dabbrev t)
|
(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)
|
(remove-hook 'completion-at-point-functions #'comint-completion-at-point t)
|
||||||
(setq-local completion-at-point-functions
|
(setq-local completion-at-point-functions
|
||||||
(delq t completion-at-point-functions))
|
(delq t completion-at-point-functions))
|
||||||
|
|||||||
Reference in New Issue
Block a user