@choiceopen/atomemo-plugin-schema 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Choiceform
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,37 +1,280 @@
1
- # Choiceform Atomemo Plugin Schema
1
+ # @choiceopen/atomemo-plugin-schema
2
+
3
+ [English](./README.md) | [中文](./README.zh-CN.md)
4
+
5
+ A comprehensive TypeScript type definitions and Zod schema validation library for developing Choiceform Atomemo plugins. This library ensures type safety at compile time and runtime validation for plugin definitions.
6
+
7
+ ## Features
8
+
9
+ - 🎯 **Type Safety**: Complete TypeScript type definitions for plugin development
10
+ - ✅ **Runtime Validation**: Zod schema validation for plugin definitions
11
+ - 🌍 **i18n Support**: Built-in internationalization text types and validation
12
+ - 🎨 **Flexible Property System**: Support for various data types and UI components
13
+ - 🔧 **Conditional Display**: Conditional display logic based on other property values
14
+ - 📦 **Tree-shakeable**: Optimized exports for minimal bundle size
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ # Using npm
20
+ npm install @choiceopen/atomemo-plugin-schema zod
21
+
22
+ # Using yarn
23
+ yarn add @choiceopen/atomemo-plugin-schema zod
24
+
25
+ # Using pnpm
26
+ pnpm add @choiceopen/atomemo-plugin-schema zod
27
+
28
+ # Using bun
29
+ bun add @choiceopen/atomemo-plugin-schema zod
30
+ ```
31
+
32
+ > **Note**: `zod` is a peer dependency and must be installed separately.
33
+
34
+ ## Quick Start
35
+
36
+ ### Import Types
37
+
38
+ ```typescript
39
+ import type {
40
+ PluginDefinition,
41
+ CredentialDefinition,
42
+ DataSourceDefinition,
43
+ ModelDefinition,
44
+ ToolDefinition,
45
+ Property,
46
+ } from '@choiceopen/atomemo-plugin-schema/types';
47
+ ```
48
+
49
+ ### Import Schemas
50
+
51
+ ```typescript
52
+ import {
53
+ PluginDefinitionSchema,
54
+ CredentialDefinitionSchema,
55
+ DataSourceDefinitionSchema,
56
+ ModelDefinitionSchema,
57
+ ToolDefinitionSchema,
58
+ PropertySchema,
59
+ } from '@choiceopen/atomemo-plugin-schema/schemas';
60
+ ```
61
+
62
+ ### Example: Define a Plugin
63
+
64
+ ```typescript
65
+ import { PluginDefinitionSchema } from '@choiceopen/atomemo-plugin-schema/schemas';
66
+ import type { PluginDefinition } from '@choiceopen/atomemo-plugin-schema/types';
67
+
68
+ const pluginDefinition: PluginDefinition = {
69
+ name: 'my-plugin',
70
+ display_name: {
71
+ en_US: 'My Plugin',
72
+ zh_CN: '我的插件',
73
+ },
74
+ description: {
75
+ en_US: 'A sample plugin for Atomemo',
76
+ zh_CN: '一个示例插件',
77
+ },
78
+ icon: 'https://example.com/icon.png',
79
+ version: '1.0.0',
80
+ locales: ['en', 'zh_CN'],
81
+ };
82
+
83
+ // Validate at runtime
84
+ const result = PluginDefinitionSchema.safeParse(pluginDefinition);
85
+ if (!result.success) {
86
+ console.error('Validation failed:', result.error);
87
+ }
88
+ ```
89
+
90
+ ## Core Concepts
91
+
92
+ ### Plugin Definition
93
+
94
+ A plugin definition contains metadata about your plugin:
95
+
96
+ - Basic information: name, display name, description, icon
97
+ - Author information: name, email, repository URL, version
98
+ - Supported languages list
99
+
100
+ ### Feature Definitions
101
+
102
+ Feature definitions include:
103
+
104
+ - **Credential**: For storing and managing authentication information
105
+ - **DataSource**: For connecting to external data sources
106
+ - **Model**: For defining LLM models
107
+ - **Tool**: For executing specific functions
108
+
109
+ ### Property System
110
+
111
+ The property system is the core of defining plugin parameters and settings:
112
+
113
+ **Property Types:**
114
+ - `string`: String type
115
+ - `number` / `integer`: Number type
116
+ - `boolean`: Boolean type
117
+ - `array`: Array type
118
+ - `object`: Object type
119
+ - `discriminated_union`: Discriminated union type
120
+ - `credential_id`: Credential ID type
121
+ - `encrypted_string`: Encrypted string type
122
+
123
+ **Property Features:**
124
+ - Constant values (`constant`)
125
+ - Default values (`default`)
126
+ - Enum values (`enum`)
127
+ - Range constraints (`min_length`, `max_length`, `minimum`, `maximum`, `min_items`, `max_items`)
128
+ - Conditional display (`display.hide/show`)
129
+ - AI configuration (`ai.llm_description`)
130
+
131
+ ### UI Component System
132
+
133
+ Each property type can be configured with different UI components:
134
+
135
+ **String type components:**
136
+ - `input`, `textarea`, `code-editor`
137
+ - `select`, `radio-group`
138
+ - `emoji-picker`, `color-picker`, `credential-select`
139
+
140
+ **Number type components:**
141
+ - `number-input`, `slider`
142
+
143
+ **Boolean type components:**
144
+ - `switch`, `checkbox`
145
+
146
+ **Array type components:**
147
+ - `multi-select`, `tag-input`, `key-value-editor`, `slider`, `array-section`
148
+
149
+ **Object type components:**
150
+ - `collapsible-panel`, `json-schema-editor`, `conditions-editor`, `code-editor`
151
+
152
+ ### Conditional Display System
153
+
154
+ Supports conditional display logic based on other property values:
155
+
156
+ **Operators:**
157
+ - Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
158
+ - Existence check: `$exists`
159
+ - Set operations: `$in`, `$nin`
160
+ - Regex matching: `$regex`, `$options`
161
+ - Array operations: `$size`, `$mod`
162
+ - Logical combination: `$and`, `$or`, `$nor`
163
+
164
+ ## API Reference
165
+
166
+ ### Exports
167
+
168
+ The package exports two main entry points:
169
+
170
+ - `@choiceopen/atomemo-plugin-schema/types` - TypeScript type definitions
171
+ - `@choiceopen/atomemo-plugin-schema/schemas` - Zod schema validators
172
+
173
+ ### Development Exports
174
+
175
+ In development environments, the package exports source files directly for better debugging and hot reload support:
176
+
177
+ ```json
178
+ {
179
+ "./schemas": {
180
+ "development": "./src/schemas.ts",
181
+ "default": "./dist/schemas.js"
182
+ },
183
+ "./types": {
184
+ "development": "./src/types.ts",
185
+ "default": "./dist/types.js"
186
+ }
187
+ }
188
+ ```
2
189
 
3
190
  ## Development
4
191
 
5
- - Install dependencies:
192
+ ### Prerequisites
193
+
194
+ - [Bun](https://bun.sh) >= 1.0.0
195
+ - Node.js >= 18.0.0 (if not using Bun)
196
+
197
+ ### Setup
6
198
 
7
199
  ```bash
200
+ # Install dependencies
8
201
  bun install
9
202
  ```
10
203
 
11
- - Watch and rebuild in development
204
+ ### Available Scripts
12
205
 
13
206
  ```bash
207
+ # Watch and rebuild in development
14
208
  bun run dev
15
- ```
16
209
 
17
- - Linting and formatting
210
+ # Build the library
211
+ bun run build
18
212
 
19
- ```bash
213
+ # Run linting and formatting
20
214
  bun run check
21
- ```
22
215
 
23
- - Run the unit tests:
216
+ # Run type checking
217
+ bun run typecheck
24
218
 
25
- ```bash
219
+ # Run unit tests
26
220
  bun run test
27
221
  ```
28
222
 
29
- - Build the library:
223
+ ### Code Quality
30
224
 
31
- ```bash
32
- bun run build
225
+ This project uses [Biome](https://biomejs.dev) for unified linting and formatting. For the best development experience, install the [Biome VS Code extension](https://marketplace.visualstudio.com/items?itemName=biomejs.biome).
226
+
227
+ ## Project Structure
228
+
229
+ ```
230
+ atomemo-plugin-schema/
231
+ ├── src/ # Source code
232
+ │ ├── schemas/ # Zod schema validation modules
233
+ │ ├── types/ # TypeScript type definitions
234
+ │ ├── utils/ # Utility functions
235
+ │ ├── schemas.ts # Schema exports
236
+ │ └── types.ts # Type exports
237
+ ├── tests/ # Test files
238
+ ├── dist/ # Build output
239
+ └── [config files] # package.json, tsconfig.json, etc.
33
240
  ```
34
241
 
35
- ## Linting and formatting
242
+ ## Contributing
243
+
244
+ Contributions are welcome! Please follow these guidelines:
245
+
246
+ 1. Follow the project's code style (use Biome for formatting)
247
+ 2. Ensure all tests pass
248
+ 3. Ensure type safety (use `IsEqual` for validation)
249
+ 4. Update relevant documentation
250
+ 5. Run `bun run check` and `bun run test` before submitting
251
+
252
+ ### Development Workflow
253
+
254
+ 1. Fork the repository
255
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
256
+ 3. Make your changes
257
+ 4. Run tests and linting (`bun run check && bun run test`)
258
+ 5. Commit your changes (`git commit -m 'Add some amazing feature'`)
259
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
260
+ 7. Open a Pull Request
261
+
262
+ ## Changelog
263
+
264
+ See [CHANGELOG.md](./CHANGELOG.md) for a list of changes and version history.
265
+
266
+ ## License
267
+
268
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
269
+
270
+ ## Support
271
+
272
+ - 📖 [Documentation](https://github.com/choice-open/atomemo-plugin-schema#readme)
273
+ - 🐛 [Issue Tracker](https://github.com/choice-open/atomemo-plugin-schema/issues)
274
+ - 💬 [Discussions](https://github.com/choice-open/atomemo-plugin-schema/discussions)
275
+
276
+ ## Acknowledgments
36
277
 
37
- This project uses Biome to provide unified linting and formatting, please install VS Code extension if you use VS Code to having the best DX support.
278
+ - Built with [TypeScript](https://www.typescriptlang.org/)
279
+ - Schema validation powered by [Zod](https://zod.dev/)
280
+ - Tool types from [type-fest](https://github.com/sindresorhus/type-fest)
@@ -0,0 +1,280 @@
1
+ # @choiceopen/atomemo-plugin-schema
2
+
3
+ [English](./README.md) | [中文](./README.zh-CN.md)
4
+
5
+ 一个全面的 TypeScript 类型定义和 Zod Schema 验证库,用于开发 Choiceform Atomemo 插件。该库确保插件定义在编译时和运行时的类型安全与验证。
6
+
7
+ ## 特性
8
+
9
+ - 🎯 **类型安全**: 完整的 TypeScript 类型定义,支持插件开发
10
+ - ✅ **运行时验证**: 使用 Zod Schema 进行运行时验证
11
+ - 🌍 **国际化支持**: 内置国际化文本类型和验证
12
+ - 🎨 **灵活的属性系统**: 支持多种数据类型和 UI 组件
13
+ - 🔧 **条件显示**: 基于其他属性值的条件显示逻辑
14
+ - 📦 **Tree-shakeable**: 优化的导出,最小化打包体积
15
+
16
+ ## 安装
17
+
18
+ ```bash
19
+ # 使用 npm
20
+ npm install @choiceopen/atomemo-plugin-schema zod
21
+
22
+ # 使用 yarn
23
+ yarn add @choiceopen/atomemo-plugin-schema zod
24
+
25
+ # 使用 pnpm
26
+ pnpm add @choiceopen/atomemo-plugin-schema zod
27
+
28
+ # 使用 bun
29
+ bun add @choiceopen/atomemo-plugin-schema zod
30
+ ```
31
+
32
+ > **注意**: `zod` 是 peer dependency,需要单独安装。
33
+
34
+ ## 快速开始
35
+
36
+ ### 导入类型
37
+
38
+ ```typescript
39
+ import type {
40
+ PluginDefinition,
41
+ CredentialDefinition,
42
+ DataSourceDefinition,
43
+ ModelDefinition,
44
+ ToolDefinition,
45
+ Property,
46
+ } from '@choiceopen/atomemo-plugin-schema/types';
47
+ ```
48
+
49
+ ### 导入 Schema
50
+
51
+ ```typescript
52
+ import {
53
+ PluginDefinitionSchema,
54
+ CredentialDefinitionSchema,
55
+ DataSourceDefinitionSchema,
56
+ ModelDefinitionSchema,
57
+ ToolDefinitionSchema,
58
+ PropertySchema,
59
+ } from '@choiceopen/atomemo-plugin-schema/schemas';
60
+ ```
61
+
62
+ ### 示例:定义一个插件
63
+
64
+ ```typescript
65
+ import { PluginDefinitionSchema } from '@choiceopen/atomemo-plugin-schema/schemas';
66
+ import type { PluginDefinition } from '@choiceopen/atomemo-plugin-schema/types';
67
+
68
+ const pluginDefinition: PluginDefinition = {
69
+ name: 'my-plugin',
70
+ display_name: {
71
+ en_US: 'My Plugin',
72
+ zh_CN: '我的插件',
73
+ },
74
+ description: {
75
+ en_US: 'A sample plugin for Atomemo',
76
+ zh_CN: '一个示例插件',
77
+ },
78
+ icon: 'https://example.com/icon.png',
79
+ version: '1.0.0',
80
+ locales: ['en', 'zh_CN'],
81
+ };
82
+
83
+ // 运行时验证
84
+ const result = PluginDefinitionSchema.safeParse(pluginDefinition);
85
+ if (!result.success) {
86
+ console.error('验证失败:', result.error);
87
+ }
88
+ ```
89
+
90
+ ## 核心概念
91
+
92
+ ### 插件定义
93
+
94
+ 插件定义包含插件的元数据:
95
+
96
+ - 基本信息:名称、显示名称、描述、图标
97
+ - 作者信息:名称、邮箱、仓库 URL、版本
98
+ - 支持的语言列表
99
+
100
+ ### 功能定义
101
+
102
+ 功能定义包括:
103
+
104
+ - **Credential(凭证)**: 用于存储和管理认证信息
105
+ - **DataSource(数据源)**: 用于连接外部数据源
106
+ - **Model(模型)**: 用于定义 LLM 模型
107
+ - **Tool(工具)**: 用于执行特定功能
108
+
109
+ ### 属性系统
110
+
111
+ 属性系统是定义插件参数和设置的核心:
112
+
113
+ **属性类型:**
114
+ - `string`: 字符串类型
115
+ - `number` / `integer`: 数字类型
116
+ - `boolean`: 布尔类型
117
+ - `array`: 数组类型
118
+ - `object`: 对象类型
119
+ - `discriminated_union`: 区分联合类型
120
+ - `credential_id`: 凭证 ID 类型
121
+ - `encrypted_string`: 加密字符串类型
122
+
123
+ **属性特性:**
124
+ - 常量值(`constant`)
125
+ - 默认值(`default`)
126
+ - 枚举值(`enum`)
127
+ - 范围限制(`min_length`、`max_length`、`minimum`、`maximum`、`min_items`、`max_items`)
128
+ - 条件显示(`display.hide/show`)
129
+ - AI 配置(`ai.llm_description`)
130
+
131
+ ### UI 组件系统
132
+
133
+ 每个属性类型可以配置不同的 UI 组件:
134
+
135
+ **字符串类型可用组件:**
136
+ - `input`、`textarea`、`code-editor`
137
+ - `select`、`radio-group`
138
+ - `emoji-picker`、`color-picker`、`credential-select`
139
+
140
+ **数字类型可用组件:**
141
+ - `number-input`、`slider`
142
+
143
+ **布尔类型可用组件:**
144
+ - `switch`、`checkbox`
145
+
146
+ **数组类型可用组件:**
147
+ - `multi-select`、`tag-input`、`key-value-editor`、`slider`、`array-section`
148
+
149
+ **对象类型可用组件:**
150
+ - `collapsible-panel`、`json-schema-editor`、`conditions-editor`、`code-editor`
151
+
152
+ ### 条件显示系统
153
+
154
+ 支持基于其他属性值的条件显示逻辑:
155
+
156
+ **操作符:**
157
+ - 比较操作符:`$eq`、`$ne`、`$gt`、`$gte`、`$lt`、`$lte`
158
+ - 存在性检查:`$exists`
159
+ - 集合操作:`$in`、`$nin`
160
+ - 正则匹配:`$regex`、`$options`
161
+ - 数组操作:`$size`、`$mod`
162
+ - 逻辑组合:`$and`、`$or`、`$nor`
163
+
164
+ ## API 参考
165
+
166
+ ### 导出
167
+
168
+ 包导出两个主要入口点:
169
+
170
+ - `@choiceopen/atomemo-plugin-schema/types` - TypeScript 类型定义
171
+ - `@choiceopen/atomemo-plugin-schema/schemas` - Zod Schema 验证器
172
+
173
+ ### 开发环境导出
174
+
175
+ 在开发环境中,包直接导出源文件,以便更好地调试和支持热重载:
176
+
177
+ ```json
178
+ {
179
+ "./schemas": {
180
+ "development": "./src/schemas.ts",
181
+ "default": "./dist/schemas.js"
182
+ },
183
+ "./types": {
184
+ "development": "./src/types.ts",
185
+ "default": "./dist/types.js"
186
+ }
187
+ }
188
+ ```
189
+
190
+ ## 开发
191
+
192
+ ### 前置要求
193
+
194
+ - [Bun](https://bun.sh) >= 1.0.0
195
+ - Node.js >= 18.0.0(如果不使用 Bun)
196
+
197
+ ### 设置
198
+
199
+ ```bash
200
+ # 安装依赖
201
+ bun install
202
+ ```
203
+
204
+ ### 可用脚本
205
+
206
+ ```bash
207
+ # 开发模式监听并重新构建
208
+ bun run dev
209
+
210
+ # 构建库
211
+ bun run build
212
+
213
+ # 运行代码检查和格式化
214
+ bun run check
215
+
216
+ # 运行类型检查
217
+ bun run typecheck
218
+
219
+ # 运行单元测试
220
+ bun run test
221
+ ```
222
+
223
+ ### 代码质量
224
+
225
+ 本项目使用 [Biome](https://biomejs.dev) 进行统一的代码检查和格式化。为了获得最佳的开发体验,请安装 [Biome VS Code 扩展](https://marketplace.visualstudio.com/items?itemName=biomejs.biome)。
226
+
227
+ ## 项目结构
228
+
229
+ ```
230
+ atomemo-plugin-schema/
231
+ ├── src/ # 源代码
232
+ │ ├── schemas/ # Zod Schema 验证模块
233
+ │ ├── types/ # TypeScript 类型定义
234
+ │ ├── utils/ # 工具函数
235
+ │ ├── schemas.ts # Schema 导出
236
+ │ └── types.ts # 类型导出
237
+ ├── tests/ # 测试文件
238
+ ├── dist/ # 构建输出
239
+ └── [配置文件] # package.json, tsconfig.json 等
240
+ ```
241
+
242
+ ## 贡献
243
+
244
+ 欢迎贡献!请遵循以下指南:
245
+
246
+ 1. 遵循项目的代码风格(使用 Biome 进行格式化)
247
+ 2. 确保所有测试通过
248
+ 3. 确保类型安全(使用 `IsEqual` 进行验证)
249
+ 4. 更新相关文档
250
+ 5. 提交前运行 `bun run check` 和 `bun run test`
251
+
252
+ ### 开发工作流
253
+
254
+ 1. Fork 仓库
255
+ 2. 创建功能分支(`git checkout -b feature/amazing-feature`)
256
+ 3. 进行更改
257
+ 4. 运行测试和代码检查(`bun run check && bun run test`)
258
+ 5. 提交更改(`git commit -m '添加一些很棒的功能'`)
259
+ 6. 推送到分支(`git push origin feature/amazing-feature`)
260
+ 7. 打开 Pull Request
261
+
262
+ ## 变更日志
263
+
264
+ 查看 [CHANGELOG.md](./CHANGELOG.md) 了解变更列表和版本历史。
265
+
266
+ ## 许可证
267
+
268
+ 本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
269
+
270
+ ## 支持
271
+
272
+ - 📖 [文档](https://github.com/choice-open/atomemo-plugin-schema#readme)
273
+ - 🐛 [问题追踪](https://github.com/choice-open/atomemo-plugin-schema/issues)
274
+ - 💬 [讨论](https://github.com/choice-open/atomemo-plugin-schema/discussions)
275
+
276
+ ## 致谢
277
+
278
+ - 使用 [TypeScript](https://www.typescriptlang.org/) 构建
279
+ - Schema 验证由 [Zod](https://zod.dev/) 提供支持
280
+ - 工具类型来自 [type-fest](https://github.com/sindresorhus/type-fest)