Skip to content

Commit

Permalink
✨ feat: add plugin types
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Aug 18, 2023
1 parent b458dde commit 5cac112
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 11 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"eslint --fix"
]
},
"dependencies": {
"@types/json-schema": "^7.0.12"
},
"devDependencies": {
"@commitlint/cli": "^17",
"@lobehub/lint": "latest",
Expand Down
200 changes: 200 additions & 0 deletions src/types/chatGPT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
export interface ChatGPTPluginManifest {
HttpAuthorizationType?: HttpAuthorizationType;
ManifestAuthType?: ManifestAuthType;
/**
* API specification
* @desc The specification for the plugin's API
* @nameCN API规范
* @descCN OpenAI 插件的 API 规范
*/
api: {
/**
* Type of API specification
* @desc The type of the API specification
* @nameCN API规范的类型
* @descCN API规范的类型
*/
type: 'openapi';
/**
* URL of the OpenAPI specification file
* @desc The URL of the OpenAPI specification file
* @nameCN OpenAPI规范文件的URL
* @descCN OpenAPI规范文件的URL
*/
url: string;
};
/**
* Authentication schema
* @desc The authentication schema for the plugin
* @nameCN 认证模式
* @descCN 插件的认证模式
*/
auth: ManifestAuth;
/**
* Email contact for safety/moderation, support, and deactivation
* @desc The email contact for safety/moderation, support, and deactivation of the plugin
* @nameCN 邮件联系方式
* @descCN 插件的安全/审核,支持和停用的电子邮件联系方式
*/
contact_email: string;
/**
* Human-readable description of the plugin. 100 character max.
* @desc A human-readable description of the plugin. Maximum length of 100 characters.
* @nameCN 给用户看的描述信息
* @descCN 最大长度为100个字符。
*/
description_for_human: string;
/**
* Description better tailored to the model
* @desc A description of the plugin that is better tailored to the model. It can include considerations for token context length or keyword usage to improve plugin prompting. Maximum length of 8,000 characters.
* @nameCN 给模型看的描述
* @descCN 更适合模型的描述,可以包括对令牌上下文长度或关键字使用的考虑,以改进插件提示。最大长度为8,000个字符。
*/
description_for_model: string;
/**
* Redirect URL for users to view plugin information
* @desc The redirect URL for users to view information about the plugin
* @nameCN 重定向URL,用于用户查看插件信息
* @descCN 用户查看插件信息的重定向URL
*/
legal_info_url: string;
/**
* Plugin Logo URL
* @desc The URL used to fetch the logo of the plugin. It should have a suggested size of 512 x 512 pixels. Transparent backgrounds are supported. Only images are allowed, GIFs are not allowed.
* @nameCN 插件 Logo URL
* @descCN 用于获取插件徽标的URL。建议大小为 512 x 512 px。支持透明背景。只允许图片,不允许GIF。
*/
logo_url: string;
/**
* Human-readable Name
* @desc The human-readable name of the plugin, such as the full company name. Maximum length of 20 characters.
* @nameCN 给用户看的名称
* @descCN 比如完整的公司名称。最大长度为20个字符。
*/
name_for_human: string;

/**
* Name the model will use to target the plugin
* @desc The name that the model will use to target the plugin. It should not contain any spaces and should only consist of letters and numbers. Maximum length of 50 characters.
* @nameCN 给模型看的插件名称
* @descCN 帮助模型定位插件的名称。它不应包含任何空格,只能由字母和数字组成。最大长度为50个字符。
*/
name_for_model: string;
/**
* Manifest schema version
* @desc The version of the plugin manifest schema
* @nameCN 插件清单的版本
*/
schema_version: 'v1';
}

// Authentication schema types

/**
* Type of HTTP authorization
*/
export type HttpAuthorizationType = 'bearer' | 'basic';

/**
* Type of authentication
*/
export type ManifestAuthType = 'none' | 'user_http' | 'service_http' | 'oauth';

/**
* Base authentication schema
*/
export interface BaseManifestAuth {
/**
* Instructions for authentication
*/
instructions: string;
/**
* Type of authentication
*/
type: ManifestAuthType;
}

/**
* No authentication required
*/
export interface ManifestNoAuth extends BaseManifestAuth {
/**
* Type of authentication
*/
type: 'none';
}

/**
* Service-level HTTP authentication
*/
export interface ManifestServiceHttpAuth extends BaseManifestAuth {
/**
* Type of HTTP authorization
*/
authorization_type: HttpAuthorizationType;
/**
* Type of authentication
*/
type: 'service_http';
/**
* Verification tokens for service
*/
verification_tokens?: {
[service: string]: string;
};
}

/**
* User-level HTTP authentication
*/
export interface ManifestUserHttpAuth extends BaseManifestAuth {
/**
* Type of HTTP authorization
*/
authorization_type: HttpAuthorizationType;
/**
* Type of authentication
*/
type: 'user_http';
}

/**
* OAuth authentication
*/
export interface ManifestOAuthAuth extends BaseManifestAuth {
/**
* When exchanging OAuth code with access token, the expected header 'content-type'. For example: 'content-type: application/json'
*/
authorization_content_type: string;
/**
* Endpoint used to exchange OAuth code with access token.
*/
authorization_url: string;
/**
* OAuth URL where a user is directed to for the OAuth authentication flow to begin.
*/
client_url: string;
/**
* OAuth scopes required to accomplish operations on the user's behalf.
*/
scope: string;
/**
* Type of authentication
*/
type: 'oauth';
/**
* Verification tokens for service
*/
verification_tokens?: {
[service: string]: string;
};
}

/**
* Authentication schema
*/
export type ManifestAuth =
| ManifestNoAuth
| ManifestServiceHttpAuth
| ManifestUserHttpAuth
| ManifestOAuthAuth;
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './chatGPT';
export * from './manifest';
export * from './market';
70 changes: 65 additions & 5 deletions src/types/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
export interface PluginManifest {
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';

/**
* Plugin Schema
* @desc the schema of plugin, describe the api input of the function
* @nameCN 插件清单
* @descCN 描述一个插件的构成要素
*/
export interface PluginSchema extends Omit<JSONSchema7, 'type'> {
properties: {
[key: string]: JSONSchema7Definition;
};
type: 'object';
}

/**
* Plugin manifest
* @desc Represents the manifest of a plugin
* @nameCN 插件清单
* @descCN 描述一个插件的构成要素
*/
export interface LobeChatPlugin {
/**
* Creation date
* @desc The date when the plugin was added
* @nameCN 创建日期
* @descCN 添加该插件的日期
*/
createAt: string;
endpoint: string;
/**
* Plugin name
* @desc The name of the plugin
* @nameCN 插件名称
* @descCN 插件的名称,需要和提交到 LobeChat Plugins 仓库的插件名称一致
*/
name: string;
render?: string;

schema: any;
/**
* Plugin schema
* @desc The schema of the plugin
* @nameCN 插件模式
* @descCN 插件的模式
*/
schema: PluginSchema;
server: {
/**
* Endpoint URL
* @desc The endpoint URL of the plugin
* @nameCN 服务端接口
* @descCN 插件服务端的接口地址 URL
*/
url: string;
};
/**
* plugin ui on user side
* @desc The type of rendering for the plugin
* @nameCN 用户界面
* @descCN 插件在用户侧的展示内容
*/
ui?: {
/**
* component url
* @desc The type of rendering for the plugin
* @nameCN 动态组件
* @descCN 插件的渲染类型
*/
url?: string;
};
}
87 changes: 81 additions & 6 deletions src/types/market.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,92 @@
export interface PluginItem {
/**
* Lobe Chat Plugins
* @desc Lobe Chat Plugins interface
* @nameCN 插件列表
* @descCN 插件市场的列表接口
*/
export interface LobeChatPlugins {
/**
* plugins
* @desc List of plugin items
* @nameCN 插件列表
* @descCN 插件项列表
*/
plugins: LobeChatPluginManifest[];
/**
* version
* @desc Version of the plugins
* @nameCN 版本
* @descCN 插件的版本
*/
version: 1;
}

/**
* Plugin Item
* @desc Plugin item interface
* @nameCN 插件项
* @descCN 插件项接口
*/
export interface LobeChatPluginManifest {
/**
* createAt
* @desc Creation date of the plugin
* @nameCN 创建时间
* @descCN 插件的创建时间
*/
createAt: string;
/**
* homepage
* @desc Homepage of the plugin
* @nameCN 主页
* @descCN 插件的主页
*/
homepage: string;
/**
* manifest url of this plugin
* @desc Manifest of the plugin
* @nameCN 插件的线上 manifest url
*/
manifest: string;
/**
* metadata
* @desc Meta data of the plugin
* @nameCN 插件元数据
* @descCN 包含图片与标签等
*/
meta: Meta;
/**
* plugin name
* @nameCN 插件的名称
*/
name: string;
/**
* Manifest schema version
* @desc The version of the plugin manifest schema
* @nameCN 插件清单的版本
*/
schemaVersion: 'v1';
}

/**
* Meta
* @desc Meta data interface
* @nameCN 元数据
* @descCN 元数据接口
*/
export interface Meta {
/**
* avatar
* @desc Avatar of the plugin
* @nameCN 头像
* @descCN 插件的头像
*/
avatar: string;
/**
* tags
* @desc Tags of the plugin
* @nameCN 标签
* @descCN 插件的标签
*/
tags: string[];
}

export interface LobeChatPlugins {
plugins: PluginItem[];
version: 1;
}

0 comments on commit 5cac112

Please sign in to comment.