feishu-mcp 0.0.15 → 0.0.16
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 +21 -21
- package/README.md +257 -251
- package/dist/cli.js +0 -0
- package/dist/config.js +26 -0
- package/dist/mcp/tools/feishuBlockTools.js +202 -252
- package/dist/mcp/tools/feishuFolderTools.js +22 -28
- package/dist/mcp/tools/feishuTools.js +54 -68
- package/dist/services/feishu.js +495 -0
- package/dist/services/feishuBlockService.js +179 -0
- package/dist/services/feishuBlocks.js +135 -0
- package/dist/services/feishuService.js +475 -0
- package/dist/types/feishuSchema.js +6 -15
- package/package.json +75 -75
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated 这个文件已被弃用,所有功能已迁移到BlockFactory类。
|
|
3
|
+
* 请使用BlockFactory创建各种块内容。
|
|
4
|
+
* 所有接口定义已迁移到blockFactory.ts文件。
|
|
5
|
+
* 此文件仅保留为历史兼容性目的,将在后续版本中移除。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 构建批量创建块的请求数据
|
|
9
|
+
* @param blocks 块内容数组
|
|
10
|
+
* @param index 插入位置索引
|
|
11
|
+
* @returns 请求数据对象
|
|
12
|
+
* @deprecated 请使用BlockFactory.buildCreateBlocksRequest
|
|
13
|
+
*/
|
|
14
|
+
export function buildCreateBlocksRequest(blocks, index = 0) {
|
|
15
|
+
return {
|
|
16
|
+
children: blocks,
|
|
17
|
+
index
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 创建文本块内容
|
|
22
|
+
* @param align 对齐方式:1左对齐,2居中,3右对齐
|
|
23
|
+
* @returns 文本块内容对象
|
|
24
|
+
* @deprecated 请使用BlockFactory.createTextBlock
|
|
25
|
+
*/
|
|
26
|
+
export function createTextBlockContent(textContents, align = 1) {
|
|
27
|
+
return {
|
|
28
|
+
block_type: 2, // 2表示文本块
|
|
29
|
+
text: {
|
|
30
|
+
elements: textContents.map(content => ({
|
|
31
|
+
text_run: {
|
|
32
|
+
content: content.text,
|
|
33
|
+
text_element_style: content.style || {}
|
|
34
|
+
}
|
|
35
|
+
})),
|
|
36
|
+
style: {
|
|
37
|
+
align: align // 1 居左,2 居中,3 居右
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 创建代码块内容
|
|
44
|
+
* @param code 代码内容
|
|
45
|
+
* @param language 语言类型代码
|
|
46
|
+
* @param wrap 是否自动换行
|
|
47
|
+
* @returns 代码块内容对象
|
|
48
|
+
* @deprecated 请使用BlockFactory.createCodeBlock
|
|
49
|
+
*/
|
|
50
|
+
export function createCodeBlockContent(code, language = 0, wrap = false) {
|
|
51
|
+
return {
|
|
52
|
+
block_type: 14, // 14表示代码块
|
|
53
|
+
code: {
|
|
54
|
+
elements: [
|
|
55
|
+
{
|
|
56
|
+
text_run: {
|
|
57
|
+
content: code,
|
|
58
|
+
text_element_style: {
|
|
59
|
+
bold: false,
|
|
60
|
+
inline_code: false,
|
|
61
|
+
italic: false,
|
|
62
|
+
strikethrough: false,
|
|
63
|
+
underline: false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
style: {
|
|
69
|
+
language: language,
|
|
70
|
+
wrap: wrap
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 创建标题块内容
|
|
77
|
+
* @param text 标题文本
|
|
78
|
+
* @param level 标题级别(1-9)
|
|
79
|
+
* @param align 对齐方式:1左对齐,2居中,3右对齐
|
|
80
|
+
* @returns 标题块内容对象
|
|
81
|
+
* @deprecated 请使用BlockFactory.createHeadingBlock
|
|
82
|
+
*/
|
|
83
|
+
export function createHeadingBlockContent(text, level = 1, align = 1) {
|
|
84
|
+
// 确保标题级别在有效范围内(1-9)
|
|
85
|
+
const safeLevel = Math.max(1, Math.min(9, level));
|
|
86
|
+
// 根据标题级别设置block_type和对应的属性名
|
|
87
|
+
// 飞书API中,一级标题的block_type为3,二级标题为4,以此类推
|
|
88
|
+
const blockType = 2 + safeLevel; // 一级标题为3,二级标题为4,以此类推
|
|
89
|
+
const headingKey = `heading${safeLevel}`; // heading1, heading2, ...
|
|
90
|
+
// 构建块内容
|
|
91
|
+
const blockContent = {
|
|
92
|
+
block_type: blockType
|
|
93
|
+
};
|
|
94
|
+
// 设置对应级别的标题属性
|
|
95
|
+
blockContent[headingKey] = {
|
|
96
|
+
elements: [
|
|
97
|
+
{
|
|
98
|
+
text_run: {
|
|
99
|
+
content: text,
|
|
100
|
+
text_element_style: {}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
style: {
|
|
105
|
+
align: align,
|
|
106
|
+
folded: false
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return blockContent;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 创建列表块内容(有序或无序)
|
|
113
|
+
* @param text 列表项文本
|
|
114
|
+
* @param isOrdered 是否为有序列表
|
|
115
|
+
* @param align 对齐方式:1左对齐,2居中,3右对齐
|
|
116
|
+
* @returns 列表块内容对象
|
|
117
|
+
* @deprecated 请使用BlockFactory.createListBlock
|
|
118
|
+
*/
|
|
119
|
+
export function createListBlockContent(text, isOrdered = false, align = 1) {
|
|
120
|
+
// 确保 align 值在合法范围内(1-3)
|
|
121
|
+
const safeAlign = (align === 1 || align === 2 || align === 3) ? align : 1;
|
|
122
|
+
// 有序列表是 block_type: 13,无序列表是 block_type: 12
|
|
123
|
+
const blockType = isOrdered ? 13 : 12;
|
|
124
|
+
const propertyKey = isOrdered ? "ordered" : "bullet";
|
|
125
|
+
// 构建块内容
|
|
126
|
+
const blockContent = {
|
|
127
|
+
block_type: blockType
|
|
128
|
+
};
|
|
129
|
+
// 设置列表属性
|
|
130
|
+
blockContent[propertyKey] = {
|
|
131
|
+
elements: [
|
|
132
|
+
{
|
|
133
|
+
text_run: {
|
|
134
|
+
content: text,
|
|
135
|
+
text_element_style: {}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
style: {
|
|
140
|
+
align: safeAlign,
|
|
141
|
+
folded: false
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return blockContent;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 处理Markdown语法转换
|
|
148
|
+
* @param textContents 文本内容数组
|
|
149
|
+
* @returns 处理后的文本内容数组
|
|
150
|
+
* @deprecated 应当避免使用Markdown语法,请直接使用TextElementStyle设置样式
|
|
151
|
+
*/
|
|
152
|
+
export function processMarkdownSyntax(textContents) {
|
|
153
|
+
return textContents.map(content => {
|
|
154
|
+
let { text, style = {} } = content;
|
|
155
|
+
// 创建一个新的style对象,避免修改原始对象
|
|
156
|
+
const newStyle = { ...style };
|
|
157
|
+
// 处理粗体 **text**
|
|
158
|
+
if (text.match(/\*\*([^*]+)\*\*/g)) {
|
|
159
|
+
text = text.replace(/\*\*([^*]+)\*\*/g, "$1");
|
|
160
|
+
newStyle.bold = true;
|
|
161
|
+
}
|
|
162
|
+
// 处理斜体 *text*
|
|
163
|
+
if (text.match(/(?<!\*)\*([^*]+)\*(?!\*)/g)) {
|
|
164
|
+
text = text.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "$1");
|
|
165
|
+
newStyle.italic = true;
|
|
166
|
+
}
|
|
167
|
+
// 处理删除线 ~~text~~
|
|
168
|
+
if (text.match(/~~([^~]+)~~/g)) {
|
|
169
|
+
text = text.replace(/~~([^~]+)~~/g, "$1");
|
|
170
|
+
newStyle.strikethrough = true;
|
|
171
|
+
}
|
|
172
|
+
// 处理行内代码 `code`
|
|
173
|
+
if (text.match(/`([^`]+)`/g)) {
|
|
174
|
+
text = text.replace(/`([^`]+)`/g, "$1");
|
|
175
|
+
newStyle.inline_code = true;
|
|
176
|
+
}
|
|
177
|
+
return { text, style: newStyle };
|
|
178
|
+
});
|
|
179
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 构建批量创建块的请求数据
|
|
3
|
+
* @param blocks 块内容数组
|
|
4
|
+
* @param index 插入位置索引
|
|
5
|
+
* @returns 请求数据对象
|
|
6
|
+
*/
|
|
7
|
+
export function buildCreateBlocksRequest(blocks, index = 0) {
|
|
8
|
+
return {
|
|
9
|
+
children: blocks,
|
|
10
|
+
index
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 创建文本块内容
|
|
15
|
+
* @param text 文本内容
|
|
16
|
+
* @param style 文本样式
|
|
17
|
+
* @param align 对齐方式:1左对齐,2居中,3右对齐
|
|
18
|
+
* @returns 文本块内容对象
|
|
19
|
+
*/
|
|
20
|
+
export function createTextBlockContent(textContents, align = 1) {
|
|
21
|
+
return {
|
|
22
|
+
block_type: 2, // 2表示文本块
|
|
23
|
+
text: {
|
|
24
|
+
elements: textContents.map(content => ({
|
|
25
|
+
text_run: {
|
|
26
|
+
content: content.text,
|
|
27
|
+
text_element_style: content.style || {}
|
|
28
|
+
}
|
|
29
|
+
})),
|
|
30
|
+
style: {
|
|
31
|
+
align: align // 1 居左,2 居中,3 居右
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 创建代码块内容
|
|
38
|
+
* @param code 代码内容
|
|
39
|
+
* @param language 语言类型代码
|
|
40
|
+
* @param wrap 是否自动换行
|
|
41
|
+
* @returns 代码块内容对象
|
|
42
|
+
*/
|
|
43
|
+
export function createCodeBlockContent(code, language = 0, wrap = false) {
|
|
44
|
+
return {
|
|
45
|
+
block_type: 14, // 14表示代码块
|
|
46
|
+
code: {
|
|
47
|
+
elements: [
|
|
48
|
+
{
|
|
49
|
+
text_run: {
|
|
50
|
+
content: code,
|
|
51
|
+
text_element_style: {
|
|
52
|
+
bold: false,
|
|
53
|
+
inline_code: false,
|
|
54
|
+
italic: false,
|
|
55
|
+
strikethrough: false,
|
|
56
|
+
underline: false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
style: {
|
|
62
|
+
language: language,
|
|
63
|
+
wrap: wrap
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 创建标题块内容
|
|
70
|
+
* @param text 标题文本
|
|
71
|
+
* @param level 标题级别(1-9)
|
|
72
|
+
* @param align 对齐方式:1左对齐,2居中,3右对齐
|
|
73
|
+
* @returns 标题块内容对象
|
|
74
|
+
*/
|
|
75
|
+
export function createHeadingBlockContent(text, level = 1, align = 1) {
|
|
76
|
+
// 确保标题级别在有效范围内(1-9)
|
|
77
|
+
const safeLevel = Math.max(1, Math.min(9, level));
|
|
78
|
+
// 根据标题级别设置block_type和对应的属性名
|
|
79
|
+
// 飞书API中,一级标题的block_type为3,二级标题为4,以此类推
|
|
80
|
+
const blockType = 2 + safeLevel; // 一级标题为3,二级标题为4,以此类推
|
|
81
|
+
const headingKey = `heading${safeLevel}`; // heading1, heading2, ...
|
|
82
|
+
// 构建块内容
|
|
83
|
+
const blockContent = {
|
|
84
|
+
block_type: blockType
|
|
85
|
+
};
|
|
86
|
+
// 设置对应级别的标题属性
|
|
87
|
+
blockContent[headingKey] = {
|
|
88
|
+
elements: [
|
|
89
|
+
{
|
|
90
|
+
text_run: {
|
|
91
|
+
content: text,
|
|
92
|
+
text_element_style: {}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
style: {
|
|
97
|
+
align: align,
|
|
98
|
+
folded: false
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return blockContent;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 处理Markdown语法转换
|
|
105
|
+
* @param textContents 文本内容数组
|
|
106
|
+
* @returns 处理后的文本内容数组
|
|
107
|
+
*/
|
|
108
|
+
export function processMarkdownSyntax(textContents) {
|
|
109
|
+
return textContents.map(content => {
|
|
110
|
+
let { text, style = {} } = content;
|
|
111
|
+
// 创建一个新的style对象,避免修改原始对象
|
|
112
|
+
const newStyle = { ...style };
|
|
113
|
+
// 处理粗体 **text**
|
|
114
|
+
if (text.match(/\*\*([^*]+)\*\*/g)) {
|
|
115
|
+
text = text.replace(/\*\*([^*]+)\*\*/g, "$1");
|
|
116
|
+
newStyle.bold = true;
|
|
117
|
+
}
|
|
118
|
+
// 处理斜体 *text*
|
|
119
|
+
if (text.match(/(?<!\*)\*([^*]+)\*(?!\*)/g)) {
|
|
120
|
+
text = text.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, "$1");
|
|
121
|
+
newStyle.italic = true;
|
|
122
|
+
}
|
|
123
|
+
// 处理删除线 ~~text~~
|
|
124
|
+
if (text.match(/~~([^~]+)~~/g)) {
|
|
125
|
+
text = text.replace(/~~([^~]+)~~/g, "$1");
|
|
126
|
+
newStyle.strikethrough = true;
|
|
127
|
+
}
|
|
128
|
+
// 处理行内代码 `code`
|
|
129
|
+
if (text.match(/`([^`]+)`/g)) {
|
|
130
|
+
text = text.replace(/`([^`]+)`/g, "$1");
|
|
131
|
+
newStyle.inline_code = true;
|
|
132
|
+
}
|
|
133
|
+
return { text, style: newStyle };
|
|
134
|
+
});
|
|
135
|
+
}
|