@nextclaw/ncp-agent-runtime 0.3.12 → 0.3.14

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -456,6 +456,37 @@ function normalizeMimeType(value) {
456
456
  const normalized = value?.trim().toLowerCase() ?? "";
457
457
  return normalized.length > 0 ? normalized : "application/octet-stream";
458
458
  }
459
+ function inferMimeTypeFromFileName(fileName) {
460
+ const normalized = fileName.trim().toLowerCase();
461
+ if (normalized.endsWith(".mp3")) return "audio/mpeg";
462
+ if (normalized.endsWith(".m4a")) return "audio/mp4";
463
+ if (normalized.endsWith(".wav")) return "audio/wav";
464
+ if (normalized.endsWith(".ogg")) return "audio/ogg";
465
+ if (normalized.endsWith(".opus")) return "audio/opus";
466
+ if (normalized.endsWith(".flac")) return "audio/flac";
467
+ if (normalized.endsWith(".aac")) return "audio/aac";
468
+ if (normalized.endsWith(".weba")) return "audio/webm";
469
+ if (normalized.endsWith(".mp4") || normalized.endsWith(".m4v")) return "video/mp4";
470
+ if (normalized.endsWith(".mov")) return "video/quicktime";
471
+ if (normalized.endsWith(".webm")) return "video/webm";
472
+ if (normalized.endsWith(".mkv")) return "video/x-matroska";
473
+ if (normalized.endsWith(".avi")) return "video/x-msvideo";
474
+ if (normalized.endsWith(".wmv")) return "video/x-ms-wmv";
475
+ if (normalized.endsWith(".png")) return "image/png";
476
+ if (normalized.endsWith(".jpg") || normalized.endsWith(".jpeg")) return "image/jpeg";
477
+ if (normalized.endsWith(".gif")) return "image/gif";
478
+ if (normalized.endsWith(".webp")) return "image/webp";
479
+ if (normalized.endsWith(".svg")) return "image/svg+xml";
480
+ if (normalized.endsWith(".pdf")) return "application/pdf";
481
+ if (normalized.endsWith(".json")) return "application/json";
482
+ if (normalized.endsWith(".txt")) return "text/plain";
483
+ return null;
484
+ }
485
+ function resolveStoredMimeType(fileName, mimeType) {
486
+ const normalized = normalizeMimeType(mimeType);
487
+ if (normalized !== "application/octet-stream") return normalized;
488
+ return inferMimeTypeFromFileName(fileName) ?? normalized;
489
+ }
459
490
  function buildAssetId() {
460
491
  return `asset_${Date.now().toString(36)}_${randomUUID().slice(0, 8)}`;
461
492
  }
@@ -616,12 +647,13 @@ var LocalAssetStore = class {
616
647
  return record;
617
648
  }
618
649
  async putFromBytes(params) {
619
- const bytes = Buffer.from(params.bytes);
650
+ const { bytes: rawBytes, createdAt, fileName, mimeType } = params;
651
+ const bytes = Buffer.from(rawBytes);
620
652
  const record = this.buildRecord({
621
- fileName: params.fileName,
622
- mimeType: params.mimeType,
653
+ fileName,
654
+ mimeType,
623
655
  bytes,
624
- createdAt: params.createdAt
656
+ createdAt
625
657
  });
626
658
  const assetDir = this.resolveStorageKeyDirectory(record.storageKey);
627
659
  await mkdir(assetDir, { recursive: true });
@@ -630,20 +662,21 @@ var LocalAssetStore = class {
630
662
  return record;
631
663
  }
632
664
  buildRecord(params) {
633
- const createdAt = params.createdAt ?? /* @__PURE__ */ new Date();
665
+ const { bytes, createdAt: rawCreatedAt, fileName: rawFileName, mimeType } = params;
666
+ const createdAt = rawCreatedAt ?? /* @__PURE__ */ new Date();
634
667
  const id = buildAssetId();
635
668
  const storageKey = buildStorageKey(createdAt, id);
636
- const fileName = normalizeFileName(params.fileName);
669
+ const fileName = normalizeFileName(rawFileName);
637
670
  return {
638
671
  id,
639
672
  uri: buildAssetUri(storageKey),
640
673
  storageKey,
641
674
  fileName,
642
675
  storedName: normalizeSegment(fileName),
643
- mimeType: normalizeMimeType(params.mimeType),
644
- sizeBytes: params.bytes.length,
676
+ mimeType: resolveStoredMimeType(fileName, mimeType),
677
+ sizeBytes: bytes.length,
645
678
  createdAt: createdAt.toISOString(),
646
- sha256: createHash("sha256").update(params.bytes).digest("hex")
679
+ sha256: createHash("sha256").update(bytes).digest("hex")
647
680
  };
648
681
  }
649
682
  async writeMeta(assetDir, record) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-agent-runtime",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "private": false,
5
5
  "description": "Default agent runtime implementation built on NCP interfaces.",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "ajv": "^8.17.1",
19
- "@nextclaw/ncp": "0.5.2"
19
+ "@nextclaw/ncp": "0.5.4"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^20.17.6",