index.mjs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 未来飞马
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at https://mozilla.org/MPL/2.0/.
  6. //
  7. // Trademark Notice:
  8. // The MPL-2.0 license grants copyright permissions for source code only.
  9. // It does NOT grant any rights to use trademarks including "未来飞马",
  10. // "Harness Loop", "RSI", and associated slogan "让AI进化提前发生,让AI落地快人一步".
  11. // Any use of these trademarks requires separate written permission.
  12. /**
  13. * skill-agent-log-s3 公共 SDK 入口
  14. *
  15. * 数字生命自报运行日志到个人 S3 空间,走云函数免密钥通道。
  16. *
  17. * @example Node.js
  18. * import { resolveIdentity, uploadJson, ENDPOINTS } from 'skill-agent-log-s3';
  19. * const id = resolveIdentity();
  20. * const { publicUrl } = await uploadJson({ sessionToken: id.sessionToken, key: 'log/20260923/1400.json', content: metrics });
  21. *
  22. * @example Browser (不支持指标采集,仅支持上传)
  23. * import { uploadJson } from 'skill-agent-log-s3/browser';
  24. */
  25. export { resolveIdentity, identitySummary } from './identity.mjs';
  26. export { getUploadUrl, uploadJson, listOldLogs, ENDPOINTS } from './upload.mjs';
  27. /** 生成当前时刻的日志路径 log/<YYYYMMDD>/<HHMM>.json */
  28. export function makeLogKey(now = new Date()) {
  29. const pad = n => String(n).padStart(2, '0');
  30. const d = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}`;
  31. const t = `${pad(now.getHours())}${pad(now.getMinutes())}`;
  32. return `log/${d}/${t}.json`;
  33. }