@axiom-lattice/client-sdk

中文文档
8.0.2发布于 2026/11/03MITTypeScriptESM + CJS近 30 天下载 3062

TypeScript client SDK for interacting with the Agent Service API

原始使用文档
文档目录15 节
  1. Overview
  2. Runtime and scope
  3. Features
  4. Agent Web App Management
  5. Installation
  6. Usage
  7. Migration Notes
  8. Runtime Environment Support
  9. HTTP Client Standardization
  10. ChunkMessageMerger
  11. Future Migration Plans
  12. API Reference
  13. Client
  14. WeChatClient
  15. ChunkMessageMerger

Axiom Lattice Client SDK

A TypeScript client for the Axiom Lattice Agent Service API.

Overview

The Client SDK provides a simple interface for interacting with the Axiom Lattice Agent Service API. It handles authentication, request/response formatting, and error handling.

Runtime and scope

This package is runtime-neutral: it targets browser, Node 18+, Deno, Bun and similar modern JS runtimes. It contains HTTP/SSE client and protocol types only; React hooks, UI components and server-side business logic live in other packages.

Public APIs use cross-runtime Web standard types. File/archive inputs use Blob (browser File is a Blob subclass); the SDK does not require DOM-only File or Node-only node:* types. Node types in the build are for tests/tooling, not the public contract. See docs/architecture/decisions/ADR-260-client-sdk-runtime-neutral.md.

Features

  • Create and manage threads
  • Send messages and receive responses
  • Stream responses with event-based callbacks
  • Register client-side tools
  • Handle tool calls and responses
  • Process streaming message chunks with ChunkMessageMerger
  • Standardized HTTP client using axios for all API calls
  • Authenticated Agent Web App publication management through client.webApps

Agent Web App Management

client.webApps is the authenticated Console management API, not the anonymous external runtime client. It provides list, get, create, update, enable, disable, and delete.

import { Client, type CreateAgentWebAppInput } from "@axiom-lattice/client-sdk";

const client = new Client({
  baseURL: "http://localhost:4001",
  apiKey: "console-session-token",
  assistantId: "support-agent",
  transport: "sse",
});

const input: CreateAgentWebAppInput = {
  assistantId: "support-agent",
  name: "Support",
  integration: { type: "react_sdk" },
  scope: { defaultProjectId: "support", allowedProjectIds: ["support"] },
  features: {
    projectSelector: false,
    modelSelector: false,
    threadManagement: true,
    attachments: false,
    hitl: false,
    genUI: false,
  },
  appearance: { title: "Support assistant" },
};

const publication = await client.webApps.create(input);
await client.webApps.enable(publication.id);

Use @axiom-lattice/react-sdk/web-app in the external React application. The default/local SQLite setup currently uses an in-memory Web App store, so publication definitions do not survive gateway restart; configure the PostgreSQL store for persistence. See the management guide.

Installation

npm install @axiom-lattice/client-sdk

Usage

import { Client, createSimpleMessageMerger } from "@axiom-lattice/client-sdk";

// Create a client
const client = new Client({
  baseURL: "https://api.example.com",
  apiKey: "your-api-key",
  assistantId: "your-assistant-id",
  transport: "sse",
  environment: "web", // Optional: "web" (default) or "wechat-miniprogram"
});

// Create a thread
const threadId = await client.createThread({
  metadata: { user: "user123" },
});

// Send a message
const response = await client.chat.send({
  threadId,
  messages: [
    {
      role: "user",
      content: "Hello, how can you help me?",
      id: "msg-1",
    },
  ],
});

// Stream a message
const stopStreaming = client.chat.stream(
  {
    threadId,
    messages: [
      {
        role: "user",
        content: "Tell me a story",
        id: "msg-2",
      },
    ],
  },
  (event) => {
    console.log("Event:", event);
  },
  () => {
    console.log("Stream completed");
  },
  (error) => {
    console.error("Stream error:", error);
  }
);

// Stop streaming if needed
// stopStreaming();

// Use ChunkMessageMerger to process streaming chunks
const merger = createSimpleMessageMerger();

// Process user message
merger.push({
  type: "human",
  data: {
    id: "user-1",
    content: "Hello",
  },
});

// Process AI message with tool calls
merger.push({
  type: "ai",
  data: {
    id: "ai-1",
    content: "I need to search for that.",
    tool_calls: [
      {
        name: "search",
        args: { query: "typescript" },
        id: "search-1",
      },
    ],
  },
});

// Process tool response
merger.push({
  type: "tool",
  data: {
    id: "tool-1",
    content: "Search results: ...",
    tool_call_id: "search-1",
  },
});

// Get merged messages
const messages = merger.getMessages();

Migration Notes

Runtime Environment Support

As of version 1.0.13, the client SDK now supports different runtime environments through the environment configuration option. Currently supported environments are:

  • "web" (default): Uses axios for all HTTP requests, including streaming responses
  • "wechat-miniprogram": Uses a custom WeChat Mini Program HTTP client implementation for compatibility with WeChat Mini Programs

To specify the environment:

const client = new Client({
  // ... other options
  environment: "wechat-miniprogram", // For WeChat Mini Program environments
});

The WeChat Mini Program environment uses a different approach for streaming responses since true streaming is not supported in that environment. It uses a polling mechanism instead.

HTTP Client Standardization

As of version 1.0.12, the client SDK now uses axios exclusively for all HTTP requests, including streaming responses. Previously, the SDK used a combination of axios for regular requests and the native fetch API for streaming. This change standardizes the HTTP client implementation across the SDK.

Benefits:

  • Consistent error handling
  • Unified request/response interceptors
  • Simplified maintenance and debugging
  • Better compatibility with different JavaScript environments

ChunkMessageMerger

The ChunkMessageMerger module has been moved from the web project to the client-sdk package. It provides functionality for processing streaming message chunks and merging them into complete messages.

To use it:

import { createSimpleMessageMerger } from "@axiom-lattice/client-sdk";

const merger = createSimpleMessageMerger();
// Use merger methods: push, getMessages, reset, etc.

Future Migration Plans

The current web project uses its own implementation of useChat that is tightly integrated with the web app's API and message format. In the future, we plan to migrate the web project to use the react-sdk's useChat hook, which provides a more standardized interface for chat interactions.

Steps for future migration:

  1. Update the web project's message types to align with the react-sdk's message format
  2. Replace direct API calls with client-sdk methods
  3. Integrate the react-sdk's useChat hook
  4. Update UI components to work with the new message format

API Reference

Client

The main client class for interacting with the Axiom Lattice Agent Service API.

WeChatClient

A specialized client implementation for WeChat Mini Programs that uses the native wx API for network requests.

import { WeChatClient } from "@axiom-lattice/client-sdk";

// Create a WeChat client
const client = new WeChatClient({
  baseURL: "https://api.example.com",
  apiKey: "your-api-key",
  assistantId: "your-assistant-id",
  transport: "sse",
});

// Use the same API methods as the standard Client
const threadId = await client.createThread({
  metadata: { user: "user123" },
});

// Send a message
const response = await client.chat.send({
  threadId,
  messages: [
    {
      role: "user",
      content: "Hello, how can you help me?",
      id: "msg-1",
    },
  ],
});

ChunkMessageMerger

A utility for processing streaming message chunks and merging them into complete messages.

  • createSimpleMessageMerger(): Creates a new message merger instance
    • push(chunk): Processes a message chunk
    • getMessages(): Gets all messages with tool calls merged
    • getMessagesWithoutToolCalls(): Gets messages without tool calls
    • initialMessages(msgs): Initializes with existing messages
    • reset(): Resets the merger state

版本与发布记录

@axiom-lattice/client-sdk 共发布 145 个版本,首次发布于 2025/09/01;过去 12 个月发布了 116 个版本。

版本发布日期距今
8.0.2latest2026/11/034 天前
8.0.12026/11/025 天前
8.0.02026/10/317 天前
7.2.12026/10/299 天前
7.2.02026/10/2810 天前
7.1.02026/10/2711 天前

其他发布通道:hotfix → 2.1.13-hotfix.0。

关于 @axiom-lattice/client-sdk 的常见问题

@axiom-lattice/client-sdk 是什么?

TypeScript client SDK for interacting with the Agent Service API

如何安装 @axiom-lattice/client-sdk?

在项目目录运行 npm install @axiom-lattice/client-sdk,或使用 pnpm add / yarn add / bun add。

@axiom-lattice/client-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@axiom-lattice/client-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@axiom-lattice/client-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@axiom-lattice/client-sdk 可以商用吗?

@axiom-lattice/client-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@axiom-lattice/client-sdk 的下载量有多少?

根据 npm 官方下载统计,@axiom-lattice/client-sdk 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,062 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@axiom-lattice/client-sdk 还在维护吗?

最新版本 8.0.2 发布于 2026/11/03(4 天前);至今共发布 145 个版本,其中过去 12 个月发布了 116 个;首次发布于 2025/09/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。