npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cleak/agent-core

v0.2.1

Published

Framework-free agentic loop, tool abstraction, MCP client and multi-provider (OpenAI/Anthropic/local) model adapters.

Readme

@cleak/agent-core

Lõi agentic không phụ thuộc framework: vòng lặp native tool-calling, MCP client, và callModel đa provider (streaming, idle-timeout, nén ngữ cảnh). leak-inspector-tui xây trên package này; bản thân nó không biết gì về memory leak — chỉ là cơ chế điều phối mô hình ↔ tool có thể tái dùng.

Publish lên npm cùng CLI (@cleak/agent-core); trong monorepo build bằng tsup.

Kiến trúc

src/
  loop.ts            queryLoop(): async-generator một lượt = stream → gọi tool → kết quả → lặp
  tool.ts            trừu tượng Tool + buildTool() (default an toàn)
  types.ts           Message, ContentBlock, ToolUse/ToolResult, AgentEvent, Usage, …
  deps.ts            CallModel + các cổng phụ thuộc (inject được)
  providers/         buildCallModel() → local | openai | anthropic | openai-compat
    openaiChat.ts    đường chat-completions (local/openai/compat)
    anthropic.ts     Messages API
    normalize.ts     đổi qua lại message/tool giữa các provider
    transport.ts     fetchWithRetry (retry lỗi tạm thời)
  compaction.ts      nén transcript khi vượt ngưỡng token (estimateTokens, pruneStaleToolResults)
  concurrency.ts     mapWithLimit() — fan-out có giới hạn
  mcp/mcpClient.ts   McpClient: Streamable-HTTP, retry transient (MCP_MAX_RETRIES)
  mcp/mcpToolAdapter.ts  loadMcpTools()/wrapMcpTool(): tools/list của MCP → Tool[]

API chính

| Symbol | Loại | Vai trò | |---|---|---| | queryLoop(params) | async function* | vòng lặp agent: yield AgentEvent, trả LoopResult | | buildCallModel(settings, uuid?, onNotice?) | function | dựng CallModel từ ProviderSettings (local/openai/anthropic/compat) | | buildTool(def) | function | tạo Tool với default an toàn | | loadMcpTools(client, flagResolver?) | async function | nạp tool từ MCP server thành Tool[] | | wrapMcpTool(...) | function | bọc 1 MCP tool thành Tool (kèm cờ permission/format) | | McpClient | class | client Streamable-HTTP (McpClientOptions) | | Tool, ToolCtx, Message, AgentEvent, Usage, LoopResult | type/interface | hợp đồng dữ liệu của loop | | mapWithLimit(items, n, fn) | function | chạy song song có trần đồng thời | | estimateTokens, pruneStaleToolResults, truncateResult | function | tiện ích nén/cắt ngữ cảnh | | isTransientError, retryTransient | function | phân loại + retry lỗi mạng/tạm thời |

Cấu hình (ENV)

thư viện, không chạy độc lập ⇒ không có .env.example. Biến env duy nhất:

| Biến | Ý nghĩa | Mặc định | |---|---|---| | MCP_MAX_RETRIES | số lần retry khi MCP transport lỗi tạm thời (mcp/mcpClient.ts) | 3 |

Tham số provider (base URL, key, model, nhiệt độ, timeout…) truyền qua ProviderSettings, do consumer (TUI) đọc từ env của nó — xem apps/leak-inspector-tui/.env.example.

Build / test

turbo run build --filter=@cleak/agent-core    # tsup bundle
turbo run test  --filter=@cleak/agent-core    # bun test