Skip to content

Commit 9135f22

Browse files
committed
Merge branch 'main' into fix/153-table-display-remotemd
Signed-off-by: Jenks <me@jenksguo.com>
2 parents afa7c6c + 62cb52d commit 9135f22

26 files changed

Lines changed: 924 additions & 3585 deletions

CLAUDE.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ docs/ # Main documentation content (MDX files)
8989
├── stakers/ # Staker documentation
9090
│ ├── btc_stakers/ # BTC staking guides
9191
│ │ ├── native_staking/ # Direct staking
92-
│ │ ├── liquid_staking/ # LST protocols
93-
│ │ └── campaigns/ # Staking campaigns
92+
│ │ └── liquid_staking/ # LST protocols
9493
│ └── baby_stakers/ # BABY token staking
9594
├── developers/ # Developer documentation
9695
│ ├── bitcoin_staking/ # Bitcoin staking integration
@@ -379,7 +378,7 @@ The site is organized into distinct sections for different audiences:
379378
- BTC staking program details, vigilante services
380379

381380
- **Stakers** (`/stakers/`) - User guides for all staking options
382-
- BTC Stakers: Native staking, liquid staking (LSTs), staking campaigns
381+
- BTC Stakers: Native staking, liquid staking (LSTs)
383382
- BABY Stakers: BABY token staking guides
384383

385384
- **Developers** (`/developers/`) - Technical integration guides

docs/developers/babylon_genesis_chain/chain_information.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import TabItem from '@theme/TabItem';
4444
|----------|-------|
4545
| Chain ID | `edge-devnet-1` |
4646
| Chain Name | `Babylon Edge Devnet` |
47-
| EVM Chain ID | `6901` |
4847
| Binary Name | `babylond` |
4948
| Version | `v0.6.0` |
5049
| Genesis Date | `2024-10-15` |

docs/guides/overview/babylon_genesis/networks/mainnet.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Built on the Cosmos SDK framework, Babylon Genesis introduces three key innovati
2121
- **Advanced PoS Security**: Protects against long-range attacks by anchoring states to Bitcoin's ledger.
2222

2323
### 3. Control Plane for the BSN Ecosystem
24-
- **Orchestrating Security & Liquidity**: Babylon Genesis will coordinate both economic security and liquidity for all connected Bitcoin Secured Networks, supporting robust EVM primitives and cross-network incentives via the BABY token.
24+
- **Orchestrating Security & Liquidity**: Babylon Genesis will coordinate both economic security and liquidity for all connected Bitcoin Secured Networks, enabling cross-network incentives via the BABY token.
2525

2626
BABY is the native token of Babylon Genesis, used for staking, governance, and transaction fees—and also for distributing ecosystem rewards and incentives to attract growth and developers.
2727

@@ -32,7 +32,6 @@ Babylon Genesis's mainnet ecosystem is rapidly expanding. Some notable activitie
3232
- **BTC Staking**: Over 57,000 BTC (≈$6.1 billion value at the time) have already been staked by early adopters, making Bitcoin a top-10 staking asset globally, with huge growth potential ahead.
3333
- **Bitcoin-Backed Security**: Finality Providers use staked BTC to secure Babylon Genesis and demonstrate advanced security that can be exported to other networks in future phases.
3434
- **Active Governance**: The BABY token enables decentralized protocol governance, giving the community a direct role in protocol evolution.
35-
- **EVM-Compatible dApps**: Babylon's EVM layer is currently under development and is planned for a future release. Once available, developers will be able to deploy DeFi primitives—such as liquid staking tokens (LSTs), decentralized exchanges, and lending protocols—anchored by Bitcoin-level security. Please refer to the [Babylon roadmap](https://docs.babylonchain.io/roadmap) for updates on EVM compatibility.
3635
- **Cross-chain Integrations**: Upcoming partnerships and technical integrations will onboard new L1s, rollups, and DeFi protocols as part of the expanding Bitcoin Secured Network.
3736

3837
> Ancient Babylon was a vibrant center for trade, culture, and innovation, uniting economies through a central marketplace. Babylon Genesis aims to do the same for web3: unlocking Bitcoin's security, liquidity, and community for a decentralized future.

docs/stakers/btc_stakers/campaigns/_category_.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/stakers/btc_stakers/campaigns/pioneer_nfts.mdx

Lines changed: 0 additions & 93 deletions
This file was deleted.

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@docusaurus/tsconfig": "3.7.0",
59+
"@playwright/test": "^1.58.2",
5960
"@styled-icons/bootstrap": "^10.47.0",
6061
"@styled-icons/boxicons-logos": "^10.47.0",
6162
"@swc/core": "^1.3.42",

src/components/ChatWidget.tsx

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ interface ChatSession {
3838
}
3939

4040
const STORAGE_KEY = 'babylon_ai_chat_sessions';
41-
const OLD_STORAGE_KEY = 'babylon_ai_chat_history'; // For migration
4241
const CONSENT_KEY = 'babylon_ai_chat_consent';
4342

4443
const PRIVACY_CONSENT_TEXT =
@@ -77,38 +76,23 @@ export default function ChatWidget() {
7776
return false;
7877
});
7978

80-
// State for sessions
79+
// State for sessions (with two-calendar-month expiry to match backend retention policy)
8180
const [sessions, setSessions] = useState<ChatSession[]>(() => {
8281
if (typeof window !== 'undefined') {
83-
// Try new format first
8482
const savedSessions = localStorage.getItem(STORAGE_KEY);
8583
if (savedSessions) {
8684
try {
87-
return JSON.parse(savedSessions);
85+
const parsed: ChatSession[] = JSON.parse(savedSessions);
86+
// Prune sessions older than two calendar months
87+
const cutoff = new Date();
88+
cutoff.setMonth(cutoff.getMonth() - 2);
89+
const cutoffTs = cutoff.getTime();
90+
const fresh = parsed.filter(s => s.timestamp >= cutoffTs);
91+
if (fresh.length > 0) return fresh;
8892
} catch (e) {
8993
console.error('Failed to parse sessions', e);
9094
}
9195
}
92-
93-
// Migration: Check for old format
94-
const oldHistory = localStorage.getItem(OLD_STORAGE_KEY);
95-
if (oldHistory) {
96-
try {
97-
const messages = JSON.parse(oldHistory);
98-
if (Array.isArray(messages) && messages.length > 0) {
99-
const migratedSession: ChatSession = {
100-
id: Date.now().toString(),
101-
thread_uuid: generateUUID(), // Best effort migration
102-
title: 'Previous Chat',
103-
messages: messages,
104-
timestamp: Date.now()
105-
};
106-
return [migratedSession];
107-
}
108-
} catch (e) {
109-
console.error('Failed to migrate old history', e);
110-
}
111-
}
11296
}
11397
// Default initial session
11498
return [{
@@ -141,8 +125,10 @@ export default function ChatWidget() {
141125
const [editTitle, setEditTitle] = useState('');
142126
const [tokenLimits, setTokenLimits] = useState<TokenLimits | null>(null);
143127
const [inputError, setInputError] = useState<string | null>(null);
128+
const pendingQueryRef = useRef<string | null>(null);
144129
const messagesEndRef = useRef<HTMLDivElement>(null);
145130
const abortControllerRef = useRef<AbortController | null>(null);
131+
const handleSubmitRef = useRef<(e?: React.FormEvent, directQuestion?: string) => Promise<void>>();
146132

147133
// Default fallback limits if API fails
148134
const DEFAULT_INPUT_LIMIT = 1000;
@@ -265,7 +251,7 @@ export default function ChatWidget() {
265251
if (value.trim()) {
266252
const estimatedTokens = estimateTokens(value);
267253
if (estimatedTokens > maxTokens) {
268-
setInputError(`Message too long (~${estimatedTokens}/${maxTokens} tokens).Please shorten your question.`);
254+
setInputError(`Message too long (~${estimatedTokens}/${maxTokens} tokens). Please shorten your question.`);
269255
} else if (estimatedTokens > maxTokens * 0.8) {
270256
setInputError(`Approaching limit (~${estimatedTokens}/${maxTokens} tokens)`);
271257
} else {
@@ -290,12 +276,10 @@ export default function ChatWidget() {
290276
scrollToBottom();
291277
}, [messages, isOpen, isExpanded, currentSessionId]);
292278

293-
// Persist sessions
279+
// Persist sessions (expired sessions pruned on load)
294280
useEffect(() => {
295281
if (typeof window !== 'undefined') {
296282
localStorage.setItem(STORAGE_KEY, JSON.stringify(sessions));
297-
// Clean up old key if exists
298-
localStorage.removeItem(OLD_STORAGE_KEY);
299283
}
300284
}, [sessions]);
301285

@@ -346,6 +330,42 @@ export default function ChatWidget() {
346330
};
347331
}, []);
348332

333+
// Keep handleSubmitRef in sync with latest handleSubmit
334+
useEffect(() => {
335+
handleSubmitRef.current = handleSubmit;
336+
});
337+
338+
// Listen for AI query events (from PageActionsDropdown, TextSelectionToolbar, HeroSearch)
339+
useEffect(() => {
340+
if (typeof window === 'undefined') return;
341+
342+
const handleAIQuery = (e: Event) => {
343+
const customEvent = e as CustomEvent;
344+
const question = customEvent.detail?.question;
345+
if (!question) return;
346+
347+
pendingQueryRef.current = question;
348+
openedFromHeaderRef.current = true;
349+
setIsOpen(true);
350+
setIsExpanded(true);
351+
setHasUserToggledExpand(true);
352+
};
353+
354+
window.addEventListener('babylon-ai-query', handleAIQuery);
355+
return () => window.removeEventListener('babylon-ai-query', handleAIQuery);
356+
}, []);
357+
358+
// Auto-submit pending query once the widget is open, consented, and not loading.
359+
// Uses a ref (not state) to avoid re-render cleanup killing the submission.
360+
useEffect(() => {
361+
if (!isOpen || !hasConsented || isLoading) return;
362+
const query = pendingQueryRef.current;
363+
if (!query) return;
364+
365+
pendingQueryRef.current = null;
366+
handleSubmitRef.current?.(undefined, query);
367+
}, [isOpen, hasConsented, isLoading]);
368+
349369
const createNewSession = () => {
350370
if (sessions.length >= 15) {
351371
alert("Maximum chat limit (15) reached. Please delete an old chat to start a new one.");
@@ -402,14 +422,15 @@ export default function ChatWidget() {
402422
}));
403423
};
404424

405-
const handleSubmit = async (e?: React.FormEvent) => {
425+
const handleSubmit = async (e?: React.FormEvent, directQuestion?: string) => {
406426
e?.preventDefault();
407-
if (!input.trim() || isLoading || isInputTooLong) return;
427+
const queryText = directQuestion || input;
428+
if (!queryText.trim() || isLoading || (!directQuestion && isInputTooLong)) return;
408429

409430
const userMessage: Message = {
410431
id: Date.now().toString(),
411432
role: 'user',
412-
content: input.trim()
433+
content: queryText.trim()
413434
};
414435

415436
// Create placeholder for AI response immediately

0 commit comments

Comments
 (0)