@searchfe/openclaw-baiduapp 0.1.7-beta.5 → 0.1.7-beta.7

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/index.js CHANGED
@@ -4348,7 +4348,7 @@ async function sendBaiduAppMessage(account, message, options) {
4348
4348
  return result;
4349
4349
  }
4350
4350
 
4351
- // openclaw/src/channels/plugins/media-payload.ts
4351
+ // src/media-payload.ts
4352
4352
  function buildMediaPayload(mediaList, opts) {
4353
4353
  const first = mediaList[0];
4354
4354
  const mediaPaths = mediaList.map((media) => media.path);
@@ -4453,7 +4453,6 @@ async function dispatchBaiduAppMessage(params) {
4453
4453
  peer: { kind: "dm", id: "default" }
4454
4454
  });
4455
4455
  logger2.info(`SessionKey: ${route.sessionKey}`);
4456
- route.sessionKey = "agent:main:main";
4457
4456
  logger2.info(
4458
4457
  `route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
4459
4458
  );
@@ -4707,7 +4706,7 @@ async function fetchSksCredentials(account, deps = {}) {
4707
4706
  try {
4708
4707
  payload = await response.json();
4709
4708
  } catch (error) {
4710
- throw new Error(`SKS response is not valid JSON: ${formatError(error)}`);
4709
+ throw new Error(`SKS response is not valid JSON: ${formatError(error)}`, { cause: error });
4711
4710
  }
4712
4711
  return parseSksCredentialsFromPayload(payload);
4713
4712
  }
@@ -4822,7 +4821,7 @@ async function downloadInboundFileToTemp(options, deps = {}) {
4822
4821
  };
4823
4822
  } catch (error) {
4824
4823
  if (isAbortError(error)) {
4825
- throw new Error(`Download timed out after ${timeoutMs}ms`);
4824
+ throw new Error(`Download timed out after ${timeoutMs}ms`, { cause: error });
4826
4825
  }
4827
4826
  throw error;
4828
4827
  } finally {
@@ -5021,7 +5020,7 @@ async function assertSafeRemoteHttpUrl(remoteUrl, lookupHost) {
5021
5020
  try {
5022
5021
  resolvedAddresses = await lookupHost(hostname);
5023
5022
  } catch (error) {
5024
- throw new Error(`Remote URL host lookup failed: ${hostname} (${formatError(error)})`);
5023
+ throw new Error(`Remote URL host lookup failed: ${hostname} (${formatError(error)})`, { cause: error });
5025
5024
  }
5026
5025
  if (!resolvedAddresses.length) {
5027
5026
  throw new Error(`Remote URL host lookup returned no addresses: ${hostname}`);
@@ -5964,7 +5963,7 @@ function stopAccountPolling(accountId) {
5964
5963
  accountPollers.delete(accountId);
5965
5964
  }
5966
5965
 
5967
- // openclaw/src/plugin-sdk/reply-payload.ts
5966
+ // src/channel.ts
5968
5967
  function resolveOutboundMediaUrls(payload) {
5969
5968
  if (payload.mediaUrls?.length) {
5970
5969
  return payload.mediaUrls;
@@ -5974,8 +5973,6 @@ function resolveOutboundMediaUrls(payload) {
5974
5973
  }
5975
5974
  return [];
5976
5975
  }
5977
-
5978
- // src/channel.ts
5979
5976
  var meta = {
5980
5977
  id: "openclaw-baiduapp",
5981
5978
  label: "Baidu App",
@@ -5987,30 +5984,6 @@ var meta = {
5987
5984
  order: 85
5988
5985
  };
5989
5986
  var unregisterHooks = /* @__PURE__ */ new Map();
5990
- var BAIDU_FILE_TYPE_BY_EXTENSION = {
5991
- ".amr": "audio/amr",
5992
- ".csv": "text/csv",
5993
- ".doc": "application/msword",
5994
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
5995
- ".gif": "image/gif",
5996
- ".jpeg": "image/jpeg",
5997
- ".jpg": "image/jpeg",
5998
- ".json": "application/json",
5999
- ".md": "text/markdown",
6000
- ".mov": "video/quicktime",
6001
- ".mp3": "audio/mpeg",
6002
- ".mp4": "video/mp4",
6003
- ".pdf": "application/pdf",
6004
- ".png": "image/png",
6005
- ".ppt": "application/vnd.ms-powerpoint",
6006
- ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
6007
- ".svg": "image/svg+xml",
6008
- ".txt": "text/plain",
6009
- ".wav": "audio/wav",
6010
- ".xls": "application/vnd.ms-excel",
6011
- ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
6012
- ".zip": "application/zip"
6013
- };
6014
5987
  function resolveOutboundLocalMediaPath(mediaUrl) {
6015
5988
  const trimmed = mediaUrl?.trim();
6016
5989
  if (!trimmed) {
@@ -6031,12 +6004,8 @@ function resolveOutboundLocalMediaPath(mediaUrl) {
6031
6004
  return trimmed;
6032
6005
  }
6033
6006
  function inferBaiduOutboundFileType(params) {
6034
- const normalizedMimeType = params.mimeType?.split(";")[0]?.trim().toLowerCase();
6035
- if (normalizedMimeType) {
6036
- return normalizedMimeType;
6037
- }
6038
- const extension = path2.extname(params.mediaPath).toLowerCase();
6039
- return BAIDU_FILE_TYPE_BY_EXTENSION[extension] ?? "application/octet-stream";
6007
+ const ext = path2.extname(params.mediaPath).toLowerCase();
6008
+ return ext.startsWith(".") ? ext.slice(1) : ext || "bin";
6040
6009
  }
6041
6010
  function buildOutboundMediaPayload(params) {
6042
6011
  const caption = params.caption?.trim();
@@ -6295,6 +6264,7 @@ var baiduAppPlugin = {
6295
6264
  },
6296
6265
  sendMedia: async (params) => {
6297
6266
  const account = resolveBaiduAppAccount({ cfg: params.cfg, accountId: params.accountId ?? void 0 });
6267
+ console.log("baiduapp sendMedia", params.mediaUrl);
6298
6268
  if (!account.canSendActive) {
6299
6269
  return {
6300
6270
  channel: "openclaw-baiduapp",
@@ -6305,12 +6275,45 @@ var baiduAppPlugin = {
6305
6275
  }
6306
6276
  const localMediaPath = resolveOutboundLocalMediaPath(params.mediaUrl);
6307
6277
  if (!localMediaPath) {
6308
- return {
6309
- channel: "openclaw-baiduapp",
6310
- ok: false,
6311
- messageId: "",
6312
- error: new Error("Outbound media requires a local file path")
6313
- };
6278
+ const remoteUrl = params.mediaUrl?.trim() ?? "";
6279
+ if (!remoteUrl) {
6280
+ return {
6281
+ channel: "openclaw-baiduapp",
6282
+ ok: false,
6283
+ messageId: "",
6284
+ error: new Error("Outbound media requires a URL or local file path")
6285
+ };
6286
+ }
6287
+ try {
6288
+ const result = await sendBaiduAppMessage(
6289
+ account,
6290
+ buildOutboundMediaPayload({
6291
+ caption: params.text,
6292
+ uploadedUrl: remoteUrl,
6293
+ fileType: inferBaiduOutboundFileType({ mediaPath: remoteUrl })
6294
+ })
6295
+ );
6296
+ if (!result.ok) {
6297
+ return {
6298
+ channel: "openclaw-baiduapp",
6299
+ ok: false,
6300
+ messageId: result.msgid ?? "",
6301
+ error: new Error(result.errmsg ?? "send failed")
6302
+ };
6303
+ }
6304
+ return {
6305
+ channel: "openclaw-baiduapp",
6306
+ ok: true,
6307
+ messageId: result.msgid ?? ""
6308
+ };
6309
+ } catch (err) {
6310
+ return {
6311
+ channel: "openclaw-baiduapp",
6312
+ ok: false,
6313
+ messageId: "",
6314
+ error: err instanceof Error ? err : new Error(String(err))
6315
+ };
6316
+ }
6314
6317
  }
6315
6318
  try {
6316
6319
  const uploaded = await uploadLocalFileToBos({
@@ -6325,8 +6328,7 @@ var baiduAppPlugin = {
6325
6328
  caption: params.text,
6326
6329
  uploadedUrl: uploaded.url,
6327
6330
  fileType: inferBaiduOutboundFileType({
6328
- mediaPath: uploaded.fileName || localMediaPath,
6329
- mimeType: params.mimeType
6331
+ mediaPath: uploaded.fileName || localMediaPath
6330
6332
  })
6331
6333
  })
6332
6334
  );