mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:07:19 +01:00
fix(inject): carry modelPref through /api/inject payload to daemon launch
501a6e7 added modelPref to the conf-file path so the daemon's auto-
launch could read it. But /api/inject didn't write model into the
pending_commands payload at all, and execute_inject's dispatch case
didn't extract it — so cloud-side dispatches still launched with
empty model and fell back to each agent's built-in default. The
conf-file fallback worked, but a user who dispatched right after
changing modelPref (before the 5-minute conf-sync) would miss it.
Three-file change makes the explicit path land:
- InjectPayload: add model?: string. Mirrors the field shape already
on LaunchAgentPayload + SwitchAgentPayload.
- /api/inject route: extract dbMatch.modelPref, include as
`model: eventModel` in the executeInject payload.
- cockpit-daemon.sh: dispatch case reads payload.model; execute_inject
accepts a 7th arg and prefers it over _conf_model_for_tab in the
auto-launch branch. Empty payload model falls through to conf.
Precedence is now: payload_model > conf model > agent's built-in
default. tsc clean, daemon syntax OK.
This commit is contained in:
3 files changed
+30
-9
No files matched your search
@@ -200,7 +200,7 @@ next: <state to resume from; empty when nothing is mid-flight>"
|
||||
}
|
||||
|
||||
execute_inject() {
|
||||
local id="$1" tab="$2" prompt="$3" prompt_key="${4:-}" prompt_label="${5:-}" payload_adapter="${6:-}"
|
||||
local id="$1" tab="$2" prompt="$3" prompt_key="${4:-}" prompt_label="${5:-}" payload_adapter="${6:-}" payload_model="${7:-}"
|
||||
|
||||
# Look up the project's directory and live adapter (process scan beats conf default).
|
||||
local adapter="claude" project_dir=""
|
||||
@@ -243,12 +243,16 @@ execute_inject() {
|
||||
# before injecting. Otherwise the prompt gets typed into a bare shell.
|
||||
if [ -n "$project_dir" ] && type _is_agent_running_in_dir >/dev/null 2>&1 \
|
||||
&& ! _is_agent_running_in_dir "$adapter" "$project_dir"; then
|
||||
# Honor user_projects.modelPref via the 4th column of agent-projects.conf
|
||||
# (synced from /api/agent/projects). Without this the launch always used
|
||||
# the agent's built-in default, so a Codex project pinned to gpt-5 still
|
||||
# launched as gpt-5.4 and a Gemini project pinned to flash launched 1.5-pro.
|
||||
local _model=""
|
||||
if type _conf_model_for_tab >/dev/null 2>&1; then
|
||||
# Honor user_projects.modelPref. Precedence:
|
||||
# 1. payload_model — explicit caller choice (cloud /api/inject now
|
||||
# passes it from dbMatch.modelPref; future direct callers can pin).
|
||||
# 2. _conf_model_for_tab — agent-projects.conf 4th column (synced from
|
||||
# /api/agent/projects on a 5-minute cycle).
|
||||
# Without this the launch fell back to each agent's built-in default —
|
||||
# a Codex project pinned to gpt-5 launched as gpt-5.4, a Gemini project
|
||||
# pinned to flash launched 1.5-pro.
|
||||
local _model="$payload_model"
|
||||
if [ -z "$_model" ] && type _conf_model_for_tab >/dev/null 2>&1; then
|
||||
_model=$(_conf_model_for_tab "$tab" 2>/dev/null || true)
|
||||
fi
|
||||
local _launch_cmd
|
||||
@@ -1330,7 +1334,8 @@ while true; do
|
||||
printf '%s' "$run_id" > "$(_brand_tmp "run-${tab}")"
|
||||
fi
|
||||
payload_adapter=$(echo "$payload" | jq -r '.adapter // empty')
|
||||
execute_inject "$id" "$tab" "$prompt" "$prompt_key" "$prompt_label" "$payload_adapter"
|
||||
payload_model=$(echo "$payload" | jq -r '.model // empty')
|
||||
execute_inject "$id" "$tab" "$prompt" "$prompt_key" "$prompt_label" "$payload_adapter" "$payload_model"
|
||||
;;
|
||||
focus_tab)
|
||||
tab=$(echo "$payload" | jq -r '.tab')
|
||||
|
||||
@@ -87,6 +87,14 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// Model override from user_projects.modelPref. The daemon's execute_inject
|
||||
// auto-launch reads payload.model and prefers it over the conf-file model,
|
||||
// so a project pinned to "opus" launches Claude with the opus model and a
|
||||
// Codex project pinned to "gpt-5" gets gpt-5 instead of the daemon's
|
||||
// hardcoded gpt-5.4 default. Caller-supplied model (none yet, but kept for
|
||||
// future explicit dispatch) is not in this route's schema — pure DB read.
|
||||
const eventModel = dbMatch.modelPref?.trim() || undefined;
|
||||
|
||||
let prompt: string;
|
||||
let promptLabel = "Custom";
|
||||
let effectiveTab = canonical;
|
||||
@@ -200,7 +208,7 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
const result = await executeInject(
|
||||
{ tab: effectiveTab, prompt, promptKey, promptLabel, adapter: eventAdapter, projectId, projectKey: canonical },
|
||||
{ tab: effectiveTab, prompt, promptKey, promptLabel, adapter: eventAdapter, model: eventModel, projectId, projectKey: canonical },
|
||||
userId,
|
||||
injectFn ?? (() => Promise.reject(new Error("Runtime unavailable"))),
|
||||
);
|
||||
|
||||
@@ -26,6 +26,14 @@ export type InjectPayload = {
|
||||
promptKey?: string;
|
||||
promptLabel?: string;
|
||||
adapter?: string;
|
||||
/**
|
||||
* Model override for the dispatched agent (e.g. "opus", "flash", "gpt-5").
|
||||
* The daemon's execute_inject auto-launch reads this when the target tab has
|
||||
* no live agent and prefers it over the conf-file model. Matches the shape
|
||||
* already used by LaunchAgentPayload/SwitchAgentPayload — adding it here so
|
||||
* /api/inject can honor user_projects.modelPref end-to-end.
|
||||
*/
|
||||
model?: string;
|
||||
projectId?: string | null;
|
||||
projectKey?: string;
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user