memory-eternal 0.3.5 → 0.3.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/index.js CHANGED
@@ -412,8 +412,9 @@ export function apply(ctx, config) {
412
412
  // 单智能体安装/卸载 MCP:POST {agent, action}
413
413
  if (req.method !== 'POST') return json(res, 405, { ok: false, error: '需 POST' })
414
414
  try {
415
- let raw = ''
416
- for await (const chunk of req) raw += chunk
415
+ const chunks = []
416
+ for await (const chunk of req) chunks.push(chunk)
417
+ const raw = Buffer.concat(chunks).toString('utf8')
417
418
  const body = JSON.parse(raw || '{}')
418
419
  const agent = String(body.agent || '')
419
420
  const action = String(body.action || '')
@@ -452,8 +453,9 @@ export function apply(ctx, config) {
452
453
  return json(res, 200, { ok: true, config: safe, revision: me?.revision ?? 0, writable: true, readonly: false, schema: me?.schema ?? null, dsh: dshInfo, version: versionRef })
453
454
  }
454
455
  if (method === 'POST') {
455
- let raw = ''
456
- for await (const chunk of req) raw += chunk
456
+ const cfgChunks = []
457
+ for await (const chunk of req) cfgChunks.push(chunk)
458
+ const raw = Buffer.concat(cfgChunks).toString('utf8')
457
459
  let body = {}
458
460
  try { body = JSON.parse(raw || '{}') } catch { return json(res, 400, { ok: false, error: 'JSON 解析失败' }) }
459
461
  const patch = body.patch ?? {}
package/lib/api.js CHANGED
@@ -147,8 +147,9 @@ export function createApi(deps = {}) {
147
147
  return
148
148
  }
149
149
  case '/write': {
150
- let raw = ''
151
- for await (const chunk of req) raw += chunk
150
+ const chunks = []
151
+ for await (const chunk of req) chunks.push(chunk)
152
+ const raw = Buffer.concat(chunks).toString('utf8')
152
153
  let body
153
154
  try { body = JSON.parse(raw || '{}') } catch { return json(res, 400, { ok: false, error: 'JSON 解析失败' }) }
154
155
  if (!body.body) return json(res, 400, { ok: false, error: '缺少正文' })
@@ -158,8 +159,9 @@ export function createApi(deps = {}) {
158
159
  return
159
160
  }
160
161
  case '/import': {
161
- let raw = ''
162
- for await (const chunk of req) raw += chunk
162
+ const importChunks = []
163
+ for await (const chunk of req) importChunks.push(chunk)
164
+ const raw = Buffer.concat(importChunks).toString('utf8')
163
165
  if (raw.length > 20 * 1024 * 1024) return json(res, 413, { ok: false, error: '文件过大' })
164
166
  let payload
165
167
  try { payload = JSON.parse(raw || '{}') } catch { return json(res, 400, { ok: false, error: 'JSON 解析失败' }) }
@@ -238,8 +240,9 @@ export function createApi(deps = {}) {
238
240
  return
239
241
  }
240
242
  case '/feedback': {
241
- let raw = ''
242
- for await (const chunk of req) raw += chunk
243
+ const fbChunks = []
244
+ for await (const chunk of req) fbChunks.push(chunk)
245
+ const raw = Buffer.concat(fbChunks).toString('utf8')
243
246
  let rec
244
247
  try { rec = JSON.parse(raw || '{}') } catch { return json(res, 400, { ok: false, error: 'JSON 解析失败' }) }
245
248
  if (!rec || !rec.path) return json(res, 400, { ok: false, error: '缺少 path' })
@@ -320,8 +323,9 @@ export function json(res, status, body) {
320
323
  /** 读请求体(POST body),返回解析后的 JSON 对象或空。 */
321
324
  export async function readBody(req) {
322
325
  try {
323
- let raw = ''
324
- for await (const chunk of req) raw += chunk
326
+ const chunks = []
327
+ for await (const chunk of req) chunks.push(chunk)
328
+ const raw = Buffer.concat(chunks).toString('utf8')
325
329
  return raw ? JSON.parse(raw) : {}
326
330
  } catch { return {} }
327
331
  }