Contexts
Release rolling / release (push) Successful in 9m38s

This commit is contained in:
2026-08-18 21:29:16 -04:00
parent 6886335351
commit 7184b17553
10 changed files with 351 additions and 152 deletions
+99 -48
View File
@@ -2251,7 +2251,8 @@ async function bareAgentResetChatSession(ctx, paths, argv0) {
*/
const BARE_AGENT_QVAC_CTX_QWEN3 = 32768
const BARE_AGENT_QVAC_CTX_LLAMA32_1B = 131072
const BARE_AGENT_QVAC_CTX_ABSOLUTE_MAX = 131072
const BARE_AGENT_QVAC_CTX_QWEN35 = 262144
const BARE_AGENT_QVAC_CTX_ABSOLUTE_MAX = 262144
/**
* @typedef {{
@@ -2325,17 +2326,58 @@ const BARE_AGENT_QVAC_PROFILES = {
* @returns {number}
*/
function bareAgentQvacModelCardCtxSize(modelId) {
const id = String(modelId || '')
.trim()
.toUpperCase()
if (!id) return BARE_AGENT_QVAC_CTX_QWEN3
if (id.includes('LLAMA') || id.includes('LLAMA_TOOL')) {
return BARE_AGENT_QVAC_CTX_LLAMA32_1B
const raw = String(modelId || '').trim()
if (
typeof bareAgentQvacFindChatModel === 'function' &&
raw
) {
const card = bareAgentQvacFindChatModel(raw)
const n = card && Number(card.ctxSize)
if (Number.isFinite(n) && n >= 2048) return Math.floor(n)
}
if (id.includes('QWEN3')) return BARE_AGENT_QVAC_CTX_QWEN3
const id = raw.toUpperCase()
if (!id) return BARE_AGENT_QVAC_CTX_QWEN3
if (/QWEN3[._-]?[56](?![A-Z0-9])/.test(id)) {
return BARE_AGENT_QVAC_CTX_QWEN35
}
if (/GEMMA[-_]?4/.test(id) && /31B/.test(id)) return 262144
if (/GEMMA[-_]?4/.test(id)) return 131072
if (/GPT[_-]?OSS/.test(id)) return 131072
if (/SMOLLM/.test(id)) return 8192
if (/QWEN3VL/.test(id)) return 131072
if (/LLAMA/.test(id)) return BARE_AGENT_QVAC_CTX_LLAMA32_1B
if (/QWEN3/.test(id)) return BARE_AGENT_QVAC_CTX_QWEN3
return BARE_AGENT_QVAC_CTX_QWEN3
}
/**
* Align profile + auto ctx when the selected QVAC model changes.
* qvac_ctx_size 0 means "use the model card". Stale smaller leftovers
* (32k after switching to Qwen3.5) are cleared so the next load uses
* the new window.
* @param {Record<string, unknown>} config
* @param {string} [modelId]
* @returns {Record<string, unknown>}
*/
function bareAgentQvacSyncSettingsForModel(config, modelId) {
const out = config && typeof config === 'object' ? config : {}
const id = String(
modelId || out.qvac_model || out.model || ''
).trim()
if (!id) return out
const card =
typeof bareAgentQvacFindChatModel === 'function'
? bareAgentQvacFindChatModel(id)
: null
if (card && card.profile) out.qvac_profile = card.profile
const cardCtx = bareAgentQvacModelCardCtxSize(id)
const raw = Number(out.qvac_ctx_size)
if (!Number.isFinite(raw) || raw <= 0 || raw < cardCtx) {
out.qvac_ctx_size = 0
}
return out
}
/** @returns {BareAgentQvacProfile[]} */
function bareAgentQvacProfileList() {
return Object.values(BARE_AGENT_QVAC_PROFILES)
@@ -2664,7 +2706,10 @@ function bareAgentIsQvacModelId(model) {
if (!m) return false
return (
/^QWEN/i.test(m) ||
/^LLAMA_TOOL/i.test(m) ||
/^LLAMA/i.test(m) ||
/^GEMMA/i.test(m) ||
/^GPT[_-]?OSS/i.test(m) ||
/^SMOLLM/i.test(m) ||
/QWEN3/i.test(m) ||
/LLAMA_TOOL_CALLING/i.test(m)
)
@@ -2724,21 +2769,15 @@ function bareAgentQvacResolveCtxSize(config, profile) {
(profile && profile.chatModel) ||
''
)
const cardCtx = bareAgentQvacModelCardCtxSize(modelId)
const profileCtx = Math.max(
2048,
Number(profile && profile.ctxSize) || cardCtx
)
let ctx = Math.min(
BARE_AGENT_QVAC_CTX_ABSOLUTE_MAX,
Math.max(profileCtx, cardCtx)
)
const cardCtx = Math.max(2048, bareAgentQvacModelCardCtxSize(modelId))
let ctx = Math.min(BARE_AGENT_QVAC_CTX_ABSOLUTE_MAX, cardCtx)
const raw = Number(config && config.qvac_ctx_size)
if (Number.isFinite(raw) && raw >= profileCtx) {
// 0 / missing / leftover-below-card → auto (model card).
// Explicit values at or above the card allow YaRN-style extension.
if (Number.isFinite(raw) && raw >= cardCtx) {
ctx = Math.min(BARE_AGENT_QVAC_CTX_ABSOLUTE_MAX, Math.floor(raw))
}
// Full Bare OS tool list ≈ 4.5k tokens; leave room for system + reply.
// Tools are always on for agent sessions — keep enough ctx for schemas.
if (ctx < 8192) ctx = 8192
return ctx
}
@@ -2774,27 +2813,27 @@ function bareAgentQvacResolveDeviceOpts(config) {
* Shared QVAC chat catalog + REST /models helpers (preamble for agent and discord-bot).
*/
/** @type {{ id: string, family: string, label: string, tools: boolean, ramGb: number, profile?: string }[]} */
/** @type {{ id: string, family: string, label: string, tools: boolean, ramGb: number, ctxSize: number, profile?: string }[]} */
var BARE_AGENT_QVAC_CHAT_MODELS = [
{ id: 'QWEN3_600M_INST_Q4', family: 'qwen3', label: 'Qwen3 0.6B Instruct Q4', tools: true, ramGb: 4, profile: 'lite' },
{ id: 'QWEN3_1_7B_INST_Q4', family: 'qwen3', label: 'Qwen3 1.7B Instruct Q4', tools: true, ramGb: 8, profile: 'recommended' },
{ id: 'QWEN3_4B_INST_Q4_K_M', family: 'qwen3', label: 'Qwen3 4B Instruct Q4_K_M', tools: true, ramGb: 16, profile: 'strong' },
{ id: 'QWEN3_4B_Q4_K_M', family: 'qwen3', label: 'Qwen3 4B Q4_K_M', tools: true, ramGb: 16 },
{ id: 'QWEN3_8B_INST_Q4_K_M', family: 'qwen3', label: 'Qwen3 8B Instruct Q4_K_M', tools: true, ramGb: 24 },
{ id: 'LLAMA_TOOL_CALLING_1B_INST_Q4_K', family: 'llama', label: 'Llama 3.2 1B tool-calling', tools: true, ramGb: 6, profile: 'tool-tiny' },
{ id: 'LLAMA_3_2_1B_INST_Q4_0', family: 'llama', label: 'Llama 3.2 1B Instruct Q4_0', tools: true, ramGb: 6 },
{ id: 'SMOLLM2_360M_INST_Q8', family: 'smol', label: 'SmolLM2 360M Instruct Q8', tools: false, ramGb: 3 },
{ id: 'GPT_OSS_20B_INST_Q4_K_M', family: 'gpt-oss', label: 'GPT-OSS 20B Instruct Q4_K_M', tools: true, ramGb: 24 },
{ id: 'GEMMA4_2B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 2B multimodal Q4', tools: true, ramGb: 8 },
{ id: 'GEMMA4_2B_MULTIMODAL_Q6_K', family: 'gemma', label: 'Gemma 4 2B multimodal Q6', tools: true, ramGb: 10 },
{ id: 'GEMMA4_4B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 4B multimodal Q4', tools: true, ramGb: 16 },
{ id: 'GEMMA4_31B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 31B multimodal Q4', tools: true, ramGb: 48 },
{ id: 'QWEN3VL_2B_MULTIMODAL_Q4_K', family: 'qwen3', label: 'Qwen3-VL 2B multimodal Q4', tools: true, ramGb: 10 },
{ id: 'QWEN3_5_2B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 2B multimodal Q4', tools: true, ramGb: 10 },
{ id: 'QWEN3_5_4B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 4B multimodal Q4', tools: true, ramGb: 16 },
{ id: 'QWEN3_5_0_8B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 8B multimodal Q4', tools: true, ramGb: 24 },
{ id: 'QWEN3_5_9B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 9B multimodal Q4', tools: true, ramGb: 28 },
{ id: 'QWEN3_6_27B_MULTIMODAL_Q4_K_XL', family: 'large', label: 'Qwen3.6 27B multimodal Q4', tools: true, ramGb: 48 }
{ id: 'QWEN3_600M_INST_Q4', family: 'qwen3', label: 'Qwen3 0.6B Instruct Q4', tools: true, ramGb: 4, profile: 'lite', ctxSize: 32768 },
{ id: 'QWEN3_1_7B_INST_Q4', family: 'qwen3', label: 'Qwen3 1.7B Instruct Q4', tools: true, ramGb: 8, profile: 'recommended', ctxSize: 32768 },
{ id: 'QWEN3_4B_INST_Q4_K_M', family: 'qwen3', label: 'Qwen3 4B Instruct Q4_K_M', tools: true, ramGb: 16, profile: 'strong', ctxSize: 32768 },
{ id: 'QWEN3_4B_Q4_K_M', family: 'qwen3', label: 'Qwen3 4B Q4_K_M', tools: true, ramGb: 16, ctxSize: 32768 },
{ id: 'QWEN3_8B_INST_Q4_K_M', family: 'qwen3', label: 'Qwen3 8B Instruct Q4_K_M', tools: true, ramGb: 24, ctxSize: 32768 },
{ id: 'LLAMA_TOOL_CALLING_1B_INST_Q4_K', family: 'llama', label: 'Llama 3.2 1B tool-calling', tools: true, ramGb: 6, profile: 'tool-tiny', ctxSize: 131072 },
{ id: 'LLAMA_3_2_1B_INST_Q4_0', family: 'llama', label: 'Llama 3.2 1B Instruct Q4_0', tools: true, ramGb: 6, ctxSize: 131072 },
{ id: 'SMOLLM2_360M_INST_Q8', family: 'smol', label: 'SmolLM2 360M Instruct Q8', tools: false, ramGb: 3, ctxSize: 8192 },
{ id: 'GPT_OSS_20B_INST_Q4_K_M', family: 'gpt-oss', label: 'GPT-OSS 20B Instruct Q4_K_M', tools: true, ramGb: 24, ctxSize: 131072 },
{ id: 'GEMMA4_2B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 2B multimodal Q4', tools: true, ramGb: 8, ctxSize: 131072 },
{ id: 'GEMMA4_2B_MULTIMODAL_Q6_K', family: 'gemma', label: 'Gemma 4 2B multimodal Q6', tools: true, ramGb: 10, ctxSize: 131072 },
{ id: 'GEMMA4_4B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 4B multimodal Q4', tools: true, ramGb: 16, ctxSize: 131072 },
{ id: 'GEMMA4_31B_MULTIMODAL_Q4_K_M', family: 'gemma', label: 'Gemma 4 31B multimodal Q4', tools: true, ramGb: 48, ctxSize: 262144 },
{ id: 'QWEN3VL_2B_MULTIMODAL_Q4_K', family: 'qwen3', label: 'Qwen3-VL 2B multimodal Q4', tools: true, ramGb: 10, ctxSize: 131072 },
{ id: 'QWEN3_5_2B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 2B multimodal Q4', tools: true, ramGb: 10, ctxSize: 262144 },
{ id: 'QWEN3_5_4B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 4B multimodal Q4', tools: true, ramGb: 16, ctxSize: 262144 },
{ id: 'QWEN3_5_0_8B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 0.8B multimodal Q4', tools: true, ramGb: 8, ctxSize: 262144 },
{ id: 'QWEN3_5_9B_MULTIMODAL_Q4_K_M', family: 'qwen3.5', label: 'Qwen3.5 9B multimodal Q4', tools: true, ramGb: 28, ctxSize: 262144 },
{ id: 'QWEN3_6_27B_MULTIMODAL_Q4_K_XL', family: 'large', label: 'Qwen3.6 27B multimodal Q4', tools: true, ramGb: 48, ctxSize: 262144 }
]
/** @type {Record<string, string[]>} */
@@ -2909,11 +2948,15 @@ function bareAgentHonorExplicitQvacModel(config, profile) {
if (explicit) {
out.qvac_model = explicit
out.model = explicit
const card =
typeof bareAgentQvacFindChatModel === 'function'
? bareAgentQvacFindChatModel(explicit)
: null
if (card && card.profile) out.qvac_profile = card.profile
if (typeof bareAgentQvacSyncSettingsForModel === 'function') {
bareAgentQvacSyncSettingsForModel(out, explicit)
} else {
const card =
typeof bareAgentQvacFindChatModel === 'function'
? bareAgentQvacFindChatModel(explicit)
: null
if (card && card.profile) out.qvac_profile = card.profile
}
return out
}
const fallback = String((profile && profile.chatModel) || '').trim()
@@ -2950,6 +2993,7 @@ function bareAgentApplyLiveModel(config, modelId) {
out.provider = 'qvac'
out.qvac_model = id
out.model = id
out.qvac_ctx_size = 0
return bareAgentHonorExplicitQvacModel(out, null)
}
out.backend = 'rest'
@@ -13634,9 +13678,16 @@ function bareAgentApplyProviderProfile(cfg) {
out.qvac_model = profile.chatModel
out.model = profile.chatModel
}
const rawCtx = Number(out.qvac_ctx_size)
if (!Number.isFinite(rawCtx) || rawCtx < profile.ctxSize) {
out.qvac_ctx_size = 0
if (typeof bareAgentQvacSyncSettingsForModel === 'function') {
bareAgentQvacSyncSettingsForModel(
out,
String(out.qvac_model || out.model || profile.chatModel || '')
)
} else {
const rawCtx = Number(out.qvac_ctx_size)
if (!Number.isFinite(rawCtx) || rawCtx < profile.ctxSize) {
out.qvac_ctx_size = 0
}
}
if (!String(out.qvac_main_gpu || '').trim()) out.qvac_main_gpu = 'auto'
if (typeof bareAgentSanitizeConfigForBackend === 'function') {