refactor: replace context_token_budget with model context_window for context trimming

The per-bot context_token_budget column was unused (no frontend UI) and
has been removed. Context trimming now derives the budget from the chat
model's context_window setting, which is already configured per model.
This commit is contained in:
Acbox
2026-04-14 21:04:42 +08:00
parent cb44408277
commit 84f1d0612a
10 changed files with 16 additions and 42 deletions
+3 -13
View File
@@ -31,7 +31,6 @@ SET language = 'auto',
memory_provider_id = NULL,
tts_model_id = NULL,
browser_context_id = NULL,
context_token_budget = NULL,
persist_full_tool_results = false,
updated_at = now()
WHERE id = $1
@@ -64,7 +63,6 @@ SELECT
image_models.id AS image_model_id,
tts_models.id AS tts_model_id,
browser_contexts.id AS browser_context_id,
bots.context_token_budget,
bots.persist_full_tool_results
FROM bots
LEFT JOIN models AS chat_models ON chat_models.id = bots.chat_model_id
@@ -100,7 +98,6 @@ type GetSettingsByBotIDRow struct {
ImageModelID pgtype.UUID `json:"image_model_id"`
TtsModelID pgtype.UUID `json:"tts_model_id"`
BrowserContextID pgtype.UUID `json:"browser_context_id"`
ContextTokenBudget pgtype.Int4 `json:"context_token_budget"`
PersistFullToolResults bool `json:"persist_full_tool_results"`
}
@@ -128,7 +125,6 @@ func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSe
&i.ImageModelID,
&i.TtsModelID,
&i.BrowserContextID,
&i.ContextTokenBudget,
&i.PersistFullToolResults,
)
return i, err
@@ -156,11 +152,10 @@ WITH updated AS (
image_model_id = COALESCE($17::uuid, bots.image_model_id),
tts_model_id = COALESCE($18::uuid, bots.tts_model_id),
browser_context_id = COALESCE($19::uuid, bots.browser_context_id),
context_token_budget = COALESCE($20::integer, bots.context_token_budget),
persist_full_tool_results = $21,
persist_full_tool_results = $20,
updated_at = now()
WHERE bots.id = $22
RETURNING bots.id, bots.language, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.compaction_enabled, bots.compaction_threshold, bots.compaction_ratio, bots.timezone, bots.chat_model_id, bots.heartbeat_model_id, bots.compaction_model_id, bots.title_model_id, bots.image_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id, bots.context_token_budget, bots.persist_full_tool_results
WHERE bots.id = $21
RETURNING bots.id, bots.language, bots.reasoning_enabled, bots.reasoning_effort, bots.heartbeat_enabled, bots.heartbeat_interval, bots.heartbeat_prompt, bots.compaction_enabled, bots.compaction_threshold, bots.compaction_ratio, bots.timezone, bots.chat_model_id, bots.heartbeat_model_id, bots.compaction_model_id, bots.title_model_id, bots.image_model_id, bots.search_provider_id, bots.memory_provider_id, bots.tts_model_id, bots.browser_context_id, bots.persist_full_tool_results
)
SELECT
updated.id AS bot_id,
@@ -183,7 +178,6 @@ SELECT
image_models.id AS image_model_id,
tts_models.id AS tts_model_id,
browser_contexts.id AS browser_context_id,
updated.context_token_budget,
updated.persist_full_tool_results
FROM updated
LEFT JOIN models AS chat_models ON chat_models.id = updated.chat_model_id
@@ -217,7 +211,6 @@ type UpsertBotSettingsParams struct {
ImageModelID pgtype.UUID `json:"image_model_id"`
TtsModelID pgtype.UUID `json:"tts_model_id"`
BrowserContextID pgtype.UUID `json:"browser_context_id"`
ContextTokenBudget pgtype.Int4 `json:"context_token_budget"`
PersistFullToolResults bool `json:"persist_full_tool_results"`
ID pgtype.UUID `json:"id"`
}
@@ -243,7 +236,6 @@ type UpsertBotSettingsRow struct {
ImageModelID pgtype.UUID `json:"image_model_id"`
TtsModelID pgtype.UUID `json:"tts_model_id"`
BrowserContextID pgtype.UUID `json:"browser_context_id"`
ContextTokenBudget pgtype.Int4 `json:"context_token_budget"`
PersistFullToolResults bool `json:"persist_full_tool_results"`
}
@@ -268,7 +260,6 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
arg.ImageModelID,
arg.TtsModelID,
arg.BrowserContextID,
arg.ContextTokenBudget,
arg.PersistFullToolResults,
arg.ID,
)
@@ -294,7 +285,6 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
&i.ImageModelID,
&i.TtsModelID,
&i.BrowserContextID,
&i.ContextTokenBudget,
&i.PersistFullToolResults,
)
return i, err