|
| 1 | +--- |
| 2 | +title: 插件描述清单 Schema |
| 3 | +group: Schema |
| 4 | +atomId: pluginManifestSchema |
| 5 | +description: 插件描述文件的 Schema |
| 6 | +nav: API |
| 7 | +--- |
| 8 | + |
| 9 | +## pluginManifestSchema |
| 10 | + |
| 11 | +**描述**:插件的清单文件(Manifest)数据模式定义。 |
| 12 | + |
| 13 | +### 使用示例 |
| 14 | + |
| 15 | +```typescript |
| 16 | +import { pluginManifestSchema } from '@lobehub/chat-plugin-sdk'; |
| 17 | + |
| 18 | +const manifestData = { |
| 19 | + api: [ |
| 20 | + { |
| 21 | + description: 'API 描述', |
| 22 | + name: 'API 名称', |
| 23 | + parameters: { |
| 24 | + properties: {}, |
| 25 | + type: 'object', |
| 26 | + }, |
| 27 | + url: 'http://example.com/api', |
| 28 | + }, |
| 29 | + ], |
| 30 | + gateway: 'http://example.com/gateway', |
| 31 | + identifier: 'plugin-identifier', |
| 32 | + openapi: 'http://example.com/openapi', |
| 33 | + settings: { |
| 34 | + properties: {}, |
| 35 | + type: 'object', |
| 36 | + }, |
| 37 | + ui: { |
| 38 | + height: 500, |
| 39 | + mode: 'iframe', |
| 40 | + url: 'http://example.com/plugin', |
| 41 | + width: 800, |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +const result = pluginManifestSchema.parse(manifestData); |
| 46 | + |
| 47 | +console.log(result); |
| 48 | + |
| 49 | +// 输出:{ api: [ { description: 'API 描述', name: 'API 名称', parameters: { properties: {}, type: 'object' }, url: 'http://example.com/api' } ], gateway: 'http://example.com/gateway', identifier: 'plugin-identifier', openapi: 'http://example.com/openapi', settings: { properties: {}, type: 'object' }, ui: { height: 500, mode: 'iframe', url: 'http://example.com/plugin', width: 800 } } |
| 50 | +``` |
| 51 | + |
| 52 | +## `pluginApiSchema` |
| 53 | + |
| 54 | +**描述**:插件 API 的数据模式定义。 |
| 55 | + |
| 56 | +```typescript |
| 57 | +import { z } from 'zod'; |
| 58 | + |
| 59 | +const JSONSchema = z.object({ |
| 60 | + properties: z.object({}), |
| 61 | + type: z.enum(['object']), |
| 62 | +}); |
| 63 | + |
| 64 | +const pluginApiSchema = z.object({ |
| 65 | + description: z.string(), |
| 66 | + name: z.string(), |
| 67 | + parameters: JSONSchema, |
| 68 | + url: z.string().url(), |
| 69 | +}); |
| 70 | + |
| 71 | +export default pluginApiSchema; |
| 72 | +``` |
| 73 | + |
| 74 | +### 使用示例 |
| 75 | + |
| 76 | +```typescript |
| 77 | +import { pluginApiSchema } from '@lobehub/chat-plugin-sdk'; |
| 78 | + |
| 79 | +const apiData = { |
| 80 | + description: 'API 描述', |
| 81 | + name: 'API 名称', |
| 82 | + parameters: { |
| 83 | + properties: {}, |
| 84 | + type: 'object', |
| 85 | + }, |
| 86 | + url: 'http://example.com/api', |
| 87 | +}; |
| 88 | + |
| 89 | +const result = pluginApiSchema.parse(apiData); |
| 90 | +console.log(result); |
| 91 | +// 输出:{ description: 'API 描述', name: 'API 名称', parameters: { properties: {}, type: 'object' }, url: 'http://example.com/api' } |
| 92 | +``` |
| 93 | + |
| 94 | +## Schema 定义 |
| 95 | + |
| 96 | +### pluginManifestSchema |
| 97 | + |
| 98 | +| 属性 | 类型 | 描述 | |
| 99 | +| ------------ | ------------------- | ----------------------- | |
| 100 | +| `api` | `pluginApiSchema[]` | 插件的 API 列表 | |
| 101 | +| `gateway` | `string` (可选) | 插件的网关 URL | |
| 102 | +| `identifier` | `string` | 插件的标识符 | |
| 103 | +| `openapi` | `string` (可选) | 插件的 OpenAPI 文档 URL | |
| 104 | +| `settings` | `JSONSchema` (可选) | 插件的设置数据定义 | |
| 105 | +| `ui` | `object` (可选) | 插件的 UI 配置 | |
| 106 | +| `ui.height` | `number` (可选) | 插件 UI 的高度 | |
| 107 | +| `ui.mode` | `'iframe'` (可选) | 插件 UI 的模式 | |
| 108 | +| `ui.url` | `string` | 插件 UI 的 URL | |
| 109 | +| `ui.width` | `number` (可选) | 插件 UI 的宽度 | |
| 110 | + |
| 111 | +### pluginApiSchema |
| 112 | + |
| 113 | +| 属性 | 类型 | 描述 | |
| 114 | +| ------------- | ------------ | ------------------- | |
| 115 | +| `description` | `string` | 插件 API 的描述 | |
| 116 | +| `name` | `string` | 插件 API 的名称 | |
| 117 | +| `parameters` | `JSONSchema` | 插件 API 的参数定义 | |
| 118 | +| `url` | `string` | 插件 API 的 URL | |
0 commit comments