frontend/packages/arch/bot-typings/README.md
A comprehensive TypeScript type definitions package extracted from the bot application, providing essential type declarations for the Coze bot platform. This package centralizes common type definitions, interfaces, and module declarations to ensure type safety across the bot ecosystem.
Expand, PartialRequired, and Obj for enhanced type manipulationInstall the package in your Rush.js monorepo:
# Add to your package.json
"@coze-arch/bot-typings": "workspace:*"
# Run Rush update to install
rush update
Import the main type definitions:
// Import the main type definitions
import "@coze-arch/bot-typings";
// Import specific modules
import { BotPageFromEnum, Obj, Expand, PartialRequired } from "@coze-arch/bot-typings/common";
import { DynamicParams } from "@coze-arch/bot-typings/teamspace";
BotPageFromEnumDefines the source of bot detail pages:
enum BotPageFromEnum {
Bot = 'bot', // Bot list
Explore = 'explore', // Explore list
Store = 'store',
Template = 'template',
}
Obj - Generic object type:
type Obj = Record<string, any>;
Expand<T> - Expands intersection types for better readability:
type Intersection = { a: string } & { b: number };
type Result = Expand<Intersection>;
// Result: { a: string; b: number }
PartialRequired<T, K> - Makes specific fields required:
interface Agent {
id?: string;
name?: string;
desc?: string;
}
type Result = PartialRequired<Agent, 'id' | 'name'>;
// Result: { id: string; name: string; desc?: string }
DynamicParamsDefines route parameters for teamspace navigation:
interface DynamicParams extends Record<string, string | undefined> {
space_id?: string;
bot_id?: string;
plugin_id?: string;
workflow_id?: string;
dataset_id?: string;
doc_id?: string;
tool_id?: string;
invite_key?: string;
product_id?: string;
mock_set_id?: string;
conversation_id: string; // Required
commit_version?: string;
scene_id?: string;
post_id?: string;
project_id?: string;
}
The package provides comprehensive types under the DataItem namespace:
UserInfoComplete user information interface:
interface UserInfo {
user_id_str: string;
name: string;
screen_name: string;
avatar_url: string;
email?: string;
// ... many more fields
}
AuthLoginParams - OAuth login parametersAuthorizeResponse - Authorization response structureSendCodeData - Verification code responseUserCheckResponse - User validation responseThe package automatically provides type declarations for:
Image Files:
// .jpeg, .jpg, .webp, .gif, .png files
import myImage from './image.png'; // string
Stylesheets:
// .less, .css files
import styles from './styles.less'; // { [key: string]: string }
SVG Files:
// .svg files
import { ReactComponent } from './icon.svg'; // React.FunctionComponent
import icon from './icon.svg'; // any (depends on svgDefaultExport config)
Window Interface Extensions:
// IDE plugin support
window.editorDispose?.();
// Mini-program integration
window.tt?.miniProgram.postMessage({ data: {...} });
// Coze app integration
window.__cozeapp__?.setLoading?.(true);
Navigator Extensions:
// Standalone app detection
if (navigator.standalone) {
// Running as standalone web app
}
src/
├── index.d.ts # Main type definitions and module declarations
├── common.ts # Common utility types and enums
├── teamspace.ts # Teamspace-related type definitions
├── data_item.d.ts # User and authentication type definitions
├── navigator.d.ts # Navigator API extensions
└── window.d.ts # Window object extensions
This package contains only TypeScript declarations and requires no build step:
npm run build # No-op (exits with code 0)
npm run lint
index.d.tscommon.tswindow.d.ts or navigator.d.tsRemember to update the exports field in package.json for new modules.
None - this package contains only TypeScript type definitions.
Apache-2.0
Author: [email protected]
This package is part of the Coze bot platform architecture and provides essential type safety for bot development workflows.