@hcmai/sdk 0.21.8 → 0.21.9

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.d.ts CHANGED
@@ -994,6 +994,7 @@ interface AttachmentMeta {
994
994
  fileName: string;
995
995
  mimeType: string;
996
996
  fileSize: number;
997
+ bindingStatus?: string;
997
998
  }
998
999
  declare function guessMimeType(filePath: string): string;
999
1000
  /**
@@ -1010,7 +1011,12 @@ declare function guessMimeType(filePath: string): string;
1010
1011
  * 「分类不存在」。2026-08-26 按交付技能跑弹性报表端到端时,Step 4「上传模板」
1011
1012
  * 卡在这里;模板是报表的必需件,这条不通整条链就断了。
1012
1013
  */
1013
- declare function uploadDocument(http: AxiosInstance, filePath: string, storageCategory?: string): Promise<AttachmentMeta>;
1014
+ declare function uploadDocument(http: AxiosInstance, filePath: string, storageCategory?: string, owner?: {
1015
+ model: string;
1016
+ originId: string;
1017
+ field: string;
1018
+ state?: string;
1019
+ }): Promise<AttachmentMeta>;
1014
1020
  /** 默认产物落盘目录(对标 Claude Code 工具产物本地直接访问)。 */
1015
1021
  declare function defaultDownloadDir(): string;
1016
1022
  /**
package/dist/index.js CHANGED
@@ -2326,7 +2326,7 @@ function guessMimeType(filePath) {
2326
2326
  return MIME_BY_EXT[path5.extname(filePath).toLowerCase()] ?? "application/octet-stream";
2327
2327
  }
2328
2328
  var CHAT_ATTACHMENT_CATEGORY = "ai-conversation";
2329
- async function uploadDocument(http, filePath, storageCategory = CHAT_ATTACHMENT_CATEGORY) {
2329
+ async function uploadDocument(http, filePath, storageCategory = CHAT_ATTACHMENT_CATEGORY, owner) {
2330
2330
  const abs = expandHome(filePath);
2331
2331
  const buf = await fsp.readFile(abs);
2332
2332
  const fileName = path5.basename(abs);
@@ -2334,13 +2334,23 @@ async function uploadDocument(http, filePath, storageCategory = CHAT_ATTACHMENT_
2334
2334
  form.append("file", new Blob([buf], { type: guessMimeType(abs) }), fileName);
2335
2335
  form.append("storageCategory", storageCategory);
2336
2336
  form.append("allowEmptyFormId", "true");
2337
+ if (owner) {
2338
+ if (!owner.model?.trim() || !owner.originId?.trim() || !owner.field?.trim()) {
2339
+ throw new Error("\u4E1A\u52A1\u9644\u4EF6\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B model\u3001originId\u3001field");
2340
+ }
2341
+ form.append("model", owner.model.trim());
2342
+ form.append("originId", owner.originId.trim());
2343
+ form.append("field", owner.field.trim());
2344
+ if (owner.state?.trim()) form.append("state", owner.state.trim());
2345
+ }
2337
2346
  const resp = await http.post("/api/documents/upload", form);
2338
2347
  const meta = resp.data?.data ?? resp.data;
2339
2348
  return {
2340
2349
  documentId: String(meta.documentId ?? meta.id),
2341
2350
  fileName: String(meta.fileName ?? fileName),
2342
2351
  mimeType: String(meta.contentType ?? meta.mimeType ?? guessMimeType(abs)),
2343
- fileSize: Number(meta.fileSize ?? meta.size ?? buf.length)
2352
+ fileSize: Number(meta.fileSize ?? meta.size ?? buf.length),
2353
+ ...meta.bindingStatus ? { bindingStatus: String(meta.bindingStatus) } : owner ? { bindingStatus: "UNBOUND_BACKEND_CONTRACT_UNAVAILABLE" } : {}
2344
2354
  };
2345
2355
  }
2346
2356
  function defaultDownloadDir() {
@@ -2352,7 +2362,17 @@ function absoluteDownloadUrl(apiBase, url) {
2352
2362
  }
2353
2363
  async function downloadDocument(http, ref, destPath) {
2354
2364
  const url = ref.downloadUrl ?? `/api/documents/download/${ref.documentId}`;
2355
- const resp = await http.get(url, { responseType: "arraybuffer" });
2365
+ const resp = await http.get(url, { responseType: "arraybuffer" }).catch((error) => {
2366
+ const data = error.response?.data;
2367
+ if (Buffer.isBuffer(data) || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
2368
+ const bytes2 = Buffer.isBuffer(data) ? data : data instanceof ArrayBuffer ? Buffer.from(data) : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
2369
+ try {
2370
+ error.response.data = JSON.parse(bytes2.toString("utf8"));
2371
+ } catch {
2372
+ }
2373
+ }
2374
+ throw error;
2375
+ });
2356
2376
  const headerName = parseFilenameFromDisposition(resp.headers?.["content-disposition"]);
2357
2377
  const rawName = ref.fileName ?? headerName ?? `${ref.documentId ?? "download"}.bin`;
2358
2378
  let dir;