Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions tui/liii/pi/tui/interactive/app-events.scm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
) ;define

;; job 载荷:(消息 thinking-level provider model-id thinking-level-explicit?),
;; 会话内 /model 与 /thinking 切换均对下一条消息生效(对齐上游 per-request 覆盖)
;; 会话内 /model 与 /thinking 切换提供新任务的初始快照;运行中切模
;; 另由 request-selection-chan 在每次新 Provider 请求前由 prepare-request 读取最新选择
(define (%pi-app-job-payload app msg)
(list msg
(pi-app-thinking-level app)
Expand Down Expand Up @@ -323,16 +324,6 @@
) ;case
) ;define

(define (%pi-app-finish-pending-model-switch! app)
(let ((target (pi-app-pending-model-switch app)))
(when target
(%pi-app-pending-model-switch-set! app #f)
(pi-footer-clear-pending-model! (%pi-app-footer app))
(pi-app-add-assistant-text! app (string-append "已经切换到 " target))
) ;when
) ;let
) ;define

;; 非阻塞轮询来自后台 Worker 的事件流,驱动卡片实时上屏与队列结算
(define (pi-app-poll-events! app)
(let ((ch (pi-app-event-chan app)) (q (pi-app-queue app)) (has-event #f))
Expand All @@ -357,15 +348,13 @@
(when (and (> (length ev) 1) (cadr ev))
(pi-app-add-assistant-text! app "Aborted")
) ;when
(%pi-app-finish-pending-model-switch! app)
(pi-queue-finish-task! q)
(settle!)
) ;
((error)
(%pi-app-close-thinking-card! app)
(%pi-app-close-assistant-card! app)
(pi-app-add-tool-result! app "error" '() 'error (cadr ev))
(%pi-app-finish-pending-model-switch! app)
(pi-queue-finish-task! q)
(settle!)
) ;
Expand Down
54 changes: 9 additions & 45 deletions tui/liii/pi/tui/interactive/app-model.scm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
(liii pi tui interactive footer)
(liii pi tui interactive thinking)
(liii pi tui interactive app-thinking)
(liii pi tui interactive app-selection)
(liii pi tui interactive model-selector)
) ;import
(begin
Expand Down Expand Up @@ -180,55 +181,19 @@
) ;let*
) ;define

(define (%model-display-label provider model-id)
(if (and (string? provider) (not (string-null? provider)))
(string-append provider "/" model-id)
model-id
) ;if
) ;define

;; 应用模型切换(对齐上游 setModel):
;; 应用模型切换(对齐上游 setModel):无论 busy/idle 都立即生效。
;; - 状态与 footer 的 provider/model/supports 联动
;; - thinking 回退到默认级别并按模型能力收敛(不支持 reasoning 时为 off)
;; - persist? 时触发 on-save-model 持久化 settings 默认模型
;; - 完成后发布一次完整请求选择快照,Worker 在下次请求前应用
(define (%apply-model! app model persist?)
(let* ((old-provider (pi-app-provider app))
(old-model (pi-app-model app))
(old-tl (pi-app-thinking-level app))
(old-supports? (pi-app-supports-thinking? app))
(footer (%pi-app-footer app))
(old-active-node (pi-footer-active-node footer))
(busy? (not (pi-queue-idle? (pi-app-queue app))))
(provider (%model-ref model 'provider))
(model-id (%model-ref model 'id))
(changed? (not (and (equal? old-provider provider) (equal? old-model model-id)))
) ;changed?
(target-label (%model-display-label provider model-id))
) ;
(when busy?
(cond
((and changed? (not (pi-footer-pending-model footer)))
(pi-footer-set-pending-model! footer old-provider old-model old-tl
old-supports? old-active-node
) ;pi-footer-set-pending-model!
(%pi-app-pending-model-switch-set! app target-label)
) ;
((pi-footer-pending-model footer)
(let* ((pf (pi-footer-pending-model footer))
(req-provider (car pf))
(req-model (cadr pf))
) ;
(if (and (equal? req-provider provider) (equal? req-model model-id))
(begin
(pi-footer-clear-pending-model! footer)
(%pi-app-pending-model-switch-set! app #f)
) ;begin
(%pi-app-pending-model-switch-set! app target-label)
) ;if
) ;let*
) ;
) ;cond
) ;when
(pi-app-apply-model-ui! app model)
(when persist?
(let ((save (%pi-app-on-save-model app)))
Expand All @@ -242,17 +207,16 @@
(when changed?
(%record-model-change! app provider model-id)
) ;when
;; 发布运行时选择快照:Worker 在每次新 Provider 请求前读取最新项
(pi-app-publish-request-selection! app)
(%pi-app-active-selector-set! app #f)
(editor-set-focused! (pi-app-editor app) #t)
(scroll-view-invalidate! (pi-app-scroll-view app))
(container-add! (%pi-app-chat app)
(make-assistant-card
(cond ((and busy? (pi-app-pending-model-switch app))
(string-append "本轮结束之后,将会切换到 " target-label)
) ;
(persist? (string-append "Default model: " provider "/" model-id))
(else (string-append "Model: " model-id))
) ;cond
(make-assistant-card (if persist?
(string-append "Default model: " provider "/" model-id)
(string-append "Model: " model-id)
) ;if
) ;make-assistant-card
) ;container-add!
(pi-app-render! app)
Expand Down
50 changes: 50 additions & 0 deletions tui/liii/pi/tui/interactive/app-selection.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;;
;; Copyright (C) 2026 The Goldfish Scheme Authors
;;
;; Licensed under the MIT License
;;

;; 独立于 jobs-chan 的“最新请求选择”通道发布辅助(latest-wins)。
;; 集中发布规则,避免 /model 与 /thinking 各复制一套导致互相覆盖。
(define-library (liii pi tui interactive app-selection)
(export pi-app-publish-request-selection!)
(import (scheme base) (liii go) (liii tui) (liii pi tui interactive state))
(begin

;; 发布一次完整请求选择快照到 request-selection-chan(latest-wins):
;; 发布前先排空通道内未消费的旧快照,保证连续切换 A->B->C 时下一次请求只看到 C。
;; /model 与 /thinking 共用此出口,避免较早的 /model 快照覆盖较新的 /thinking 快照。
;; 发布不得长时间阻塞 TUI;通道关闭等异常以错误卡片提示,不静默吞掉。
(define (pi-app-publish-request-selection! app)
(let ((ch (pi-app-request-selection-chan app)))
;; 先排空旧快照:latest-wins
(let drain
()
(let ((old (catch #t (lambda () (chan-try-recv! ch #f)) (lambda args #f))))
(when old
(drain)
) ;when
) ;let
) ;let
(catch #t
(lambda ()
(chan-send! ch
(list (pi-app-provider app)
(pi-app-model app)
(pi-app-thinking-level app)
(pi-app-thinking-level-explicit? app)
) ;list
1000
) ;chan-send!
) ;lambda
(lambda (tag . args)
(container-add! (%pi-app-chat app)
(make-tool-card "session" '() 'error "Failed to publish model selection")
) ;container-add!
) ;lambda
) ;catch
) ;let
) ;define

) ;begin
) ;define-library
4 changes: 4 additions & 0 deletions tui/liii/pi/tui/interactive/app-thinking.scm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
(liii pi tui interactive thinking)
(liii pi tui interactive thinking-selector)
(liii pi tui interactive app-bash)
(liii pi tui interactive app-selection)
) ;import
(begin

Expand Down Expand Up @@ -75,6 +76,9 @@
(when (and (pi-app-supports-thinking? app) (not (equal? old level)))
(%record-thinking-change! app level)
) ;when
;; 显式修改 thinking 后发布当前 provider/model 的完整最新快照,
;; 避免被一个较早的 /model 快照覆盖(保证 /model 联动 thinking 不回归)
(pi-app-publish-request-selection! app)
) ;let
) ;define

Expand Down
7 changes: 5 additions & 2 deletions tui/liii/pi/tui/interactive/app.scm
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@
(bash-abort-chan (make-chan 1))
(steering-chan (make-chan 16))
(follow-up-chan (make-chan 16))
;; 独立于 jobs-chan 的“最新请求选择”通道(latest-wins):
;; /model 与 /thinking 发布完整选择快照,Worker 请求前排空应用最后一项
(request-selection-chan (make-chan 16))
(actual-record-sink (%make-pi-record-sink record-sink jobs-chan))
(app (%make-pi-app actual-term
screen
Expand Down Expand Up @@ -364,7 +367,7 @@
(and thinking-level-explicit #t)
#f
#f
#f
request-selection-chan
) ;%make-pi-app
) ;app
(ed (%make-pi-editor app tl))
Expand All @@ -385,7 +388,7 @@
;; 无自定义 handler 时启动后台 agent worker
(unless handler
(go (pi-tui-agent-worker jobs-chan event-chan abort-chan session-file
steering-chan follow-up-chan
steering-chan follow-up-chan request-selection-chan
) ;pi-tui-agent-worker
) ;go
) ;unless
Expand Down
36 changes: 8 additions & 28 deletions tui/liii/pi/tui/interactive/footer-model.scm
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
;; 右侧模型串:all-in-one 精简为 all-in-one/<chain-id>(不显示伪模型括号与
;; 自身等级),普通供应商保持 (provider) model • level;有实际节点时追加
;; " -> (provider) model • level",等级为收敛后的最终生效值。
;; opt-pending 为用户刚切换、尚未被请求确认的等级:此时在节点等级后加 "*",
;; 让用户立即看到切换已被记录、右侧仍是上一次请求的生效值。
(define (pi-footer-model-part provider model thinking-level
supports-thinking? active-node . opt-pending
) ;
(let* ((pending (if (pair? opt-pending) (car opt-pending) #f))
(aio? (equal? provider "all-in-one"))
supports-thinking? active-node
) ;pi-footer-model-part
(let* ((aio? (equal? provider "all-in-one"))
(base (if aio?
(string-append "all-in-one/" (or model ""))
(string-append (%provider-prefix provider)
Expand All @@ -50,30 +47,13 @@
) ;let*
) ;define

;; 右侧模型串(含请求进行中切换模型时的 "正在请求 -> 新切换" 双段展示):
;; 若正在请求的是 all-in-one 且已有实际节点,左侧直接展示实际节点,不出现 all-in-one/<chain-id>
;; 右侧模型串(含 all-in-one 实际节点展示)。
(define (pi-footer-right-part provider model thinking-level
supports-thinking? active-node pending-from
supports-thinking? active-node
) ;pi-footer-right-part
(let ((new-part (pi-footer-model-part provider model thinking-level
supports-thinking? active-node
) ;pi-footer-model-part
) ;new-part
) ;
(if (pair? pending-from)
(let* ((fp (list-ref pending-from 0))
(fm (list-ref pending-from 1))
(ftl (list-ref pending-from 2))
(fs? (list-ref pending-from 3))
(fnode (list-ref pending-from 4))
(aio-node (and (equal? fp "all-in-one") (%active-node-label fnode)))
(from-part (or aio-node (pi-footer-model-part fp fm ftl fs? fnode)))
) ;
(string-append from-part " -> " new-part)
) ;let*
new-part
) ;if
) ;let
(pi-footer-model-part provider model thinking-level supports-thinking?
active-node
) ;pi-footer-model-part
) ;define

(define (%provider-prefix provider)
Expand Down
40 changes: 6 additions & 34 deletions tui/liii/pi/tui/interactive/footer.scm
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
pi-footer-message pi-footer-stats pi-footer-set-stats!
pi-footer-set-token-stats! pi-footer-set-context-unknown!
pi-footer-context-window pi-footer-set-active-node! pi-footer-active-node
pi-footer-pending-model pi-footer-set-pending-model!
pi-footer-clear-pending-model!
) ;export
(import (scheme base)
(liii string)
Expand Down Expand Up @@ -75,7 +73,7 @@
(define-record-type <pi-footer-state>
(%make-pi-footer-state cwd branch provider model stats thinking-level
supports-thinking? session-name message context-info context-percent
context-window active-node pending-from
context-window active-node
) ;%make-pi-footer-state
pi-footer-state?
(cwd pi-footer-state-cwd)
Expand All @@ -101,9 +99,6 @@
) ;context-window
;; all-in-one 伪模型当前实际执行节点(provider . model . thinking-level)
(active-node pi-footer-state-active-node pi-footer-state-active-node-set!)
;; 请求进行中通过 /model 切换时,记录正在请求的原模型快照:
;; (provider model thinking-level supports-thinking? active-node) 或 #f
(pending-from pi-footer-state-pending-from pi-footer-state-pending-from-set!)
) ;define-record-type

(define (pi-footer? obj)
Expand Down Expand Up @@ -137,7 +132,6 @@
(pi-footer-state-thinking-level st)
(pi-footer-state-supports-thinking? st)
(pi-footer-state-active-node st)
(pi-footer-state-pending-from st)
) ;pi-footer-right-part
) ;right-part
(left-part
Expand Down Expand Up @@ -207,7 +201,7 @@
) ;
(component-data-set! comp
(%make-pi-footer-state cwd branch provider model stats tl supports?
session-name #f context-info 0.0 context-window active-node #f
session-name #f context-info 0.0 context-window active-node
) ;%make-pi-footer-state
) ;component-data-set!
comp
Expand Down Expand Up @@ -269,42 +263,20 @@
) ;let*
) ;define

;; all-in-one 交接后同步当前实际节点;请求中切模时更新左侧原模型节点
;; all-in-one 交接后同步当前实际节点;同时更新上下文窗口容量
(define (pi-footer-set-active-node! comp node)
(let* ((st (%footer-state comp)) (p (pi-footer-state-pending-from st)))
(if (pair? p)
(pi-footer-state-pending-from-set! st
(list (car p) (cadr p) (caddr p) (cadddr p) node)
) ;pi-footer-state-pending-from-set!
(pi-footer-state-active-node-set! st node)
) ;if
(let ((st (%footer-state comp)))
(pi-footer-state-active-node-set! st node)
(when (and (pair? node) (>= (length node) 4))
(%update-footer-cw! st (list-ref node 3))
) ;when
) ;let*
) ;let
) ;define

(define (pi-footer-active-node comp)
(pi-footer-state-active-node (%footer-state comp))
) ;define

;; 请求进行中切换模型时,记录正在请求的原模型(显示在右下角左侧)
(define (pi-footer-set-pending-model! comp provider model tl supports? . opt-node)
(let ((node (if (pair? opt-node) (car opt-node) #f)))
(pi-footer-state-pending-from-set! (%footer-state comp)
(list provider model tl supports? node)
) ;pi-footer-state-pending-from-set!
) ;let
) ;define

(define (pi-footer-clear-pending-model! comp)
(pi-footer-state-pending-from-set! (%footer-state comp) #f)
) ;define

(define (pi-footer-pending-model comp)
(pi-footer-state-pending-from (%footer-state comp))
) ;define

(define (pi-footer-set-session-name! comp session-name)
(pi-footer-state-session-name-set! (%footer-state comp) session-name)
) ;define
Expand Down
Loading
Loading