Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat: strip blog from bundle, enable R2 cache, simplify chat scroll
Gus7c3322a821be
diff --git a/src/app/scripts/bundle.ts b/src/app/scripts/bundle.tsindex 1d54132d7..570a194f7 100644--- a/src/app/scripts/bundle.ts+++ b/src/app/scripts/bundle.ts@@ -26,7 +26,36 @@ if (existsSync(bundledDir)) rmSync(bundledDir, { recursive: true });// --- Build Web ---console.log("\n=== Building Web (opennextjs-cloudflare) ===\n");const webSrc = join(monoRoot, "src", "web");-run("npx opennextjs-cloudflare build", webSrc);++const blogStub = `\+export interface BlogPost { slug: string; title: string; date: string; author: string; excerpt: string; readingTime: string; content: string; }+export function getAllPosts(): BlogPost[] { return []; }+export function getPostBySlug(slug: string): BlogPost | undefined { return undefined; }+`;++// Strip blog content before building the app package+const blogAppDir = join(webSrc, "src", "app", "blog");+const blogLibDir = join(webSrc, "src", "lib", "blog");++console.log("[bundle] Stripping blog content for app-only build...");+rmSync(blogAppDir, { recursive: true });+rmSync(blogLibDir, { recursive: true });+mkdirSync(blogLibDir, { recursive: true });+writeFileSync(join(blogLibDir, "posts.ts"), blogStub);++try {+ run("npx opennextjs-cloudflare build", webSrc);+} finally {+ console.log("[bundle] Restoring blog source files...");+ try {+ execSync("git checkout -- src/web/src/app/blog/ src/web/src/lib/blog/", {+ cwd: monoRoot,+ stdio: "inherit",+ });+ } catch (e) {+ console.error("[bundle] WARNING: Failed to restore blog files:", e);+ }+}const webDest = join(bundledDir, "web");mkdirSync(webDest, { recursive: true });diff --git a/src/web/open-next.config.ts b/src/web/open-next.config.tsindex 898b93feb..4f3ea77be 100644--- a/src/web/open-next.config.ts+++ b/src/web/open-next.config.ts@@ -1,9 +1,6 @@import { defineCloudflareConfig } from "@opennextjs/cloudflare";+import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache";export default defineCloudflareConfig({- // Uncomment to enable R2 cache,- // It should be imported as:- // `import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache";`- // See https://opennext.js.org/cloudflare/caching for more details- // incrementalCache: r2IncrementalCache,+ incrementalCache: r2IncrementalCache,});diff --git a/src/web/src/app/blog/[slug]/page.tsx b/src/web/src/app/blog/[slug]/page.tsxindex 745be5e91..2969d31c8 100644--- a/src/web/src/app/blog/[slug]/page.tsx+++ b/src/web/src/app/blog/[slug]/page.tsx@@ -5,6 +5,8 @@ import { ArrowLeft, ArrowRight } from "lucide-react";import { getAllPosts, getPostBySlug } from "@/lib/blog/posts";import { highlightCodeBlocks } from "@/lib/blog/highlight";+export const dynamicParams = false;+export function generateStaticParams(): { slug: string }[] {return getAllPosts().map((post) => ({ slug: post.slug }));}diff --git a/src/web/src/components/agent-chat/agent-chat-view.tsx b/src/web/src/components/agent-chat/agent-chat-view.tsxindex 5a24916ac..37067de41 100644--- a/src/web/src/components/agent-chat/agent-chat-view.tsx+++ b/src/web/src/components/agent-chat/agent-chat-view.tsx@@ -13,7 +13,6 @@ import {createConversation,listMessages,listMessagesAroundTask,- listPreviousConversations,sendMessage,getTask,getTaskMessages,@@ -33,7 +32,7 @@ import {unflagMessage as apiUnflagMessage,} from "@/lib/api";import { appendCachedMessage, getCachedMessages, getCachedMessagesBefore, getCacheMeta, mergeCachedMessages } from "@/lib/chat-cache";-import type { PreviousConversation, TraceTask } from "@/lib/api";+import type { TraceTask } from "@/lib/api";import type { Artifact, Conversation, Issue, IssueComment, Message, TaskApi as Task, TaskMessage, WsMessage } from "@alook/shared";import { useAgentContext } from "@/contexts/agent-context";import { useInboxCount } from "@/contexts/inbox-count-context";@@ -61,7 +60,6 @@ import { AgentPreviewCard } from "@/components/agent-preview-card";import { Popover, PopoverTrigger, PopoverContent } from "@/components/ui/popover";const MESSAGE_LIMIT = 20;-const MAX_CONV_FETCHES_PER_CLICK = 5;const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MBfunction MentionHighlight(props: Record<string, unknown> & { children?: React.ReactNode }) {@@ -361,8 +359,6 @@ export function AgentChatView({const [pendingFiles, setPendingFiles] = useState<File[]>([]);const [bufferedMessages, setBufferedMessages] = useState<Message[]>([]);const [caretIndex, setCaretIndex] = useState<number | null>(null);- const [previousConversations, setPreviousConversations] = useState<PreviousConversation[]>([]);- const [hasMoreConversations, setHasMoreConversations] = useState(false);const [napMarkers, setNapMarkers] = useState<NapMarker[]>([]);const [stepCounts, setStepCounts] = useState<Record<string, number>>({});const [renderNow] = useState(() => Date.now());@@ -435,7 +431,6 @@ export function AgentChatView({const isNearBottom = useRef(true);const scrollTargetActiveRef = useRef(false);const startPollingRef = useRef<((taskId: string, conversationId: string, initialSeq?: number) => void) | null>(null);- const oldestConversationCursorRef = useRef<PreviousConversation | null>(null);const backfillAttemptsRef = useRef(0);const prevConversationIdRef = useRef<string | undefined>(undefined);const fileInputRef = useRef<HTMLInputElement>(null);@@ -493,9 +488,6 @@ export function AgentChatView({setPendingFilesByMessage(new Map());setNapMarkers([]);setStepCounts({});- setPreviousConversations([]);- setHasMoreConversations(false);- oldestConversationCursorRef.current = null;setInput(localStorage.getItem(`chat-draft:${agentId}:${targetConvId ?? 'default'}`) ?? "");setMessages([]);async function load() {@@ -548,7 +540,6 @@ export function AgentChatView({});if (ignore) return;setConversation(data.conversation);- setHasMoreConversations(data.has_more_conversations);if (!data.cache_valid && data.messages) {setMessages((prev) => mergeMessages(prev, data.messages!));writeToCacheRef.current(data.messages, data.has_more_messages).catch(() => {});@@ -591,7 +582,6 @@ export function AgentChatView({setHasMore(data.has_more_messages);setArtifacts(data.artifacts);setBufferedMessages(data.buffered_messages);- setHasMoreConversations(data.has_more_conversations);writeToCacheRef.current(data.messages, data.has_more_messages).catch(() => {});listFlaggedMessageIds(workspaceId, data.conversation.id).then((r) => { if (!ignore) setFlaggedIds(new Set(r.message_ids)); })@@ -759,10 +749,6 @@ export function AgentChatView({const messagesRef = useLatest(messages);const hasMoreRef = useLatest(hasMore);- const prevConvsRef = useLatest(previousConversations);- const hasMoreConvsRef = useLatest(hasMoreConversations);- const agentNameRef = useLatest(agentName);- const activeChannelRef = useLatest(activeChannel);const loadOlderMessages = useCallback(async (scrollToEnd = false) => {if (!conversation || loadingMoreRef.current) return;@@ -770,34 +756,11 @@ export function AgentChatView({const currentMessages = messagesRef.current;const currentHasMore = hasMoreRef.current;- const currentHasMoreConvs = hasMoreConvsRef.current;- const currentAgentName = agentNameRef.current;- const currentChannel = activeChannelRef.current;const oldest = currentMessages[0];- const paginatingConvId = oldestConversationCursorRef.current?.id ?? conversation.id;const canLoadMoreInConv = currentHasMore && oldest;- let prevConvsList = prevConvsRef.current;- if (!canLoadMoreInConv && prevConvsList.length === 0 && currentHasMoreConvs) {- const oldestConv = oldestConversationCursorRef.current ?? { id: conversation.id, created_at: conversation.created_at };- try {- const result = await listPreviousConversations(agentId, workspaceId, {- exclude: conversation.id,- before: oldestConv.created_at,- channel: currentChannel,- });- prevConvsList = result.conversations;- setPreviousConversations(result.conversations);- setHasMoreConversations(result.has_more);- } catch {- setHasMoreConversations(false);- }- }-- const canLoadPrevConv = prevConvsList.length > 0;-- if (!canLoadMoreInConv && !canLoadPrevConv) {+ if (!canLoadMoreInConv) {loadingMoreRef.current = false;return;}@@ -808,105 +771,30 @@ export function AgentChatView({const prevScrollHeight = el?.scrollHeight ?? 0;try {- let phase1Messages: Message[] = [];- let phase2Messages: Message[] = [];- let remaining = MESSAGE_LIMIT;+ let olderMessages: Message[] = [];let lastHasMore = false;- const napMarkersToAdd: { agentName: string; created_at: string; id: string }[] = [];-- // --- Phase 1: Load from current/paginating conversation ---- if (canLoadMoreInConv) {- const cached = paginatingConvId === conversation.id- ? await getCachedMessagesBefore(paginatingConvId, oldest!.created_at, oldest!.id, MESSAGE_LIMIT, workspaceId)- : null;-- if (cached) {- phase1Messages = cached.messages;- remaining -= cached.messages.length;- lastHasMore = cached.hasMore;- } else {- const result = await listMessages(paginatingConvId, workspaceId, {- limit: MESSAGE_LIMIT,- before: oldest!.created_at,- beforeId: oldest!.id,- });- phase1Messages = result.messages;- remaining -= result.messages.length;- lastHasMore = result.has_more;- }- }- // --- Phase 2: If current conv is exhausted AND still have quota, load from previous convs ---- if (!lastHasMore && remaining > 0) {- if (prevConvsList.length === 0 && currentHasMoreConvs) {- const oldestConv = oldestConversationCursorRef.current ?? { id: conversation.id, created_at: conversation.created_at };- try {- const result = await listPreviousConversations(agentId, workspaceId, {- exclude: conversation.id,- before: oldestConv.created_at,- channel: currentChannel,- });- prevConvsList = result.conversations;- setPreviousConversations(result.conversations);- setHasMoreConversations(result.has_more);- } catch {- setHasMoreConversations(false);- }- }+ const cached = await getCachedMessagesBefore(conversation.id, oldest!.created_at, oldest!.id, MESSAGE_LIMIT, workspaceId);- let consumed = 0;- let fetchCount = 0;-- while (- consumed < prevConvsList.length &&- remaining > 0 &&- fetchCount < MAX_CONV_FETCHES_PER_CLICK- ) {- const prevConv = prevConvsList[consumed]!;- consumed++;- fetchCount++;- const result = await listMessages(prevConv.id, workspaceId, {- limit: remaining,- });-- if (result.messages.length === 0) {- oldestConversationCursorRef.current = prevConv;- continue;- }-- const napTs = oldestConversationCursorRef.current?.created_at ?? conversation.created_at;- napMarkersToAdd.push({- agentName: currentAgentName,- created_at: napTs,- id: `nap-${prevConv.id}`,- });-- phase2Messages = [...result.messages, ...phase2Messages];- remaining -= result.messages.length;- lastHasMore = result.has_more;- oldestConversationCursorRef.current = prevConv;- }-- if (consumed > 0) {- setPreviousConversations((prev) => prev.slice(consumed));- }+ if (cached) {+ olderMessages = cached.messages;+ lastHasMore = cached.hasMore;+ } else {+ const result = await listMessages(conversation.id, workspaceId, {+ limit: MESSAGE_LIMIT,+ before: oldest!.created_at,+ beforeId: oldest!.id,+ });+ olderMessages = result.messages;+ lastHasMore = result.has_more;}- // --- Final state update ---- const allNewMessages = [...phase2Messages, ...phase1Messages];flushSync(() => {- if (allNewMessages.length > 0) {- if (napMarkersToAdd.length > 0) {- setNapMarkers((prev) => {- const existingIds = new Set(prev.map((m) => m.id));- const newMarkers = napMarkersToAdd.filter((m) => !existingIds.has(m.id));- return [...prev, ...newMarkers];- });- }+ if (olderMessages.length > 0) {setHasMore(lastHasMore);setMessages((prev) => {const existingIds = new Set(prev.map((m) => m.id));- const unique = allNewMessages.filter((m) => !existingIds.has(m.id));+ const unique = olderMessages.filter((m) => !existingIds.has(m.id));return [...unique, ...prev];});} else {@@ -914,11 +802,8 @@ export function AgentChatView({}});- if (allNewMessages.length > 0 && conversation) {- const currentConvMessages = allNewMessages.filter((m) => m.conversation_id === conversation.id);- if (currentConvMessages.length > 0) {- mergeCachedMessages(conversation.id, currentConvMessages, lastHasMore, workspaceId).catch(() => {});- }+ if (olderMessages.length > 0) {+ mergeCachedMessages(conversation.id, olderMessages, lastHasMore, workspaceId).catch(() => {});}loadingMoreRef.current = false;@@ -942,16 +827,11 @@ export function AgentChatView({}, [conversation,workspaceId,- agentId,messagesRef,hasMoreRef,- hasMoreConvsRef,- agentNameRef,- activeChannelRef,- prevConvsRef,]);- const canLoadMore = hasMore || previousConversations.length > 0 || hasMoreConversations;+ const canLoadMore = hasMore;useEffect(() => {if (conversation?.id === prevConversationIdRef.current) return;@@ -1598,11 +1478,6 @@ export function AgentChatView({{ agentName, created_at: newConv.created_at, id: `nap-${conversation.id}` },]);- setPreviousConversations((prev) => [- { id: conversation.id, created_at: conversation.created_at },- ...prev,- ]);-setConversation(newConv);setActiveTask(null);setTaskMessages([]);@@ -1613,7 +1488,6 @@ export function AgentChatView({lastSeqRef.current = 0;setConnectionLost(false);setHasMore(false);- oldestConversationCursorRef.current = null;scrollToBottom();} catch {diff --git a/src/web/src/lib/blog/highlight.ts b/src/web/src/lib/blog/highlight.tsindex 68aea4c78..37d9e2e2a 100644--- a/src/web/src/lib/blog/highlight.ts+++ b/src/web/src/lib/blog/highlight.ts@@ -22,7 +22,14 @@ function detectLanguage(code: string): string {}export async function highlightCodeBlocks(html: string): Promise<string> {- const hl = await getHighlighter();+ if (!html.includes("<pre><code")) return html;++ let hl: Highlighter;+ try {+ hl = await getHighlighter();+ } catch {+ return html;+ }return html.replace(/<pre><code(?:\s+class="language-(\w+)")?>([\s\S]*?)<\/code><\/pre>/g,diff --git a/src/web/src/lib/blog/posts.ts b/src/web/src/lib/blog/posts.tsindex aff91ed12..69945bcc5 100644--- a/src/web/src/lib/blog/posts.ts+++ b/src/web/src/lib/blog/posts.ts@@ -97,6 +97,50 @@ const posts: BlogPost[] = [<p>Alook is open source. You can spin up your first agent team today — on your machine, with your data, under your control. No vendor lock-in, no token limits that throttle you at the worst moment, no data leaving your infrastructure.</p>+<p>Here's how quick it is to define an agent:</p>++<pre><code class="language-typescript">import { createAgent } from "@alook/sdk";++const writer = createAgent({+ name: "writer",+ role: "Content Writer",+ instructions: "Draft blog posts, social copy, and email sequences.",+ tools: ["web-search", "email-send", "file-write"],+});++await writer.start();+</code></pre>++<p>Need agents to collaborate? They can message each other directly:</p>++<pre><code class="language-typescript">const planner = createAgent({+ name: "planner",+ role: "Project Planner",+ instructions: "Break goals into tasks. Assign to teammates.",+ teammates: [writer, coder],+});++// Planner delegates to writer automatically+await planner.run("Launch blog post about our new feature");+</code></pre>++<p>Or configure the whole team in a single YAML file:</p>++<pre><code class="language-yaml">team:+ - name: builder+ role: Full-Stack Developer+ tools: [github, terminal, code-review]++ - name: communicator+ role: Outreach & Comms+ tools: [email, calendar, slack]++ - name: planner+ role: Project Manager+ tools: [task-board, teammates]+ teammates: [builder, communicator]+</code></pre>+<p>Start with one agent. Give it a clear role. Let it prove itself. Then add another. Before you know it, you're running a company — not just working in one.</p>`,},