@brightsy/client

中文文档
1.0.34发布于 2026/10/26MITTypeScriptES Module近 30 天下载 1850

Unified client SDK for Brightsy CMS and Agents

原始使用文档
文档目录24 节
  1. Installation
  2. Quick Start
  3. API Reference
  4. Content Management (CMS)
  5. Agents
  6. Scenarios
  7. Schedules
  8. Webhooks
  9. Apps
  10. Files
  11. AI Images
  12. API Keys
  13. Advanced Usage
  14. File Upload Examples
  15. Filtering and Pagination
  16. Error Handling
  17. Streaming Agent Responses
  18. Development & Testing
  19. Running Tests
  20. Test Structure
  21. Building
  22. Authentication
  23. Support
  24. License

Brightsy Client

Official TypeScript/JavaScript client for the Brightsy API.

Installation

npm install @brightsy/client

Quick Start

import { BrightsyClient } from '@brightsy/client';

const client = new BrightsyClient({
  api_key: 'bsy_your_api_key',
  account_id: 'your_account_id',
  endpoint: 'https://brightsy.ai' // optional
});

API Reference

Content Management (CMS)

CMA - Content Management API

Access draft content with full CRUD operations:

// List records
const posts = await client.cma()
  .recordType('blog-post')
  .where('status', 'eq', 'draft')
  .pageSize(10)
  .get();

// Create a record
const newPost = await client.cma()
  .recordType('blog-post')
  .create({
    title: 'My Post',
    content: '...'
  });

// Update a record
await client.cma()
  .recordType('blog-post')
  .id('record-id')
  .update({ title: 'Updated Title' });

// Delete a record
await client.cma()
  .recordType('blog-post')
  .id('record-id')
  .delete();

CDA - Content Delivery API

Access published content (read-only):

const posts = await client.cda()
  .recordType('blog-post')
  .where('published', 'eq', true)
  .get();

CPA - Content Preview API

Access draft content (read-only):

const drafts = await client.cpa()
  .recordType('blog-post')
  .get();

Agents

Manage and interact with AI agents:

// List agents
const agents = await client.agents().list({ search: 'customer' });

// Create an agent
const agent = await client.agents().create({
  name: 'Customer Support',
  description: 'Handles customer inquiries',
  system_instruction: '...'
});

// Get agent details
const agent = await client.agents().get('agent-id');

// Update an agent
await client.agents().update('agent-id', {
  name: 'Updated Name'
});

// Delete an agent
await client.agents().delete('agent-id');

// Chat with an agent (execution)
const response = await client.agent('agent-id').chat({
  message: 'Hello!',
  chat_id: client.createChatId()
});

Scenarios

Manage automation scenarios:

// List scenarios
const scenarios = await client.scenarios().list();

// Create a scenario
const scenario = await client.scenarios().create({
  name: 'Welcome Email',
  description: '...',
  trigger_type: 'webhook',
  run_as_user_id: 'user-uuid' // Optional user context for webhook/signature runs
});

// Get, update, delete
await client.scenarios().get('scenario-id');
await client.scenarios().update('scenario-id', { run_as_user_id: 'user-uuid' });
await client.scenarios().delete('scenario-id');

// Trigger a scenario (legacy method)
await client.scenario('scenario-id').trigger({ data: '...' });

Schedules

Manage scheduled tasks:

// List schedules
const schedules = await client.schedules().list();

// Create a schedule
const schedule = await client.schedules().create({
  name: 'Daily Backup',
  cron: '0 0 * * *',
  scenario_id: 'scenario-id'
});

// Get, update, delete
await client.schedules().get('schedule-id');
await client.schedules().update('schedule-id', { /* ... */ });
await client.schedules().delete('schedule-id');

Webhooks

Manage event webhooks:

// List webhooks
const webhooks = await client.webhooks().list();

// Create a webhook
const webhook = await client.webhooks().create({
  name: 'Content Published',
  webhook_type: 'http',
  endpoint_url: 'https://example.com/webhook',
  triggers: {
    cms: {
      'blog-post': {
        publish: true
      }
    }
  }
});

// Get, update, delete
await client.webhooks().get('webhook-id');
await client.webhooks().update('webhook-id', { /* ... */ });
await client.webhooks().delete('webhook-id');

// Test a webhook
await client.webhooks().test('webhook-id');

Apps

Access connected apps/integrations:

// List connected apps
const apps = await client.apps().list();

// Get app details
const app = await client.apps().get('app-id');

Files

Manage files and folders in account storage:

// List files
const files = await client.files().list({ 
  path: 'public/images',
  search: 'logo' 
});

// Create folder
await client.files().createFolder({
  path: 'public',
  folderName: 'images'
});

// Upload file
await client.files().upload({
  path: 'public',
  filename: 'image.jpg',
  file: fileBlob
});

// Get signed URL for private file
const { signedUrl } = await client.files().signedUrl({
  path: 'public/image.jpg',
  expiresIn: 3600
});

// Move/rename file
await client.files().move('old/path.jpg', 'new/path.jpg');

// Delete file
await client.files().delete('path/to/file.jpg');

AI Images

AI-powered image operations:

// Analyze an image
const analysis = await client.images().analyze({
  imageUrl: 'https://example.com/image.jpg',
  prompt: 'What objects are in this image?', // optional
  model: 'gemini_2_5_flash_preview_09_2025' // optional
});
console.log(analysis.data.response);

// Get improvement suggestions
const suggestions = await client.images().suggestEdits({
  imageUrl: 'https://example.com/image.jpg',
  model: 'gemini_2_5_flash_preview_09_2025' // optional
});
console.log(suggestions.data.suggestions);
// Returns structured suggestions with category, title, description, priority

// Generate a new image
const generation = await client.images().generate({
  prompt: 'A beautiful sunset over mountains',
  width: 1024,  // optional, default: 1024
  height: 768,  // optional, default: 768
  model: 'gemini_nano_banana_2_1' // optional; catalog key or OpenRouter id
});
console.log(generation.data.imageUrl);

Image Analysis uses Gemini 2.5 Flash for AI vision analysis of images. You can ask specific questions about the image or get a general description.

Image Suggestions returns structured recommendations for improving the image, including composition, color, brightness, technical, and creative suggestions.

Image Generation creates new images from text prompts using Flux 1.1 Pro. The generated image URL is temporary and should be downloaded if you need to persist it.

// List files
const files = await client.files().list({
  path: 'documents',
  search: 'invoice'
});

// Create a folder
await client.files().createFolder({
  path: 'documents',
  folderName: '2024'
});

// Option 1: Direct upload (convenience method)
const { fileUrl, path } = await client.files().upload({
  path: 'documents',
  filename: 'report.pdf',
  file: fileData // File, Blob, or Buffer
});

// Option 2: Manual two-step upload
const { uploadUrl, fileUrl } = await client.files().uploadUrl({
  path: 'documents',
  filename: 'report.pdf'
});

await fetch(uploadUrl, {
  method: 'PUT',
  body: fileData
});

// Get signed download URL
const { signedUrl } = await client.files().signedUrl({
  path: 'documents/report.pdf',
  expiresIn: 3600
});

// Delete a file
await client.files().delete('documents/report.pdf');

// Move/rename a file
await client.files().move('old-path.pdf', 'new-path.pdf');

API Keys

Manage team API keys:

// List API keys
const keys = await client.apikeys().list();

// Create an API key
const newKey = await client.apikeys().create({
  name: 'Production Key',
  permissions: {
    cms: {
      'blog-post': {
        read: true,
        create: true
      }
    }
  }
});

// Get, update, delete
await client.apikeys().get('key-id');
await client.apikeys().update('key-id', { name: 'Updated' });
await client.apikeys().delete('key-id');

// Rotate an API key
const { key } = await client.apikeys().rotate('key-id');

Advanced Usage

File Upload Examples

Browser (with File input)

// From file input
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];

const { fileUrl } = await client.files().upload({
  path: 'uploads',
  filename: file.name,
  file: file
});

console.log('File uploaded to:', fileUrl);

Node.js (with fs)

import fs from 'fs';

const fileBuffer = fs.readFileSync('./report.pdf');

const { fileUrl } = await client.files().upload({
  path: 'documents',
  filename: 'report.pdf',
  file: fileBuffer
});

With Blob/ArrayBuffer

const blob = new Blob(['Hello, world!'], { type: 'text/plain' });

const { fileUrl } = await client.files().upload({
  path: 'notes',
  filename: 'hello.txt',
  file: blob
});

Filtering and Pagination

const results = await client.cma()
  .recordType('blog-post')
  .where('status', 'eq', 'published')
  .where('views', 'gt', 1000)
  .orderBy('created_at', 'desc')
  .page(1)
  .pageSize(20)
  .select('title', 'slug', 'created_at')
  .get();

Error Handling

try {
  const agent = await client.agents().get('invalid-id');
} catch (error) {
  console.error('Error:', error.message);
}

Streaming Agent Responses

await client.agent('agent-id').chat({
  message: 'Tell me a story',
  stream: true,
  onChunk: (chunk) => {
    console.log(chunk);
  }
});

Development & Testing

Running Tests

# Run all unit tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run API integration tests (with MSW mocks)
pnpm test:api

# Run E2E tests against REAL API
# Option 1: Use CLI login (recommended)
brightsy login  # Run once to authenticate
pnpm test:e2e

# Option 2: Use environment variables
BRIGHTSY_API_KEY=bsy_xxx BRIGHTSY_ACCOUNT_ID=xxx pnpm test:e2e

# Run tests with coverage
pnpm test:coverage

Test Structure

The test suite includes:

  • Unit Tests (src/*.test.ts)

    • Client.test.ts - BrightsyClient class and generateUUID
    • oauth.test.ts - OAuth PKCE utilities and OAuthClient
    • stream-utils.test.ts - Message formatting and JSON parsing
  • API Integration Tests (src/api.test.ts)

    • Tests for Agents, Scenarios, CMS, Files APIs
    • Uses MSW (Mock Service Worker) for API mocking
  • E2E Tests (src/e2e.test.ts)

    • Tests against the real Brightsy API
    • Requires BRIGHTSY_API_KEY and BRIGHTSY_ACCOUNT_ID env vars
    • Use a test account to avoid modifying production data

Building

pnpm build

Authentication

The client supports team API keys with granular permissions. Get your API key from the Brightsy dashboard.

Support

License

MIT

版本与发布记录

@brightsy/client 共发布 19 个版本,首次发布于 2025/12/03;过去 12 个月发布了 19 个版本。

版本发布日期距今
1.0.34latest2026/10/2613 天前
1.0.332026/10/2613 天前
1.0.322026/10/2514 天前
1.0.312026/10/2415 天前
1.0.302026/10/2317 天前
1.0.272026/10/2317 天前

关于 @brightsy/client 的常见问题

@brightsy/client 是什么?

Unified client SDK for Brightsy CMS and Agents

如何安装 @brightsy/client?

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

@brightsy/client 支持 TypeScript 吗?

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

@brightsy/client 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@brightsy/client 可以商用吗?

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

@brightsy/client 的下载量有多少?

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

@brightsy/client 还在维护吗?

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