beplus-mcp 0.20.0 → 0.20.1

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 +56 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1120,7 +1120,7 @@ ${list}${flagsLine(status)}` }, ...blocks] };
1120
1120
  import { z as z2 } from "zod";
1121
1121
 
1122
1122
  // src/probe.ts
1123
- import { readFile as readFile2, open } from "fs/promises";
1123
+ import { open, stat } from "fs/promises";
1124
1124
  import { extname as extname2, isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
1125
1125
  import { homedir as homedir2 } from "os";
1126
1126
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -1144,6 +1144,49 @@ function kindFromExt(ref) {
1144
1144
  if (VIDEO_EXT.has(ext)) return "video";
1145
1145
  return null;
1146
1146
  }
1147
+ async function readAt(ref, offset, len) {
1148
+ if (!isRemote(ref)) {
1149
+ const fh = await open(toLocalPath2(ref), "r");
1150
+ try {
1151
+ const buf = Buffer.alloc(len);
1152
+ const { bytesRead } = await fh.read(buf, 0, len, offset);
1153
+ return buf.subarray(0, bytesRead);
1154
+ } finally {
1155
+ await fh.close();
1156
+ }
1157
+ }
1158
+ const ctrl = new AbortController();
1159
+ const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
1160
+ try {
1161
+ const res = await fetch(ref, {
1162
+ headers: { Range: `bytes=${offset}-${offset + len - 1}` },
1163
+ signal: ctrl.signal
1164
+ });
1165
+ if (res.status !== 206) throw new Error("servidor n\xE3o aceita Range");
1166
+ return Buffer.from(await res.arrayBuffer());
1167
+ } finally {
1168
+ clearTimeout(timer);
1169
+ }
1170
+ }
1171
+ async function findMoov(ref, fileSize) {
1172
+ let offset = 0;
1173
+ for (let guard = 0; guard < 64 && offset + 8 <= fileSize; guard++) {
1174
+ const head = await readAt(ref, offset, 16);
1175
+ if (head.length < 8) return null;
1176
+ let size = head.readUInt32BE(0);
1177
+ const type = head.toString("ascii", 4, 8);
1178
+ if (size === 1) {
1179
+ if (head.length < 16) return null;
1180
+ size = Number(head.readBigUInt64BE(8));
1181
+ }
1182
+ if (size < 8) return null;
1183
+ if (type === "moov") {
1184
+ return readAt(ref, offset, Math.min(size, MAX_SCAN_BYTES));
1185
+ }
1186
+ offset += size;
1187
+ }
1188
+ return null;
1189
+ }
1147
1190
  async function readHead(ref, bytes) {
1148
1191
  if (!isRemote(ref)) {
1149
1192
  const fh = await open(toLocalPath2(ref), "r");
@@ -1297,6 +1340,11 @@ function probeMp4(b) {
1297
1340
  const fps = dur && frames ? Math.round(frames / dur * 100) / 100 : void 0;
1298
1341
  return { width, height, duration: dur, fps };
1299
1342
  }
1343
+ async function fileSizeOf(ref) {
1344
+ if (!isRemote(ref)) return (await stat(toLocalPath2(ref))).size;
1345
+ const res = await fetch(ref, { method: "HEAD" });
1346
+ return Number(res.headers.get("content-length") ?? 0);
1347
+ }
1300
1348
  var ProbeError = class extends Error {
1301
1349
  };
1302
1350
  async function probeMedia(ref) {
@@ -1319,10 +1367,13 @@ async function probeMedia(ref) {
1319
1367
  return { kind, width: dim.width, height: dim.height };
1320
1368
  }
1321
1369
  let info = probeMp4(head);
1322
- if (!info && !isRemote(ref)) {
1370
+ if (!info) {
1323
1371
  try {
1324
- const whole = await readFile2(toLocalPath2(ref));
1325
- info = probeMp4(whole.subarray(0, Math.min(whole.length, MAX_SCAN_BYTES))) ?? probeMp4(whole.subarray(Math.max(0, whole.length - MAX_SCAN_BYTES)));
1372
+ const size = await fileSizeOf(ref);
1373
+ if (size > 0) {
1374
+ const moov = await findMoov(ref, size);
1375
+ if (moov) info = probeMp4(moov);
1376
+ }
1326
1377
  } catch {
1327
1378
  }
1328
1379
  }
@@ -1768,7 +1819,7 @@ Limites simult\xE2neos por usu\xE1rio: imagem=${m.limits.perUserMaxImage}, v\xED
1768
1819
  file: z5.string().optional().describe(
1769
1820
  "[upscale] Arquivo a medir (caminho local ou URL) \u2014 preenche sozinho as medidas abaixo. Use com model=topaz/upscale/image/generative ou .../video/generative."
1770
1821
  ),
1771
- upscale_factor: z5.number().int().min(1).max(4).optional().describe("[upscale] Fator de aumento (1 a 4). Padr\xE3o 2."),
1822
+ upscale_factor: z5.number().min(1).max(4).optional().describe("[upscale] Fator de aumento, de 1 a 4 (aceita fracion\xE1rio). Padr\xE3o 2."),
1772
1823
  model_variant: z5.string().optional().describe("[upscale] Variante do Topaz (ex.: Wonder 3, Starlight Fast 2) \u2014 muda o pre\xE7o."),
1773
1824
  source_width: z5.number().int().positive().optional().describe("[upscale] Largura do arquivo."),
1774
1825
  source_height: z5.number().int().positive().optional().describe("[upscale] Altura do arquivo."),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beplus-mcp",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "Conector MCP da equipe BePlus — gere imagens/vídeos/áudio e consulte calls, projetos e clientes pela sua conta BePlus (diamantes, limites e histórico aplicados pela plataforma).",
5
5
  "type": "module",
6
6
  "bin": {