@danyow/lark-mcp 0.5.2 → 0.5.4
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.
|
@@ -87,19 +87,55 @@ exports.larkDriveExportTaskDownloadTool = {
|
|
|
87
87
|
const filePath = path.join(outputDir, fileName);
|
|
88
88
|
// Use SDK's built-in download method which returns writeFile/getReadableStream
|
|
89
89
|
let response;
|
|
90
|
+
const debug = [];
|
|
91
|
+
debug.push(`fileToken: ${fileToken}`);
|
|
92
|
+
debug.push(`useUAT: ${params === null || params === void 0 ? void 0 : params.useUAT}, hasUserAccessToken: ${!!userAccessToken}`);
|
|
90
93
|
if (userAccessToken && (params === null || params === void 0 ? void 0 : params.useUAT)) {
|
|
91
94
|
response = await client.drive.exportTask.download({ path: { file_token: fileToken } }, lark.withUserAccessToken(userAccessToken));
|
|
92
95
|
}
|
|
93
96
|
else {
|
|
94
97
|
response = await client.drive.exportTask.download({ path: { file_token: fileToken } });
|
|
95
98
|
}
|
|
99
|
+
debug.push(`response type: ${typeof response}`);
|
|
100
|
+
debug.push(`response keys: ${response ? Object.keys(response).join(', ') : 'null/undefined'}`);
|
|
101
|
+
debug.push(`response.code: ${response === null || response === void 0 ? void 0 : response.code}`);
|
|
102
|
+
debug.push(`response.msg: ${response === null || response === void 0 ? void 0 : response.msg}`);
|
|
103
|
+
debug.push(`has writeFile: ${typeof (response === null || response === void 0 ? void 0 : response.writeFile)}`);
|
|
104
|
+
debug.push(`has getReadableStream: ${typeof (response === null || response === void 0 ? void 0 : response.getReadableStream)}`);
|
|
105
|
+
// Check if response contains an API error
|
|
106
|
+
if ((response === null || response === void 0 ? void 0 : response.code) && response.code !== 0) {
|
|
107
|
+
return {
|
|
108
|
+
isError: true,
|
|
109
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
110
|
+
msg: 'API error',
|
|
111
|
+
code: response.code,
|
|
112
|
+
error: response.msg || 'Unknown error',
|
|
113
|
+
hint: 'The file_token may be invalid or expired. Export files are deleted 10 minutes after the export task completes.',
|
|
114
|
+
debug
|
|
115
|
+
}) }],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
96
118
|
// Use the SDK's writeFile method to save the file
|
|
97
119
|
if (response === null || response === void 0 ? void 0 : response.writeFile) {
|
|
120
|
+
debug.push('using writeFile method');
|
|
98
121
|
await response.writeFile(filePath);
|
|
122
|
+
debug.push('writeFile completed');
|
|
99
123
|
}
|
|
100
124
|
else if (response === null || response === void 0 ? void 0 : response.getReadableStream) {
|
|
125
|
+
debug.push('using getReadableStream method');
|
|
101
126
|
// Fallback to stream if writeFile is not available
|
|
102
127
|
const readableStream = response.getReadableStream();
|
|
128
|
+
debug.push(`readableStream: ${readableStream ? 'exists' : 'undefined'}`);
|
|
129
|
+
if (!readableStream) {
|
|
130
|
+
return {
|
|
131
|
+
isError: true,
|
|
132
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
133
|
+
msg: 'Failed to download file: getReadableStream returned undefined',
|
|
134
|
+
hint: 'The file_token may be invalid or expired. Export files are deleted 10 minutes after the export task completes.',
|
|
135
|
+
debug
|
|
136
|
+
}) }],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
103
139
|
const writableStream = fs.createWriteStream(filePath);
|
|
104
140
|
await new Promise((resolve, reject) => {
|
|
105
141
|
readableStream.pipe(writableStream);
|
|
@@ -107,13 +143,14 @@ exports.larkDriveExportTaskDownloadTool = {
|
|
|
107
143
|
writableStream.on('error', reject);
|
|
108
144
|
readableStream.on('error', reject);
|
|
109
145
|
});
|
|
146
|
+
debug.push('stream completed');
|
|
110
147
|
}
|
|
111
148
|
else {
|
|
112
149
|
return {
|
|
113
150
|
isError: true,
|
|
114
151
|
content: [{ type: 'text', text: JSON.stringify({
|
|
115
152
|
msg: 'Failed to download file: SDK response does not contain writeFile or getReadableStream',
|
|
116
|
-
debug
|
|
153
|
+
debug
|
|
117
154
|
}) }],
|
|
118
155
|
};
|
|
119
156
|
}
|
|
@@ -87,19 +87,55 @@ exports.larkDriveExportTaskDownloadTool = {
|
|
|
87
87
|
const filePath = path.join(outputDir, fileName);
|
|
88
88
|
// Use SDK's built-in download method which returns writeFile/getReadableStream
|
|
89
89
|
let response;
|
|
90
|
+
const debug = [];
|
|
91
|
+
debug.push(`fileToken: ${fileToken}`);
|
|
92
|
+
debug.push(`useUAT: ${params === null || params === void 0 ? void 0 : params.useUAT}, hasUserAccessToken: ${!!userAccessToken}`);
|
|
90
93
|
if (userAccessToken && (params === null || params === void 0 ? void 0 : params.useUAT)) {
|
|
91
94
|
response = await client.drive.exportTask.download({ path: { file_token: fileToken } }, lark.withUserAccessToken(userAccessToken));
|
|
92
95
|
}
|
|
93
96
|
else {
|
|
94
97
|
response = await client.drive.exportTask.download({ path: { file_token: fileToken } });
|
|
95
98
|
}
|
|
99
|
+
debug.push(`response type: ${typeof response}`);
|
|
100
|
+
debug.push(`response keys: ${response ? Object.keys(response).join(', ') : 'null/undefined'}`);
|
|
101
|
+
debug.push(`response.code: ${response === null || response === void 0 ? void 0 : response.code}`);
|
|
102
|
+
debug.push(`response.msg: ${response === null || response === void 0 ? void 0 : response.msg}`);
|
|
103
|
+
debug.push(`has writeFile: ${typeof (response === null || response === void 0 ? void 0 : response.writeFile)}`);
|
|
104
|
+
debug.push(`has getReadableStream: ${typeof (response === null || response === void 0 ? void 0 : response.getReadableStream)}`);
|
|
105
|
+
// Check if response contains an API error
|
|
106
|
+
if ((response === null || response === void 0 ? void 0 : response.code) && response.code !== 0) {
|
|
107
|
+
return {
|
|
108
|
+
isError: true,
|
|
109
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
110
|
+
msg: 'API 错误',
|
|
111
|
+
code: response.code,
|
|
112
|
+
error: response.msg || '未知错误',
|
|
113
|
+
hint: 'file_token 可能无效或已过期。导出的文件将在导出任务完成后 10 分钟内被删除。',
|
|
114
|
+
debug
|
|
115
|
+
}) }],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
96
118
|
// Use the SDK's writeFile method to save the file
|
|
97
119
|
if (response === null || response === void 0 ? void 0 : response.writeFile) {
|
|
120
|
+
debug.push('using writeFile method');
|
|
98
121
|
await response.writeFile(filePath);
|
|
122
|
+
debug.push('writeFile completed');
|
|
99
123
|
}
|
|
100
124
|
else if (response === null || response === void 0 ? void 0 : response.getReadableStream) {
|
|
125
|
+
debug.push('using getReadableStream method');
|
|
101
126
|
// Fallback to stream if writeFile is not available
|
|
102
127
|
const readableStream = response.getReadableStream();
|
|
128
|
+
debug.push(`readableStream: ${readableStream ? 'exists' : 'undefined'}`);
|
|
129
|
+
if (!readableStream) {
|
|
130
|
+
return {
|
|
131
|
+
isError: true,
|
|
132
|
+
content: [{ type: 'text', text: JSON.stringify({
|
|
133
|
+
msg: '下载文件失败:getReadableStream 返回 undefined',
|
|
134
|
+
hint: 'file_token 可能无效或已过期。导出的文件将在导出任务完成后 10 分钟内被删除。',
|
|
135
|
+
debug
|
|
136
|
+
}) }],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
103
139
|
const writableStream = fs.createWriteStream(filePath);
|
|
104
140
|
await new Promise((resolve, reject) => {
|
|
105
141
|
readableStream.pipe(writableStream);
|
|
@@ -107,13 +143,14 @@ exports.larkDriveExportTaskDownloadTool = {
|
|
|
107
143
|
writableStream.on('error', reject);
|
|
108
144
|
readableStream.on('error', reject);
|
|
109
145
|
});
|
|
146
|
+
debug.push('stream completed');
|
|
110
147
|
}
|
|
111
148
|
else {
|
|
112
149
|
return {
|
|
113
150
|
isError: true,
|
|
114
151
|
content: [{ type: 'text', text: JSON.stringify({
|
|
115
152
|
msg: '下载文件失败:SDK 响应不包含 writeFile 或 getReadableStream',
|
|
116
|
-
debug
|
|
153
|
+
debug
|
|
117
154
|
}) }],
|
|
118
155
|
};
|
|
119
156
|
}
|