Total Pageviews

Saturday, 10 October 2026

llm-tools-series

 Repo for my four-part series on llm tools and mcp servers.

LLM Tools Real Estate Agent - Part 4: Server-Sent Events

A production-ready AI real estate agent with real-time streaming responses using Server-Sent Events (SSE). This implementation adds streaming capabilities to the secure MCP architecture from Part 3.

📍 Current Branch: part-4-sse

This is Part 4 of a 4-part series showing the evolution from a simple chatbot to a production-ready AI agent system. This part adds real-time streaming with SSE while maintaining all security features and the frontend UI at localhost:3000.

What's New in Part 4: Server-Sent Events

Building on the secure MCP architecture from Part 3, this branch adds real-time streaming capabilities:

Key Streaming Features

  • 📡 Server-Sent Events: Real-time streaming of AI responses
  • 💭 Thinking Indicators: Visual feedback when AI is processing vs responding
  • 📝 Progressive Rendering: Stream responses character-by-character as generated
  • 🔄 Auto Reconnection: Automatic retry on connection drops
  • ⏱️ Production Timeouts: Configurable timeouts for all operations
  • 🎯 Event Types: Multiple event types (thinking, content, error, done)
  • 🔗 Connection Management: Graceful SSE connection lifecycle

Complete Feature Set

  • All features from Part 3 (JWT auth, MCP microservices, user management)
  • Real-time streaming AI responses
  • Enhanced UX with thinking indicators
  • Robust error handling and reconnection
  • Production-ready timeout configuration

Architecture

The project maintains the secure MCP microservices architecture from Part 3 with added streaming layers:

SSE Components

SSE Controller (apps/main-app/src/sse/)

  • SSE Controller: Handles streaming endpoints
  • Event Service: Manages SSE connections and events
  • Stream Manager: Coordinates multi-step streaming operations

Event Types

// Different event types sent via SSE
'thinking'    // AI is processing (tool calls, reasoning)
'content'     // Streaming response content
'error'       // Error occurred during processing
'done'        // Response completed successfully

SSE Endpoints

  • /agents/chat-stream - Protected streaming chat endpoint
  • /sse/health - SSE connection health check

Frontend Streaming Experience

The chat interface provides a smooth, real-time experience:

Real-time Features

  • Thinking Indicators: Shows "🤔 Thinking..." when AI processes requests
  • Progressive Text: Response appears character-by-character
  • Connection Status: Visual indicators for SSE connection health
  • Auto Reconnect: Seamless reconnection if connection drops

Enhanced UX Flow

  1. User sends message
  2. Shows "Thinking..." indicator
  3. Tool execution feedback (if applicable)
  4. Progressive response streaming begins
  5. Final response completion

Browser Compatibility

  • Uses native EventSource API
  • Fallback for older browsers
  • Automatic retry logic
  • Graceful degradation

Getting Started

Prerequisites

  • Node.js 18+
  • npm 9+
  • OpenRouter API key

Quick Setup

  1. Clone the repository:
git clone git@github.com:lorenseanstewart/llm-tools-series.git
cd llm-tools-series
npm run install-all  # Installs dependencies for all workspaces

Note: The default branch is part-4-sse which contains the complete project with Server-Sent Events implementation.

  1. Setup environment:

There are FOUR .env files you need to update. In the three directories within the apps directory, remove the .example part of the file name .env.example.. The main-app also needs your open router key. The fourth .env file is at the root of the project and also needs you open router key.

npm run setup

Important: You need to configure THREE .env files with matching JWT_SECRET:

  • apps/main-app/.env - Set your OpenRouter API key and JWT_SECRET
  • apps/mcp-listings/.env - Add the same JWT_SECRET
  • apps/mcp-analytics/.env - Add the same JWT_SECRET

The JWT_SECRET must be identical across all services for authentication to work.

  1. Start all services:
npm run dev

This starts:

  1. Experience real-time streaming:
  • Visit http://localhost:3000
  • Login with your credentials (or register)
  • Ask the AI agent a question
  • Watch the real-time response streaming!

SSE API Usage

Streaming Chat Endpoint

Connect to streaming chat:

# First authenticate to get JWT token
TOKEN=$(curl -X POST http://localhost:3000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "securepassword123"}' \
  | jq -r '.access_token')

# Connect to SSE stream
curl -X POST http://localhost:3000/agents/chat-stream \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: text/event-stream" \
  -H "Cache-Control: no-cache" \
  -d '{"userMessage": "Find me homes in Portland"}' \
  --no-buffer

SSE Event Format

The server sends events in this format:

event: thinking
data: {"status": "processing", "message": "Analyzing your request..."}

event: content
data: {"chunk": "I found several great properties in Portland"}

event: content  
data: {"chunk": " that match your criteria. Here are the top options:"}

event: done
data: {"status": "completed"}

JavaScript Client Example

// Connect to SSE endpoint
const eventSource = new EventSource('/agents/chat-stream', {
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

// Handle different event types
eventSource.addEventListener('thinking', (event) => {
  const data = JSON.parse(event.data);
  showThinkingIndicator(data.message);
});

eventSource.addEventListener('content', (event) => {
  const data = JSON.parse(event.data);
  appendToResponse(data.chunk);
});

eventSource.addEventListener('done', (event) => {
  hideThinkingIndicator();
  markResponseComplete();
});

eventSource.addEventListener('error', (event) => {
  handleStreamError(event);
});

Configuration

SSE Settings

// Configurable via environment variables
{
  timeout: process.env.SSE_TIMEOUT || 120000,     // 2 minutes
  keepAlive: process.env.SSE_KEEPALIVE || 30000,  // 30 seconds
  retry: process.env.SSE_RETRY || 3000            // 3 seconds
}

Streaming Options

  • Chunk Size: Configurable response chunking
  • Delay: Optional delay between chunks for demo effect
  • Buffer: Response buffering strategies

Testing Streaming

The test suite includes SSE-specific testing:

# Run all tests including SSE tests
npm run test

# Run SSE-specific tests
npm run test -w apps/main-app -- sse

# Test streaming with coverage
npm run test:cov

SSE test coverage includes:

  • Event stream creation and management
  • Authentication with streaming endpoints
  • Error handling and reconnection
  • Event type validation
  • Connection lifecycle testing

Development Tips

Testing SSE Locally

  1. Use browser dev tools Network tab to see SSE connections
  2. Monitor EventSource connection states
  3. Test connection drops and reconnection
  4. Verify event ordering and completeness

Common Issues

  • Connection drops: Check network stability and timeout settings
  • Auth failures: Ensure JWT token is valid and passed correctly
  • Event parsing: Verify JSON format in event data
  • Browser limits: Be aware of concurrent SSE connection limits

Performance Considerations

  • SSE connections are long-lived
  • Monitor server memory usage with many concurrent connections
  • Consider connection pooling for production
  • Implement proper cleanup on client disconnect

Next Steps

Congratulations! You've completed the full series. Here's what you've learned:

  • Part 1: part-1-chatbot-to-agent - Foundation with direct tool integration
  • Part 2: part-2-mcp-scaling - Microservices with MCP
  • Part 3: part-3-mcp-security - JWT authentication and security
  • Part 4: part-4-sse - Real-time streaming with Server-Sent Events

Production Deployment

This Part 4 implementation is production-ready with:

  • Secure authentication
  • Scalable microservices
  • Real-time user experience
  • Comprehensive error handling
  • Full test coverage

from  https://github.com/lorenseanstewart/llm-tools-series

让instinct帮我在render.com平台构建基于nextjs的静态博客程序vbb

 




我得到的博客网址是:

https://vbb-y9yd.onrender.com/(此是instinct帮我成功构建的。)

https://vbb-y9yd.onrender.com/posts ,支持分页。(这是我要instinct帮我实现的,程序作者并未实现这一点)

项目地址:

https://github.com/vikiboss/blog

 https://github.com/brightmann/vbb

在这里:https://github.com/brightmann/vbb/tree/main/posts/2026 ,新建源帖fh.md ,内容为:

---
title: '战马'
date: 2026-10-10T07:20
topic: '技术'
excerpt: '这是一篇文章'
tags:
  - 'misc1'
  - 'misc2'
  - 'misc3'
---

此处写正文或html codes

(详见 https://github.com/brightmann/vbb/blob/main/posts/2026/fh.md?plain=1)

 

 


Friday, 9 October 2026

用muse的web版帮我在cloudflare.com平台上构建基于elm的静态博客程序elmstatic


我用email id: luckypoem@gmail.com登录cloudflare.com后,导入仓库https://github.com/brightmann/elmstatic-demo

下面的插图就是我跟它的对话过程.共9张截图。 


 

 


 




我得到的博客地址是:
https://elmstatic-demo.luckypoem.workers.dev/
同一天发表的帖子是按字母顺序从上到下排列的:
https://elmstatic-demo.luckypoem.workers.dev/posts/2026-10-09-1527-advice 
 https://elmstatic-demo.luckypoem.workers.dev/posts/2026-10-09-ce
 https://elmstatic-demo.luckypoem.workers.dev/posts/2026-10-09-fh
 https://elmstatic-demo.luckypoem.workers.dev/posts/2026-10-09-song-sound
项目地址:
 https://github.com/brightmann/elmstatic-demo 
在此处https://github.com/brightmann/elmstatic-demo/tree/main/_posts,新建源帖 2026-10-09-fh.md ,内容为:
---
             title: "战马"
                                  tags: misc1 misc2 misc3
---
 
                                    此处写正文或html codes.  
(详见 https://github.com/brightmann/elmstatic-demo/blob/main/_posts/2026-10-09-fh.md?plain=1)
 
 

 
 
 





Cinematic Orchestrations

领导人专车,红旗N701霸气侧漏

 

"中国制造,到哪都不会输“

Dism++确实是清理磁盘空间的神器

 https://github.com/Chuyu-Team/Dism-Multi-language/releases/download/v10.1.1002.2/Dism++10.1.1002.1B.zip

我的windows系统的 磁盘空间经常很快用完,真是有点烦,看了有关Dism++的介绍,下载下来一用,一下子就清理出了4.85gb的空间,真是神速,爽歪歪。

相关帖子: https://briteming.blogspot.com/2024/06/blog-post_39.html

---------

 

Dism++ is a free, open-source graphical user interface for Microsoft's built-in Deployment Image Servicing and Management (DISM) tool on Windows. [1, 2, 3]
Core Features
  • Drive Cleaner: Removes old Windows update files, temporary files, and system cache to free up storage. [1, 2, 3]
  • App Manager: Bulk uninstalls pre-installed Microsoft Store (Appx) packages. [1, 2]
  • Startup Inspector: Manages startup programs, services, and boot options. [1]
  • Updates & Images: Scans for, installs, or integrates Windows updates into live systems or offline .iso images. [1, 2, 3]
  • System Optimizer: Toggles various hidden Windows settings and interface tweaks. [1, 2]
Important Notes
  • Development Status: The project is older and receives infrequent updates from its creator Chuyu Team, though community translation mirrors remain active on SourceForge. [1, 2, 3]
  • Caution: Certain advanced features (like driver injection, deep boot repairs, or aggressive app removal) can destabilize modern Windows 10 or 11 builds if used improperly. [1, 2]
  • Downloads: You can find version packages via the Dism++ Uptodown Page or the Dism-Multi-language GitHub Releases. [1, 2]


接班人必须不是人

 

中国政治有一个奇妙的问题:最高领导人要找接班人,但这个接班人最好同时满足两个条件——能力极强,忠诚绝对。

听上去很合理。细想一下,几乎不是人。

能力强是什么意思?能管党,能管军,能压得住地方,能镇得住各派,遇上经济危机不慌,外交出事能处理,下面几百万干部肯听他的。这样的人当然不能是木偶。

问题来了。

一个能够做到这些事情的人,必然有自己的判断、自己的人脉、自己的威望,也必然逐渐形成自己的利益体系。今天他站在你旁边,可以毕恭毕敬;明天他坐上你的椅子,手里拿着组织、人事、军队和公安,他为什么还要永远以你的利益为最高利益?

人是会变的,准确说,不是人变了,是位置变了。

当年赫鲁晓夫在斯大林活着的时候,也没有天天站在主席台上喊“将来我要反斯大林”。斯大林死后,政治条件变了,赫鲁晓夫面对的利益也变了。政治忠诚从来不是银行定期存款,存进去四十年,利息照付。

于是个人集权最麻烦的事情出现了。

接班人太弱,不行。你一死,他压不住场面。

接班人太强,也不行。你还没死,就得开始防他。

没有班底,不行,因为他接不了班。

有了班底,更不行,因为他的班底为什么要永远听你的?

所以最理想的接班人,是一个能力极强,却没有自己的野心;拥有巨大权力,却没有自己的利益;能够独立处理国家大事,却永远不独立思考自己和前任的关系。

这不是政治人物,这是人工智能,而且还是锁死权限的那一种。

习近平面对的问题尤其明显。

2012年以来,反腐和政治整肃涉及的干部数量极大,近年甚至继续深入解放军最高层。2026年的军方整肃仍然没有停止。这些行动究竟有多少属于真正反腐、有多少包含权力重组,可以争论;但有一点没有疑问:十四年不断重新分配职位、权力和利益以后,政治关系已经被反复洗牌。

这时候退休,就不是回家种花那么简单。

你要问的第一件事不是“谁能力最好”,而是:

谁上去以后不会翻账?

可是这句话本身就有毛病。

一个真正能够控制全党的新领导人,如果永远不敢碰前任留下的问题,那他的权力到底是真的还是假的?

反过来,一个只能靠前任保护才能坐稳的人,等前任真正消失以后,他又凭什么坐得住?

这就是个人集权的数学难题。

权力越集中,接班人越重要;接班人越重要,最高领导人越不敢相信他;越不相信,就越晚培养;越晚培养,突然交班时风险越大。

最后变成一个死循环:最安全的方法,就是自己继续干。

所以接班问题表面上是在找一个人,实际上是在找一种不可能的人性。

民主制度解决这个问题的方法很粗暴:不要求下一任忠于上一任,只要求他忠于制度。

个人集权解决的方法却恰恰相反:制度不可信,只好要求下一个人忠于自己。

前一种制度赌规则。

后一种制度赌人心。

而人心,偏偏是政治里面最不能下注的东西, 是远不如规则可靠的东西。