frontend/packages/arch/bot-api/README.md
RPC wrapper for bot studio application
This package provides a comprehensive API client library for the Coze Bot Studio platform. It offers TypeScript-first RPC wrappers for all bot studio services, including developer APIs, playground functionality, knowledge management, workflow orchestration, and more. The package centralizes API interactions and provides type-safe interfaces for seamless integration across the platform.
Comprehensive API Coverage: Complete wrapper for all bot studio services including:
TypeScript-First: Full type safety with auto-generated IDL definitions
Modular Architecture: Import only the APIs you need with tree-shaking support
Error Handling: Built-in error handling with customizable toast notifications
Request Interceptors: Global request/response interceptors for logging and monitoring
Axios Integration: Built on top of axios with custom configuration support
Add this package to your package.json dependencies and set it to workspace:* version:
{
"dependencies": {
"@coze-arch/bot-api": "workspace:*"
}
}
Then run:
rush update
import {
DeveloperApi,
PlaygroundApi,
KnowledgeApi,
workflowApi
} from '@coze-arch/bot-api';
// Use developer API
const bots = await DeveloperApi.getBotList({
page: 1,
page_size: 20
});
// Use playground API
const result = await PlaygroundApi.chat({
bot_id: 'bot_123',
message: 'Hello world'
});
// Import specific IDL definitions
import { BotInfo } from '@coze-arch/bot-api/developer_api';
import { ChatMessage } from '@coze-arch/bot-api/playground_api';
import { KnowledgeBase } from '@coze-arch/bot-api/knowledge';
// Import specific service implementations
import DeveloperApiService from '@coze-arch/bot-api/developer_api';
import PlaygroundApiService from '@coze-arch/bot-api/playground_api';
import {
APIErrorEvent,
handleAPIErrorEvent,
addGlobalRequestInterceptor
} from '@coze-arch/bot-api';
// Add global error handler
handleAPIErrorEvent((error) => {
console.error('API Error:', error);
});
// Add request interceptor for authentication
addGlobalRequestInterceptor((config) => {
config.headers.Authorization = `Bearer ${getAuthToken()}`;
return config;
});
import type { BotAPIRequestConfig } from '@coze-arch/bot-api';
// Disable error toast for specific request
const result = await DeveloperApi.getBotInfo(
{ bot_id: 'bot_123' },
{ __disableErrorToast: true } as BotAPIRequestConfig
);
DeveloperApi)PlaygroundApi)KnowledgeApi)workflowApi)MemoryApi - Conversation memory managementxMemoryApi - Extended memory functionalitywebContext - Web-based context handlingPluginDevelopApi - Plugin development toolsconnectorApi - Third-party integrationsmarketInteractionApi - Marketplace interactionspermissionAuthzApi - Authorization managementpermissionOAuth2Api - OAuth2 integrationpatPermissionApi - Personal access tokenstradeApi - Payment and billingbenefitApi - User benefits and rewardsincentiveApi - Incentive programsinterface BotAPIRequestConfig extends AxiosRequestConfig {
__disableErrorToast?: boolean; // Disable automatic error toasts
}
The package provides both high-level service instances and low-level IDL access:
DeveloperApi, PlaygroundApi, ProductApi, NotifyApi,
MemoryApi, KnowledgeApi, cardApi, appBuilderApi,
workflowApi, debuggerApi, tradeApi, benefitApi,
incentiveApi, fulfillApi, hubApi, SocialApi
// Access via subpath imports
'@coze-arch/bot-api/developer_api'
'@coze-arch/bot-api/playground_api'
'@coze-arch/bot-api/knowledge'
'@coze-arch/bot-api/workflow_api'
// ... and many more
npm run build - Build the package (no-op, source-only package)npm run lint - Run ESLintnpm run test - Run tests with Vitestnpm run test:cov - Run tests with coveragesrc/
├── idl/ # Auto-generated IDL definitions
│ ├── developer_api.ts # Developer service types
│ ├── playground_api.ts # Playground service types
│ └── ... # Other service definitions
├── developer-api.ts # Developer API service implementation
├── playground-api.ts # Playground API service implementation
├── axios.ts # Custom axios configuration
└── index.ts # Main exports
This package depends on:
@coze-arch/bot-http - HTTP client utilities and interceptors@coze-arch/bot-semi - UI components for error handling@coze-arch/idl - Interface definition language utilitiesaxios - HTTP client libraryquery-string - URL query string utilitiesApache-2.0