-
+
+
+
-
+
{{ token }}
-
- ⚠️ Context Overflow! The model ignores everything beyond this point.
+
+
+
+
⚠️ Context Limit Reached (Truncated)
-
@@ -61,7 +102,9 @@ const maxTokens = 100
const inputText = ref('Context engineering is the art of managing information.')
// Simple mock tokenizer: split by space for demonstration
+// In reality, tokens are subwords, but space-split is good enough for concept
const tokenizedText = computed(() => {
+ if (!inputText.value) return []
return inputText.value
.trim()
.split(/\s+/)
@@ -70,43 +113,27 @@ const tokenizedText = computed(() => {
const usedTokens = computed(() => tokenizedText.value.length)
const isOverflow = computed(() => usedTokens.value > maxTokens)
-const usagePercentage = computed(() =>
- Math.min((usedTokens.value / maxTokens) * 100, 100)
-)
+const usagePercentage = computed(() => (usedTokens.value / maxTokens) * 100)
const progressBarColor = computed(() => {
- if (isOverflow.value) return '#ef4444'
- if (usagePercentage.value > 80) return '#f59e0b'
- return '#10b981'
+ if (isOverflow.value) return 'var(--vp-c-danger-1)'
+ if (usagePercentage.value > 80) return 'var(--vp-c-warning-1)'
+ return 'var(--vp-c-success-1)'
})
+const getTokenClass = (index) => {
+ if (index >= maxTokens) return 'token-overflow'
+ return `token-normal color-${index % 5}`
+}
+
const fillLorem = (count) => {
const words = [
- 'lorem',
- 'ipsum',
- 'dolor',
- 'sit',
- 'amet',
- 'consectetur',
- 'adipiscing',
- 'elit',
- 'sed',
- 'do',
- 'eiusmod',
- 'tempor',
- 'incididunt',
- 'ut',
- 'labore',
- 'et',
- 'dolore',
- 'magna',
- 'aliqua'
+ 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
+ 'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',
+ 'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua'
]
- let text = []
- for (let i = 0; i < count; i++) {
- text.push(words[Math.floor(Math.random() * words.length)])
- }
- inputText.value += (inputText.value ? ' ' : '') + text.join(' ')
+ const newText = Array.from({ length: count }, () => words[Math.floor(Math.random() * words.length)]).join(' ')
+ inputText.value = newText
}
const clear = () => {
@@ -115,7 +142,7 @@ const clear = () => {
diff --git a/docs/.vitepress/theme/components/appendix/context-engineering/SelectiveContextDemo.vue b/docs/.vitepress/theme/components/appendix/context-engineering/SelectiveContextDemo.vue
index d28c557..9053dbd 100644
--- a/docs/.vitepress/theme/components/appendix/context-engineering/SelectiveContextDemo.vue
+++ b/docs/.vitepress/theme/components/appendix/context-engineering/SelectiveContextDemo.vue
@@ -1,125 +1,190 @@
+