diff --git a/agents/base2/base2-kimi-2-7-code.ts b/agents/base2/base2-kimi-2-7-code.ts new file mode 100644 index 0000000000..d5b9af70d1 --- /dev/null +++ b/agents/base2/base2-kimi-2-7-code.ts @@ -0,0 +1,13 @@ +import { moonshotModels } from '@codebuff/common/constants/model-config' + +import { createBase2 } from './base2' + +const definition = { + ...createBase2('free', { + model: moonshotModels.kimiK27Code, + }), + id: 'base2-kimi-2-7-code', + displayName: 'Buffy the Kimi K2.7 Code Orchestrator', +} + +export default definition diff --git a/agents/types/agent-definition.ts b/agents/types/agent-definition.ts index 9355667dfd..6315dbeb17 100644 --- a/agents/types/agent-definition.ts +++ b/agents/types/agent-definition.ts @@ -436,6 +436,7 @@ export type ModelName = | 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2:nitro' | 'moonshotai/kimi-k2.6' + | 'moonshotai/kimi-k2.7-code' | 'z-ai/glm-5' | 'z-ai/glm-5.1' | 'z-ai/glm-4.6' diff --git a/bun.lock b/bun.lock index 76e855b545..45c4d27af2 100644 --- a/bun.lock +++ b/bun.lock @@ -235,7 +235,7 @@ "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], - "@emnapi/runtime": ["@emnapi/runtime@1.11.0", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-55coeOFKHv1ywEcUXJtWU5f+Jr/W5tZDvZig8DLKSwUN1JpROQ4rk/SNOQiFWmaR/VKF4zuFyW1B8JduOSv6Pg=="], + "@emnapi/runtime": ["@emnapi/runtime@1.11.1", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-vgj7R3y3Wgx24IQaGPA/R6YFXLHVMOZ0uVEyIQPaWs+rd1AzfEMXlAC22FYwO1XkKR6NPsq7mUandH8oIRdZFw=="], "@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.9.1", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ=="], @@ -587,7 +587,7 @@ "await-to-js": ["await-to-js@3.0.0", "", {}, "sha512-zJAaP9zxTcvTHRlejau3ZOY4V7SRpiByf3/dxx2uyKxxor19tpmpV2QRsTKikckwhaPmr2dVpxxMr7jOCYVp5g=="], - "axios": ["axios@1.17.0", "", { "dependencies": { "follow-redirects": "^1.16.0", "form-data": "^4.0.5", "https-proxy-agent": "^5.0.1", "proxy-from-env": "^2.1.0" } }, "sha512-J8SwNxprqqpbfenehxWYXE7CW+wM1BB4w3+N+g+/Wx40xM4rsLrfPmHHxSWIxJLYDgSY/HqlFPIYb2/S3rxafw=="], + "axios": ["axios@1.18.0", "", { "dependencies": { "follow-redirects": "^1.16.0", "form-data": "^4.0.5", "https-proxy-agent": "^5.0.1", "proxy-from-env": "^2.1.0" } }, "sha512-E32NzpYKp++W7XRe52rHiXV2ehxmh3wbdgO7MHeFM+vqxLBYHzt0ElkiImtOBxtOmyp0yoC8C6uESVV84Y2/hw=="], "bail": ["bail@2.0.2", "", {}, "sha512-0xO6mYd7JB2YesxDKplafRpsiOzPt9V02ddPCLbY1xYGPOX24NTyN50qnUxgCPcSoYMhKpAuBTjQoRZCAkUDRw=="], @@ -595,7 +595,7 @@ "base64-js": ["base64-js@1.5.1", "", {}, "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="], - "baseline-browser-mapping": ["baseline-browser-mapping@2.10.36", "", { "bin": { "baseline-browser-mapping": "dist/cli.cjs" } }, "sha512-lVq/Df7LXlO79MVaaUHztSwWiG9oXoWHlgvNS51v8Dpd4+G4/VIy6qYePTw31nAVls33nUtnfezYeLkYAak9dg=="], + "baseline-browser-mapping": ["baseline-browser-mapping@2.10.37", "", { "bin": { "baseline-browser-mapping": "dist/cli.cjs" } }, "sha512-girxaJ7WZssDOFhzCGZTDKoTa1gk6A1TbflaYTpykLJ4UU9Fz9kx1aREM8JCuoVHbL8X8T/mJg7w2oYSq72Oig=="], "binary-extensions": ["binary-extensions@2.3.0", "", {}, "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw=="], @@ -749,7 +749,7 @@ "escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="], - "eslint": ["eslint@10.4.1", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", "@eslint/config-array": "^0.23.5", "@eslint/config-helpers": "^0.6.0", "@eslint/core": "^1.2.1", "@eslint/plugin-kit": "^0.7.2", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^9.1.2", "eslint-visitor-keys": "^5.0.1", "espree": "^11.2.0", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "minimatch": "^10.2.4", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-AyIKhnOBuOAdueD7RB3xB+YeAWScb9jHsJBgH2Hcde8InP5JYhqrRR6iTMHyTEwgENK54Cp44e4v8BwNhsuHuw=="], + "eslint": ["eslint@10.5.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", "@eslint/config-array": "^0.23.5", "@eslint/config-helpers": "^0.6.0", "@eslint/core": "^1.2.1", "@eslint/plugin-kit": "^0.7.2", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^9.1.2", "eslint-visitor-keys": "^5.0.1", "espree": "^11.2.0", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "minimatch": "^10.2.4", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-1y+7C+vi12bUK1IpZeaV3gsH9fHLBmPvYmPx42pvT/E9yG0IC8g3PUZZgp0+JLJl7ZDK0flc2gc+Aw9dpCvIsQ=="], "eslint-config-prettier": ["eslint-config-prettier@9.1.2", "", { "peerDependencies": { "eslint": ">=7.0.0" }, "bin": { "eslint-config-prettier": "bin/cli.js" } }, "sha512-iI1f+D2ViGn+uvv5HuHVUamg8ll4tN+JRHGc6IJi4TP9Kl976C57fzPXgseXNs8v0iA8aSJpHsTWjDb9QJamGQ=="], @@ -835,7 +835,7 @@ "for-each": ["for-each@0.3.5", "", { "dependencies": { "is-callable": "^1.2.7" } }, "sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg=="], - "form-data": ["form-data@4.0.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w=="], + "form-data": ["form-data@4.0.6", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.4", "mime-types": "^2.1.35" } }, "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ=="], "formdata-polyfill": ["formdata-polyfill@4.0.10", "", { "dependencies": { "fetch-blob": "^3.1.2" } }, "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g=="], @@ -1311,9 +1311,9 @@ "postgres-interval": ["postgres-interval@1.2.0", "", { "dependencies": { "xtend": "^4.0.0" } }, "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ=="], - "posthog-node": ["posthog-node@5.36.17", "", { "dependencies": { "@posthog/core": "1.32.3" }, "peerDependencies": { "rxjs": "^7.0.0" }, "optionalPeers": ["rxjs"] }, "sha512-ed1LT4a9hhiFJizB6XX7dkYYLVPAFHfUpkQSns7BRxoUyhFnvMq15QENKeAOUEKQgPmnaq2I+xNLdAHN0o9eAA=="], + "posthog-node": ["posthog-node@5.37.0", "", { "dependencies": { "@posthog/core": "^1.32.3" }, "peerDependencies": { "rxjs": "^7.0.0" }, "optionalPeers": ["rxjs"] }, "sha512-wFwWGcqAqZ1WJRlNNYc92veV83d1lOQcP4Lq0q7Kar9GdZLPpiFYHeudyybYJnjZjkI9v06vLvY/Og5CZIfByg=="], - "preact": ["preact@10.24.3", "", {}, "sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA=="], + "preact": ["preact@10.29.2", "", {}, "sha512-7tNmwg/7mzzAoB/8kSg6Hl37JraAZw3Z3A0JSY7VXlZwo82Xn0G7wKbNNs2qoF4ZEEsQGTwDAroNdqKs1ofJxQ=="], "preact-render-to-string": ["preact-render-to-string@5.2.6", "", { "dependencies": { "pretty-format": "^3.8.0" }, "peerDependencies": { "preact": ">=10" } }, "sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw=="], @@ -1643,6 +1643,8 @@ "zwitch": ["zwitch@2.0.4", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="], + "@auth/core/preact": ["preact@10.24.3", "", {}, "sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA=="], + "@auth/core/preact-render-to-string": ["preact-render-to-string@6.5.11", "", { "peerDependencies": { "preact": ">=10" } }, "sha512-ubnauqoGczeGISiOh6RjX0/cdaF8v/oDXIjO85XALCQjwQP+SB4RDXXtvZ6yTYSjG+PC1QRP2AhPgCEsM2EvUw=="], "@codebuff/common/ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="], diff --git a/cli/src/components/freebuff-model-selector.tsx b/cli/src/components/freebuff-model-selector.tsx index 0f944ad5a3..b063a58094 100644 --- a/cli/src/components/freebuff-model-selector.tsx +++ b/cli/src/components/freebuff-model-selector.tsx @@ -11,6 +11,7 @@ import React, { import { Button } from './button' import { FALLBACK_FREEBUFF_MODEL_ID, + FREEBUFF_PREMIUM_SESSION_LIMIT, getFreebuffDeploymentAvailabilityLabel, getFreebuffModelsForAccessTier, isFreebuffModelAvailable, @@ -28,6 +29,10 @@ import { freebuffModelNavigationDirectionForKey, nextFreebuffModelId, } from '../utils/freebuff-model-navigation' +import { + formatFreebuffPremiumResetCountdown, + getFreebuffPremiumResetAt, +} from '../utils/freebuff-premium-reset' import { isPlainEnterKey } from '../utils/terminal-enter-detection' import type { FreebuffModelOption } from '@codebuff/common/constants/freebuff-models' @@ -36,10 +41,12 @@ import type { KeyEvent, ScrollBoxRenderable } from '@opentui/core' // Section grouping: model rows keep their product/availability tiers, but all // selectable Freebuff models share the same daily session quota. // Putting the tier on a section header lets each row drop its redundant -// "Premium"/"Unlimited" chip. The shared 0/5 counter lives in the page title -// (rendered by the parent), not the section header — this picker is purely a -// list of choices grouped by tier. Empty sections are filtered so a model set -// with no premium (or no unlimited) entries doesn't render an orphan header. +// "Premium"/"Unlimited" chip. The shared 0/5 counter renders below the picker +// (by the parent, landing only); headers carry only what the counter can't: +// "no daily limit" on UNLIMITED, and a reset countdown on PREMIUM once the +// quota is exhausted (the moment its rows grey out). Empty sections are +// filtered so a model set with no premium (or no unlimited) entries doesn't +// render an orphan header. // // `label` may be empty: limited-tier users only see the constrained model set, // so the "LIMITED" header would just leak the internal tier name without @@ -62,8 +69,8 @@ type Section = { * Space) commits the focused row. Mouse click commits in one step. * * Layout: rows are grouped into PREMIUM / UNLIMITED sections so the tier is - * visible without a per-row chip; the shared 0/5 counter sits inside the - * PREMIUM section header. Names align in a column so taglines line up across + * visible without a per-row chip; the shared 0/5 counter renders below the + * picker (by the parent). Names align in a column so taglines line up across * rows. On narrow terminals the secondary details (warning / deployment * hours) drop onto an indented second line under the row. * @@ -170,6 +177,23 @@ export const FreebuffModelSelector: React.FC = ({ const committedModelId = session?.status === 'queued' ? session.model : null const rateLimitsByModel = getRateLimitsByModel(session) + // PREMIUM-header reset countdown, shown only once the shared quota is + // exhausted — that's when the premium rows grey out, and (in the queued + // state) the only place that explains why. All premium models share one + // pool; the server replicates the same snapshot under every model id, so + // any entry has the right count. + const sharedRateLimit = rateLimitsByModel + ? Object.values(rateLimitsByModel)[0] + : undefined + const premiumExhausted = + (sharedRateLimit?.recentCount ?? 0) >= FREEBUFF_PREMIUM_SESSION_LIMIT + const premiumResetCountdown = premiumExhausted + ? formatFreebuffPremiumResetCountdown( + getFreebuffPremiumResetAt({ rateLimitsByModel, nowMs: now }), + now, + ) + : null + const BUTTON_CHROME = 4 // 2 border + 2 padding const NAME_GAP = 2 // spaces between name column and details column @@ -455,8 +479,22 @@ export const FreebuffModelSelector: React.FC = ({ marginTop: sectionIdx === 0 ? 0 : SECTION_GAP, }} > + {/* wrapMode 'none' pins headers to one row — the offset math above + assumes exactly 1 row per header, so a wrap would desync the + focused-row auto-scroll. */} {section.label && ( - {section.label} + + {section.label} + {section.key === 'premium' && premiumResetCountdown && ( + + {' '} + · resets in {premiumResetCountdown} + + )} + {section.key === 'unlimited' && ( + · no daily limit + )} + )} {section.models.map(renderModelButton)} diff --git a/cli/src/components/waiting-room-screen.tsx b/cli/src/components/waiting-room-screen.tsx index fd4e179941..b3569cf1fa 100644 --- a/cli/src/components/waiting-room-screen.tsx +++ b/cli/src/components/waiting-room-screen.tsx @@ -107,12 +107,26 @@ const formatPrivacySignalList = ( return `${labels.slice(0, -1).join(', ')}, or ${labels[labels.length - 1]}` } +/** "BR" → "Brazil". Falls back to the raw code when the runtime can't + * resolve it (malformed code, missing ICU data). */ +const formatCountryName = (countryCode: string): string => { + try { + return ( + new Intl.DisplayNames(['en'], { type: 'region' }).of(countryCode) ?? + countryCode + ) + } catch { + return countryCode + } +} + // Tone matters here: this is shown to users who, through no fault of their // own, get the smaller model set. Frame it as model *availability* ("aren't // available in BR yet"), never as restricted *access* ("limited mode", // "blocked") — clear enough to answer "why these models?" for someone who // goes looking, quiet enough to ignore for someone who doesn't. The VPN case -// is the one the user can act on, so it leads with the action. +// is the one the user can act on, so it leads with the action. Rendered +// directly under the model list — that's where "why these models?" gets asked. const getLimitedModeNotice = ( session: FreebuffSessionResponse | null, ): string | null => { @@ -133,7 +147,9 @@ const getLimitedModeNotice = ( session.ipPrivacySignals ?? undefined, )}? More models are available on a direct connection` case 'country_not_allowed': - return `Some models aren't available in ${countryCode ?? 'your region'} yet` + return `Some models aren't available in ${ + countryCode ? formatCountryName(countryCode) : 'your region' + } yet` case 'anonymized_or_unknown_country': case 'missing_client_ip': case 'unresolved_client_ip': @@ -266,19 +282,19 @@ const TakeoverPrompt: React.FC = () => { * doesn't jump once they earn their first day. */ const StreakInlineLine: React.FC<{ streak: number - marginBottom: number -}> = ({ streak, marginBottom }) => { + marginTop: number +}> = ({ streak, marginTop }) => { const theme = useTheme() if (streak <= 0) { - return + return } return ( = ({ const isQueued = session?.status === 'queued' const accessTier = session && 'accessTier' in session ? session.accessTier : 'full' + // Hidden in compact terminals: the notice is nice-to-have context, and + // below 22 rows every line competes with the picker itself. const limitedModeNotice = - accessTier === 'limited' ? getLimitedModeNotice(session) : null + accessTier === 'limited' && !compact ? getLimitedModeNotice(session) : null // 'none' = user hasn't joined any queue yet. We're in the pre-chat landing // state: show the picker with live N-in-line hints and a prompt. Picking a // model triggers joinFreebuffQueue, which POSTs and transitions us to @@ -429,18 +447,22 @@ export const WaitingRoomScreen: React.FC = ({ : logoLines + 1 /* marginBottom */ + (logoMode === 'full' ? 1 : 0) const mainPaddingRows = (logoMode === 'text' ? 1 : 0) + 1 const adRows = showAds ? AD_CARD_HEIGHT : 0 - // Streak is rendered inline as a one-line row directly under the counter - // (landing) or title (queued), with the same bottom margin as its neighbor - // so the picker still sits flush below it. - const streakLandingRows = reserveStreakSlot ? 1 + textMarginBottom : 0 - const streakQueuedRows = reserveStreakSlot ? 1 + 1 : 0 + // Status lines render below the picker, each with marginTop 1: the session + // counter (landing only), then the limited-mode notice, then the streak. + // They still eat into the picker's height budget regardless of being above + // or below it. + const streakRows = reserveStreakSlot ? 1 + 1 : 0 + const noticeRows = limitedModeNotice + ? 1 /* marginTop */ + wrappedRows(limitedModeNotice) + : 0 + const belowPickerRows = streakRows + noticeRows + const counterRows = 1 /* marginTop */ + wrappedRows(counterText) const reservedChrome = 2 + adRows + mainPaddingRows + logoBlockRows const landingTextRows = wrappedRows('Pick a model to start') + textMarginBottom + - wrappedRows(counterText) + - textMarginBottom + - streakLandingRows + counterRows + + belowPickerRows const queuedTitleText = session?.status === 'queued' && session.position === 1 ? "You're next in line" @@ -449,7 +471,7 @@ export const WaitingRoomScreen: React.FC = ({ wrappedRows(queuedTitleText) + 1 + 4 /* position panel */ + - streakQueuedRows + belowPickerRows const selectorMaxHeight = Math.max( 3, terminalHeight - @@ -491,13 +513,9 @@ export const WaitingRoomScreen: React.FC = ({ flexShrink: 0, }} > - - {limitedModeNotice && ( - - {limitedModeNotice} - - )} - + {/* Empty spacer: justifyContent space-between needs a left sibling to + keep the ✕ pushed to the right. */} +