duclaw-cli 1.5.0 → 1.6.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/dist/bundle.js CHANGED
@@ -30242,7 +30242,7 @@ function printHelp() {
30242
30242
  `);
30243
30243
  }
30244
30244
  function printVersion() {
30245
- console.log(`duclaw-cli v${true ? "1.5.0" : "unknown"}`);
30245
+ console.log(`duclaw-cli v${true ? "1.6.0" : "unknown"}`);
30246
30246
  }
30247
30247
  function getDuclawTemplate() {
30248
30248
  return {
@@ -41794,10 +41794,18 @@ var RedisMessageDeduplication = class {
41794
41794
  }
41795
41795
  };
41796
41796
 
41797
+ // src/channels/feishu/MessageProcess.ts
41798
+ var import_node_path10 = require("node:path");
41799
+ var import_node_os4 = require("node:os");
41800
+ var import_node_fs5 = require("node:fs");
41801
+
41797
41802
  // src/oss/AliyunOSSClient.ts
41798
41803
  var import_ali_oss = __toESM(require("ali-oss"));
41799
41804
  loadEnv();
41800
41805
  var aliyunOssClient = void 0;
41806
+ var isOssConfigured = () => {
41807
+ return !!(process.env.OSS_ACCESS_KEY_ID && process.env.OSS_ACCESS_KEY_SECRET && process.env.OSS_ENDPOINT && process.env.OSS_BUCKET);
41808
+ };
41801
41809
  var createAliyunOssClient = () => {
41802
41810
  const key = process.env.OSS_ACCESS_KEY_ID;
41803
41811
  const secret = process.env.OSS_ACCESS_KEY_SECRET;
@@ -41825,6 +41833,26 @@ var createAliyunOssClient = () => {
41825
41833
  };
41826
41834
 
41827
41835
  // src/channels/feishu/MessageProcess.ts
41836
+ var saveToLocal = (userId, subDir, fileName, buffer) => {
41837
+ const dir = (0, import_node_path10.join)((0, import_node_os4.homedir)(), ".duclaw", "workspace", userId, subDir);
41838
+ (0, import_node_fs5.mkdirSync)(dir, { recursive: true });
41839
+ const filePath = (0, import_node_path10.join)(dir, fileName);
41840
+ (0, import_node_fs5.writeFileSync)(filePath, buffer);
41841
+ return filePath;
41842
+ };
41843
+ var tryUploadToOss = async (ossPath, buffer) => {
41844
+ if (!isOssConfigured()) return null;
41845
+ try {
41846
+ const ossClient = createAliyunOssClient();
41847
+ await ossClient.put(ossPath, buffer);
41848
+ const url = await ossClient.signatureUrlV4("GET", 3600, void 0, ossPath);
41849
+ console.log(`[MessageProcess] OSS \u4E0A\u4F20\u6210\u529F\uFF0C\u4E34\u65F6\u8BBF\u95EE\u94FE\u63A5: ${url}`);
41850
+ return url;
41851
+ } catch (err) {
41852
+ console.warn(`[MessageProcess] OSS \u4E0A\u4F20\u5931\u8D25\uFF0C\u4F7F\u7528\u672C\u5730\u8DEF\u5F84: ${err}`);
41853
+ return null;
41854
+ }
41855
+ };
41828
41856
  var processImageMsg = async (userRequest) => {
41829
41857
  if (!userRequest.metadata) {
41830
41858
  throw new Error(`[MessageProcess] \u98DE\u4E66\u56FE\u7247\u6D88\u606F\u5E94\u8981\u6709metadata,\u5F53\u524D:${userRequest.metadata}`);
@@ -41839,30 +41867,13 @@ var processImageMsg = async (userRequest) => {
41839
41867
  if (!image_key) {
41840
41868
  throw new Error(`[MessageProcess] \u98DE\u4E66\u56FE\u7247\u6D88\u606F\u5E94\u8981\u6709image_key`);
41841
41869
  }
41842
- const ossClient = createAliyunOssClient();
41843
- try {
41844
- const buffer = await downloadMessageImage(message.message_id, image_key);
41845
- const result = await ossClient.put(
41846
- `${userRequest.userId}/images/${image_key}`,
41847
- buffer
41848
- );
41849
- console.log("\u6587\u4EF6\u4E0A\u4F20oss\u5B8C\u6210:", result);
41850
- const publicReadableUrl = await ossClient.signatureUrlV4(
41851
- `GET`,
41852
- 3600,
41853
- // 过期时间(秒),1小时
41854
- void 0,
41855
- // 不需要额外的 headers/queries
41856
- `${userRequest.userId}/images/${image_key}`
41857
- // obj name
41858
- );
41859
- console.log(`[MessageProcess] \u4E34\u65F6\u8BBF\u95EE\u94FE\u63A5: ${publicReadableUrl}\uFF0C\u6709\u6548\u65F6\u957F: 1h`);
41860
- userRequest.metadata.imageUrl = publicReadableUrl;
41861
- userRequest.content = `<system-reminder>\u63A5\u6536\u5230\u7528\u6237\u53D1\u6765\u7684\u56FE\u7247\u6D88\u606F,\u56FE\u7247\u5DF2\u5B58\u50A8\u5728\u4E0A\u4E0B\u6587\u4E2D,\u8BF7\u4F7F\u7528image_understand\u5DE5\u5177\u5206\u6790\u56FE\u7247(\u4E0D\u9700\u8981\u4F20image_url\u53C2\u6570,\u5DE5\u5177\u4F1A\u81EA\u52A8\u83B7\u53D6\u56FE\u7247)</system-reminder>`;
41862
- return userRequest;
41863
- } catch (err) {
41864
- throw new Error(`[MessageProcess] \u4E0A\u4F20\u56FE\u7247\u5230\u963F\u91CC\u4E91oss\u5931\u8D25:${err}`);
41865
- }
41870
+ const buffer = await downloadMessageImage(message.message_id, image_key);
41871
+ const localPath = saveToLocal(userRequest.userId, "images", `${image_key}.png`, buffer);
41872
+ console.log(`[MessageProcess] \u56FE\u7247\u5DF2\u4FDD\u5B58\u5230\u672C\u5730: ${localPath}`);
41873
+ const ossUrl = await tryUploadToOss(`${userRequest.userId}/images/${image_key}`, buffer);
41874
+ userRequest.metadata.imageUrl = ossUrl || localPath;
41875
+ userRequest.content = `<system-reminder>\u63A5\u6536\u5230\u7528\u6237\u53D1\u6765\u7684\u56FE\u7247\u6D88\u606F,\u56FE\u7247\u5DF2\u5B58\u50A8\u5728\u4E0A\u4E0B\u6587\u4E2D,\u8BF7\u4F7F\u7528image_understand\u5DE5\u5177\u5206\u6790\u56FE\u7247(\u4E0D\u9700\u8981\u4F20image_url\u53C2\u6570,\u5DE5\u5177\u4F1A\u81EA\u52A8\u83B7\u53D6\u56FE\u7247)</system-reminder>`;
41876
+ return userRequest;
41866
41877
  };
41867
41878
  var processFileMsg = async (userRequest) => {
41868
41879
  const metadata = userRequest.metadata;
@@ -41875,31 +41886,22 @@ var processFileMsg = async (userRequest) => {
41875
41886
  if (!messageId || !fileKey || !fileName) {
41876
41887
  throw new Error(`[MessageProcess] \u98DE\u4E66\u6587\u4EF6\u6D88\u606F\u7F3A\u5C11 message_id/file_key/file_name`);
41877
41888
  }
41878
- const ossClient = createAliyunOssClient();
41879
- try {
41880
- const buffer = await downloadMessageFile(messageId, fileKey);
41881
- console.log(`[MessageProcess] \u6587\u4EF6\u4E0B\u8F7D\u5B8C\u6210: ${fileName}, \u5927\u5C0F: ${buffer.length} bytes`);
41882
- const ossPath = `${userRequest.userId}/files/${fileKey}_${fileName}`;
41883
- const result = await ossClient.put(ossPath, buffer);
41884
- console.log("[MessageProcess] \u6587\u4EF6\u4E0A\u4F20oss\u5B8C\u6210:", result);
41885
- const publicReadableUrl = await ossClient.signatureUrlV4(
41886
- `GET`,
41887
- 3600,
41888
- void 0,
41889
- ossPath
41890
- );
41891
- console.log(`[MessageProcess] \u6587\u4EF6\u4E34\u65F6\u8BBF\u95EE\u94FE\u63A5: ${publicReadableUrl}\uFF0C\u6709\u6548\u65F6\u957F: 1h`);
41892
- userRequest.metadata.fileUrl = publicReadableUrl;
41893
- userRequest.content = [
41894
- `\u7528\u6237\u901A\u8FC7\u98DE\u4E66\u53D1\u9001\u4E86\u4E00\u4E2A\u6587\u4EF6\u3002`,
41895
- `\u6587\u4EF6\u540D: ${fileName}`,
41896
- `\u6587\u4EF6\u5DF2\u4E0A\u4F20\u81F3\u4E91\u5B58\u50A8\uFF0C\u53EF\u901A\u8FC7\u4EE5\u4E0B URL \u8BBF\u95EE\uFF081\u5C0F\u65F6\u6709\u6548\uFF09:`,
41897
- publicReadableUrl
41898
- ].join("\n");
41899
- return userRequest;
41900
- } catch (err) {
41901
- throw new Error(`[MessageProcess] \u4E0A\u4F20\u6587\u4EF6\u5230\u963F\u91CC\u4E91oss\u5931\u8D25:${err}`);
41902
- }
41889
+ const buffer = await downloadMessageFile(messageId, fileKey);
41890
+ console.log(`[MessageProcess] \u6587\u4EF6\u4E0B\u8F7D\u5B8C\u6210: ${fileName}, \u5927\u5C0F: ${buffer.length} bytes`);
41891
+ const localPath = saveToLocal(userRequest.userId, "files", fileName, buffer);
41892
+ console.log(`[MessageProcess] \u6587\u4EF6\u5DF2\u4FDD\u5B58\u5230\u672C\u5730: ${localPath}`);
41893
+ const ossPath = `${userRequest.userId}/files/${fileKey}_${fileName}`;
41894
+ const ossUrl = await tryUploadToOss(ossPath, buffer);
41895
+ const fileLocation = ossUrl || localPath;
41896
+ userRequest.metadata.fileUrl = fileLocation;
41897
+ userRequest.content = [
41898
+ `\u7528\u6237\u901A\u8FC7\u98DE\u4E66\u53D1\u9001\u4E86\u4E00\u4E2A\u6587\u4EF6\u3002`,
41899
+ `\u6587\u4EF6\u540D: ${fileName}`,
41900
+ ossUrl ? `\u6587\u4EF6\u5DF2\u4E0A\u4F20\u81F3\u4E91\u5B58\u50A8\uFF0C\u53EF\u901A\u8FC7\u4EE5\u4E0B URL \u8BBF\u95EE\uFF081\u5C0F\u65F6\u6709\u6548\uFF09:
41901
+ ${ossUrl}` : `\u6587\u4EF6\u5DF2\u4FDD\u5B58\u5230\u672C\u5730\u8DEF\u5F84:
41902
+ ${localPath}`
41903
+ ].join("\n");
41904
+ return userRequest;
41903
41905
  };
41904
41906
 
41905
41907
  // src/channels/feishu/feishuChannelsPlugin.ts
@@ -46294,7 +46296,7 @@ var systemRoutes = new Hono2();
46294
46296
  var startTime = Date.now();
46295
46297
  systemRoutes.get("/system/info", (c) => {
46296
46298
  return c.json({
46297
- version: true ? "1.5.0" : "unknown",
46299
+ version: true ? "1.6.0" : "unknown",
46298
46300
  uptime: Math.floor((Date.now() - startTime) / 1e3),
46299
46301
  env: process.env.NODE_ENV || "development",
46300
46302
  nodeVersion: process.version