@tais00/core 0.7.0
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/README.md +172 -0
- package/dist/constants/app.d.ts +66 -0
- package/dist/constants/index.d.ts +35 -0
- package/dist/enums/index.d.ts +13 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/use-apps.d.ts +31 -0
- package/dist/hooks/use-conversations.d.ts +40 -0
- package/dist/hooks/use-dify-chat.d.ts +63 -0
- package/dist/index.cjs +3956 -0
- package/dist/index.cjs.LICENSE.txt +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3849 -0
- package/dist/index.js.LICENSE.txt +1 -0
- package/dist/repository/app/index.d.ts +158 -0
- package/dist/repository/index.d.ts +1 -0
- package/dist/types/index.d.ts +227 -0
- package/dist/utils/index.d.ts +6 -0
- package/package.json +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { AppModeEnums } from '../../constants';
|
|
2
|
+
import { EIsEnabled } from '../../enums';
|
|
3
|
+
export interface IDifyAppRequestConfig {
|
|
4
|
+
/**
|
|
5
|
+
* 请求地址
|
|
6
|
+
*/
|
|
7
|
+
apiBase: string;
|
|
8
|
+
/**
|
|
9
|
+
* Dify APP API 密钥
|
|
10
|
+
*/
|
|
11
|
+
apiKey: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 参数配置 Item
|
|
15
|
+
*/
|
|
16
|
+
export interface IParamItem {
|
|
17
|
+
variable: string;
|
|
18
|
+
required: boolean;
|
|
19
|
+
hide: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 应用配置 Item
|
|
23
|
+
*/
|
|
24
|
+
export interface IDifyAppItem {
|
|
25
|
+
/**
|
|
26
|
+
* 唯一标识
|
|
27
|
+
*/
|
|
28
|
+
id: string;
|
|
29
|
+
/**
|
|
30
|
+
* Dify 应用基本信息
|
|
31
|
+
*/
|
|
32
|
+
info: {
|
|
33
|
+
/**
|
|
34
|
+
* 应用名称
|
|
35
|
+
*/
|
|
36
|
+
name: string;
|
|
37
|
+
/**
|
|
38
|
+
* 应用类型
|
|
39
|
+
*/
|
|
40
|
+
mode?: AppModeEnums;
|
|
41
|
+
/**
|
|
42
|
+
* 应用描述
|
|
43
|
+
*/
|
|
44
|
+
description: string;
|
|
45
|
+
/**
|
|
46
|
+
* 应用标签
|
|
47
|
+
*/
|
|
48
|
+
tags: string[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 应用状态 1-启用 2-禁用
|
|
52
|
+
*/
|
|
53
|
+
isEnabled: EIsEnabled;
|
|
54
|
+
/**
|
|
55
|
+
* 请求配置
|
|
56
|
+
*/
|
|
57
|
+
requestConfig: IDifyAppRequestConfig;
|
|
58
|
+
/**
|
|
59
|
+
* 回复表单配置
|
|
60
|
+
*/
|
|
61
|
+
answerForm?: {
|
|
62
|
+
/**
|
|
63
|
+
* 是否启用
|
|
64
|
+
*/
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 反馈的占位文字
|
|
68
|
+
*/
|
|
69
|
+
feedbackText?: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 输入参数配置
|
|
73
|
+
*/
|
|
74
|
+
inputParams?: {
|
|
75
|
+
/**
|
|
76
|
+
* 开始对话后,是否支持更新对话参数
|
|
77
|
+
*/
|
|
78
|
+
enableUpdateAfterCvstStarts: boolean;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* 其他扩展配置
|
|
82
|
+
*/
|
|
83
|
+
extConfig?: {
|
|
84
|
+
/**
|
|
85
|
+
* 对话相关配置
|
|
86
|
+
*/
|
|
87
|
+
conversation?: {
|
|
88
|
+
/**
|
|
89
|
+
* 开场白配置
|
|
90
|
+
*/
|
|
91
|
+
openingStatement?: {
|
|
92
|
+
/**
|
|
93
|
+
* 展示模式 default-默认(对话开始后不展示) always-固定展示
|
|
94
|
+
*/
|
|
95
|
+
displayMode?: 'default' | 'always';
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* 标注相关配置
|
|
100
|
+
*/
|
|
101
|
+
annotation?: {
|
|
102
|
+
/**
|
|
103
|
+
* 是否启用
|
|
104
|
+
*/
|
|
105
|
+
enabled: boolean;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 应用服务的公共方法定义
|
|
111
|
+
*/
|
|
112
|
+
declare abstract class DifyAppStoreBase {
|
|
113
|
+
/**
|
|
114
|
+
* 是否只读
|
|
115
|
+
*/
|
|
116
|
+
abstract readonly?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* 获取 App 列表
|
|
119
|
+
*/
|
|
120
|
+
abstract getApps(): Promise<IDifyAppItem[]>;
|
|
121
|
+
/**
|
|
122
|
+
* 通过 id 获取 App 详情
|
|
123
|
+
*/
|
|
124
|
+
abstract getApp(id: string): Promise<IDifyAppItem | undefined>;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 只读的应用服务抽象类,只提供列表和详情接口
|
|
128
|
+
* 只需实现 getApps 和 getApp 方法,其他方法不会被调用
|
|
129
|
+
*/
|
|
130
|
+
export declare abstract class DifyAppStoreReadonly extends DifyAppStoreBase {
|
|
131
|
+
/**
|
|
132
|
+
* 声明只读
|
|
133
|
+
*/
|
|
134
|
+
abstract readonly: true;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 完整的应用服务抽象类,支持增删改查
|
|
138
|
+
* 需实现 getApps、getApp、addApp、updateApp 和 deleteApp 方法
|
|
139
|
+
*/
|
|
140
|
+
export declare abstract class DifyAppStore extends DifyAppStoreBase {
|
|
141
|
+
/**
|
|
142
|
+
* 声明可读写
|
|
143
|
+
*/
|
|
144
|
+
abstract readonly: false;
|
|
145
|
+
/**
|
|
146
|
+
* 新增 App
|
|
147
|
+
*/
|
|
148
|
+
abstract addApp(app: IDifyAppItem): Promise<unknown>;
|
|
149
|
+
/**
|
|
150
|
+
* 更新 App
|
|
151
|
+
*/
|
|
152
|
+
abstract updateApp(app: IDifyAppItem): Promise<unknown>;
|
|
153
|
+
/**
|
|
154
|
+
* 删除 App
|
|
155
|
+
*/
|
|
156
|
+
abstract deleteApp(id: string): Promise<unknown>;
|
|
157
|
+
}
|
|
158
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './app';
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dify 支持的文件类型
|
|
3
|
+
*/
|
|
4
|
+
export type IFileType = 'document' | 'image' | 'audio' | 'video' | 'custom';
|
|
5
|
+
/**
|
|
6
|
+
* 用户输入表单控件类型
|
|
7
|
+
*/
|
|
8
|
+
export type IUserInputFormItemType = 'text-input' | 'paragraph' | 'select' | 'number' | 'file' | 'file-list';
|
|
9
|
+
/**
|
|
10
|
+
* 用户输入表单控件对象
|
|
11
|
+
*/
|
|
12
|
+
export interface IUserInputFormItemValueBase {
|
|
13
|
+
default: string;
|
|
14
|
+
label: string;
|
|
15
|
+
required: boolean;
|
|
16
|
+
variable: string;
|
|
17
|
+
/**
|
|
18
|
+
* 是否隐藏
|
|
19
|
+
*/
|
|
20
|
+
hide?: boolean;
|
|
21
|
+
options?: string[];
|
|
22
|
+
/**
|
|
23
|
+
* 最大长度
|
|
24
|
+
*/
|
|
25
|
+
max_length?: number;
|
|
26
|
+
/**
|
|
27
|
+
* 输入参数类型
|
|
28
|
+
*/
|
|
29
|
+
type: IUserInputFormItemType;
|
|
30
|
+
/**
|
|
31
|
+
* 允许的文件类型
|
|
32
|
+
*/
|
|
33
|
+
allowed_file_types?: IFileType[];
|
|
34
|
+
/**
|
|
35
|
+
* 允许的文件后缀名
|
|
36
|
+
*/
|
|
37
|
+
allowed_file_extensions?: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 应用输入配置
|
|
41
|
+
*/
|
|
42
|
+
export type IUserInputForm = Record<IUserInputFormItemType, IUserInputFormItemValueBase>;
|
|
43
|
+
export interface IDifyAppParameters {
|
|
44
|
+
/**
|
|
45
|
+
* 开场白
|
|
46
|
+
*/
|
|
47
|
+
opening_statement?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 用户输入表单
|
|
50
|
+
*/
|
|
51
|
+
user_input_form: IUserInputForm[];
|
|
52
|
+
/**
|
|
53
|
+
* 开场建议问题
|
|
54
|
+
*/
|
|
55
|
+
suggested_questions?: string[];
|
|
56
|
+
/**
|
|
57
|
+
* 下一轮问题建议
|
|
58
|
+
*/
|
|
59
|
+
suggested_questions_after_answer: {
|
|
60
|
+
/**
|
|
61
|
+
* 是否启用
|
|
62
|
+
*/
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 文件上传参数
|
|
67
|
+
*/
|
|
68
|
+
file_upload: {
|
|
69
|
+
/**
|
|
70
|
+
* 是否允许上传文件
|
|
71
|
+
*/
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* 允许上传的文件后缀名
|
|
75
|
+
*/
|
|
76
|
+
allowed_file_extensions: string[];
|
|
77
|
+
/**
|
|
78
|
+
* 允许上传的文件类型
|
|
79
|
+
*/
|
|
80
|
+
allowed_file_types: IFileType[];
|
|
81
|
+
/**
|
|
82
|
+
* 允许的上传方式 - remote_url-远程地址 local_file-本地文件
|
|
83
|
+
*/
|
|
84
|
+
allowed_file_upload_methods: Array<'remote_url' | 'local_file'>;
|
|
85
|
+
/**
|
|
86
|
+
* 文件上传配置
|
|
87
|
+
*/
|
|
88
|
+
fileUploadConfig: {
|
|
89
|
+
/**
|
|
90
|
+
* 文件大小限制(单位:MB)
|
|
91
|
+
*/
|
|
92
|
+
file_size_limit: number;
|
|
93
|
+
/**
|
|
94
|
+
* 批量上传文件数量限制
|
|
95
|
+
*/
|
|
96
|
+
batch_count_limit: number;
|
|
97
|
+
/**
|
|
98
|
+
* 图片文件大小限制(单位:MB)
|
|
99
|
+
*/
|
|
100
|
+
image_file_size_limit: number;
|
|
101
|
+
/**
|
|
102
|
+
* 视频文件大小限制(单位:MB)
|
|
103
|
+
*/
|
|
104
|
+
video_file_size_limit: number;
|
|
105
|
+
/**
|
|
106
|
+
* 音频文件大小限制(单位:MB)
|
|
107
|
+
*/
|
|
108
|
+
audio_file_size_limit: number;
|
|
109
|
+
/**
|
|
110
|
+
* 工作流文件上传限制(单位:MB)
|
|
111
|
+
*/
|
|
112
|
+
workflow_file_upload_limit: number;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* 图片上传配置
|
|
116
|
+
*/
|
|
117
|
+
image: {
|
|
118
|
+
/**
|
|
119
|
+
* 是否启用图片上传
|
|
120
|
+
*/
|
|
121
|
+
enabled: false;
|
|
122
|
+
/**
|
|
123
|
+
* 允许上传的图片最大数量
|
|
124
|
+
*/
|
|
125
|
+
number_limits: 3;
|
|
126
|
+
/**
|
|
127
|
+
* 允许的上传方式 - remote_url-远程地址 local_file-本地文件
|
|
128
|
+
*/
|
|
129
|
+
transfer_methods: ['local_file', 'remote_url'];
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* 允许上传的文件数量
|
|
133
|
+
*/
|
|
134
|
+
number_limits: number;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* 文本转语音配置
|
|
138
|
+
*/
|
|
139
|
+
text_to_speech: {
|
|
140
|
+
/**
|
|
141
|
+
* 是否启用
|
|
142
|
+
*/
|
|
143
|
+
enabled: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* 是否开启自动播放 enabled-启用 disabled-禁用
|
|
146
|
+
*/
|
|
147
|
+
autoPlay: 'enabled' | 'disabled';
|
|
148
|
+
/**
|
|
149
|
+
* 语言
|
|
150
|
+
*/
|
|
151
|
+
language: string;
|
|
152
|
+
/**
|
|
153
|
+
* 音色
|
|
154
|
+
*/
|
|
155
|
+
voice: string;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* 语音转文本配置
|
|
159
|
+
*/
|
|
160
|
+
speech_to_text: {
|
|
161
|
+
/**
|
|
162
|
+
* 是否启用
|
|
163
|
+
*/
|
|
164
|
+
enabled: boolean;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 应用的 WebApp 配置
|
|
169
|
+
*/
|
|
170
|
+
export interface IDifyAppSiteSetting {
|
|
171
|
+
/**
|
|
172
|
+
* 应用标题
|
|
173
|
+
*/
|
|
174
|
+
title: string;
|
|
175
|
+
/**
|
|
176
|
+
* 聊天界面的主题色
|
|
177
|
+
*/
|
|
178
|
+
chat_color_theme: string;
|
|
179
|
+
/**
|
|
180
|
+
* 聊天界面颜色主题是否反转
|
|
181
|
+
*/
|
|
182
|
+
chat_color_theme_inverted: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* 图标类型, emoji-表情, image-图片
|
|
185
|
+
*/
|
|
186
|
+
icon_type: 'emoji' | 'image';
|
|
187
|
+
/**
|
|
188
|
+
* 图标, 如果是 emoji 类型, 则是 emoji 表情符号, 如果是 image 类型, 则是图片 URL
|
|
189
|
+
*/
|
|
190
|
+
icon: string;
|
|
191
|
+
/**
|
|
192
|
+
* hex 格式的背景色
|
|
193
|
+
*/
|
|
194
|
+
icon_background: string;
|
|
195
|
+
/**
|
|
196
|
+
* 图标链接,如果是 image 类型, 则是图片 URL
|
|
197
|
+
*/
|
|
198
|
+
icon_url?: string;
|
|
199
|
+
/**
|
|
200
|
+
* 应用描述
|
|
201
|
+
*/
|
|
202
|
+
description: string;
|
|
203
|
+
/**
|
|
204
|
+
* 版权信息
|
|
205
|
+
*/
|
|
206
|
+
copyright: string;
|
|
207
|
+
/**
|
|
208
|
+
* 隐私政策,可以自定义链接
|
|
209
|
+
*/
|
|
210
|
+
privacy_policy: string;
|
|
211
|
+
/**
|
|
212
|
+
* 自定义免责声明内容
|
|
213
|
+
*/
|
|
214
|
+
custom_disclaimer: string;
|
|
215
|
+
/**
|
|
216
|
+
* 默认语言 如 en-US zh-CN
|
|
217
|
+
*/
|
|
218
|
+
default_language: string;
|
|
219
|
+
/**
|
|
220
|
+
* 是否显示工作流步骤
|
|
221
|
+
*/
|
|
222
|
+
show_workflow_steps: false;
|
|
223
|
+
/**
|
|
224
|
+
* 是否使用 WebApp 图标作为 AI 回复的图标
|
|
225
|
+
*/
|
|
226
|
+
use_icon_as_answer_icon: false;
|
|
227
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tais00/core",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Dify Chat 的核心包",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "lexmin0412",
|
|
7
|
+
"email": "zhangle_dev@outlook.com",
|
|
8
|
+
"url": "http://github.com/lexmin0412"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "github",
|
|
12
|
+
"url": "https://github.com/lexmin0412/dify-chat",
|
|
13
|
+
"directory": "packages/core"
|
|
14
|
+
},
|
|
15
|
+
"source": "./src/index.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"source": "./src/index.ts",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@tais00/helpers": "^0.7.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@biomejs/biome": "^1.9.4",
|
|
40
|
+
"@rslib/core": "^0.12.4",
|
|
41
|
+
"@types/node": "^22.14.1",
|
|
42
|
+
"@types/react": "^19.2.7",
|
|
43
|
+
"@types/react-dom": "^19.2.3",
|
|
44
|
+
"react": "^19.2.3",
|
|
45
|
+
"react-dom": "^19.2.3",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"vitest": "^3.2.3"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=16.9.0",
|
|
51
|
+
"react-dom": ">=16.9.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "rslib build",
|
|
55
|
+
"check": "biome check --write",
|
|
56
|
+
"dev": "rslib build --watch",
|
|
57
|
+
"format": "biome format --write",
|
|
58
|
+
"test": "vitest run"
|
|
59
|
+
}
|
|
60
|
+
}
|