Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
import type { CodexContextWindowInfo } from '@cindy/maker-core';
import type { ModelPriceOverrideTarget } from './modelPriceOverride';
import type { AgentKind, ProviderView } from '@cindy/model-providers';
export const DEFAULT_MODEL_COMPACTION_PCT = 90;
/** Decimal units, independent of locale. Bare numbers always mean exact tokens. */
export function parseContextTokenInput(input: string): number | null {
const match = input.trim().match(/^(\d+(?:\.\d+)?)\s*(k|m|万|萬|tokens?)?$/i);
if (!match) return null;
const unit = match[2]?.toLowerCase();
const places = unit === 'k' ? 3 : unit === 'm' ? 6 : unit === '万' || unit === '萬' ? 4 : 0;
const [whole, fraction = ''] = match[1].split('.');
if (/[1-9]/.test(fraction.slice(places))) return null;
const tokens = Number(whole + fraction.slice(0, places).padEnd(places, '0'));
return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : null;
}
/** Match the model row identity, removing only the provider's declared bridge prefix. */
export function modelCompactionTarget(
provider: Pick<ProviderView, 'id' | 'routing'>,
agent: AgentKind,
modelId: string,
): { providerId: string; modelId: string } {
const prefix = provider.routing[agent]?.modelPrefixes?.find((value) => modelId.startsWith(value));
return { providerId: provider.id, modelId: prefix ? modelId.slice(prefix.length) : modelId };
}
/** One model row can use different wire ids in different harnesses. */
export interface ModelContextLimitTarget extends ModelPriceOverrideTarget {
/** Read-only lookup of an existing task; never starts/resumes one. */
sessionId?: string;
relatedTargets?: ModelPriceOverrideTarget[];
}
export interface ModelContextLimitOwner {
dataOwnerId: string | null;
ownerGeneration: number;
}
export interface ModelContextLimitView {
compaction?: {
pct: number;
isCustomized: boolean;
};
codexContext?: CodexContextWindowInfo | null;
limit: number | null;
isCustomized: boolean;
/** Legacy per-harness overrides differ; an edit/reset applies to the whole row. */
mixed?: boolean;
}