diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 5bae125d..555b7cd3 100644 --- a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json +++ b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "name": "minimax-bot", "displayName": "MiniMax Bot", - "version": "0.7.36", + "version": "0.7.37", "description": "Turn MiniMax Code into an always-on team of Bots. A Chief Bot helps you build the team; in group chats the admin answers and @mentions hand work to other members. Every Bot has its own octopus avatar and memory, with scheduled tasks and usage stats.", "author": "MiniMax Code", "icon": "icon.png", diff --git a/plugins/minimax-ai/minimax-bot/README.md b/plugins/minimax-ai/minimax-bot/README.md index e7f6907d..e64a391a 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -139,6 +139,12 @@ The hand-over between two Bots of a group carried the tail of the previous reply - The report a finished task batch hands back was trimmed to 4,000 characters per task without saying so. The task record already carries a marker when it had to shorten a result itself, and the report did not consult it, so a reader had no way to tell "this is the whole answer" from "this is the first part of it". - A result that was cut now ends with the same truncation mark the rest of the plugin uses. A result that fits is unchanged, and the full text is still read back with `get_tasks`. +## 0.7.37 An uploaded file whose name carries `..` can be attached + +- An upload kept the file name as given apart from a few forbidden characters, so a name containing `..` reached the stored id. The attachment reader refuses any id with `..` in it, and the file could never be attached again — the upload looked fine and the message that tried to use it failed. +- The stored name now replaces a run of dots, and a long name is cut on a whole character so an emoji is never left half-written. +- The extension is kept apart from the rest of the name and survives that cleaning, because it decides how the file is served: `photo..png` was stored as `photo_png`, so it went out as `application/octet-stream` and the Bot received a plain file instead of an image. It is stored as `photo.png` now and stays a PNG end to end. + ## 0.7.10 Optional group notes - A group can keep a note of what it said. After every round the group records the closing lines of the replies, and every Bot of the group gets that record in its standing brief. diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index 8a836bdd..ed9da831 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs @@ -662,7 +662,7 @@ export function createMcpHandler({ team, engine }) { result = { protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0], capabilities: { tools: { listChanged: false } }, - serverInfo: { name: 'minimax-bot', version: '0.7.36' }, + serverInfo: { name: 'minimax-bot', version: '0.7.37' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/server.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/server.mjs index 4ec12d19..58a56d36 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/server.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/server.mjs @@ -95,8 +95,28 @@ const MAX_UPLOAD_BYTES = 50 * 1024 * 1024; /** A file name safe to keep on disk and show back: no path parts, controls or leading dots. */ function safeUploadName(raw) { const base = String(raw ?? '').split(/[\\/]/).pop() ?? ''; - const clean = base.replace(/[\u0000-\u001f\u007f<>:"|?*]/g, '_').replace(/^\.+/, '').trim().slice(0, 140); - return clean || 'file'; + const cleaned = base.replace(/[\u0000-\u001f\u007f<>:"|?*]/g, '_'); + // The extension decides how the file is served and whether a Bot reads it as an image, so it + // is kept apart from the rest of the name and survives the cleaning: `photo..png` stays a PNG. + const dot = cleaned.lastIndexOf('.'); + const hasExtension = dot > 0 && dot < cleaned.length - 1 && /^\.[A-Za-z0-9]{1,15}$/.test(cleaned.slice(dot)); + const extension = hasExtension ? cleaned.slice(dot) : ''; + const stem = hasExtension ? cleaned.slice(0, dot) : cleaned; + // `..` reaches the stored id, and the attachment reader refuses any id carrying it, so the file + // could never be attached again. A dot at the end of the stem would join the extension into + // one, so it goes as well. + const safeStem = stem.replace(/\.{2,}/g, '_').replace(/^\.+|\.+$/g, '').trim(); + // A stem that was nothing but dots leaves nothing behind, so it falls back like an empty name. + const stemText = stem.replace(/\./g, '') === '' ? 'file' : safeStem; + // Cut by code point so a character such as an emoji is not left half-written, and keep room + // for the extension: a name that is cut short must still end in it. + const budget = Math.max(1, 140 - extension.length); + let clean = ''; + for (const point of stemText) { + if (clean.length + point.length > budget) break; + clean += point; + } + return `${clean || 'file'}${extension}`; } /** Whether a Bot (or a relay) in this chat named `src` in its text — the only files /api/media serves. */ diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index a297a586..c152016d 100644 --- a/plugins/minimax-ai/minimax-bot/package.json +++ b/plugins/minimax-ai/minimax-bot/package.json @@ -1,6 +1,6 @@ { "name": "minimax-bot", - "version": "0.7.36", + "version": "0.7.37", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/http-reliability.test.mjs b/plugins/minimax-ai/minimax-bot/tests/http-reliability.test.mjs index 1ec19828..eec36b10 100644 --- a/plugins/minimax-ai/minimax-bot/tests/http-reliability.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/http-reliability.test.mjs @@ -10,6 +10,8 @@ import { pathToFileURL } from 'node:url'; const pluginRoot = resolve(process.env.BOT_PLUGIN_ROOT ?? resolve(import.meta.dirname, '..')); const { start } = await import(pathToFileURL(join(pluginRoot, 'miniapp/node/server.mjs')).href); const { Store } = await import(pathToFileURL(join(pluginRoot, 'miniapp/node/store.mjs')).href); +const { Engine, UPLOAD_NAME_RE } = await import(pathToFileURL(join(pluginRoot, 'miniapp/node/engine.mjs')).href); +const { MemoryStore } = await import(pathToFileURL(join(pluginRoot, 'miniapp/node/memory.mjs')).href); async function fixture(t, { messages = 0, prepare, agent } = {}) { const dataDir = await mkdtemp(join(tmpdir(), 'bot-http-reliability-')); @@ -359,3 +361,69 @@ test('HTTP task snapshot and stop endpoint control an admitted MCP delegation', for(let i=0;i<100;i++){ status=(await (await fetch(`${base}/api/state`)).json()).tasks[0].status;if(status==='cancelled')break;await new Promise((resolve)=>setTimeout(resolve,5)); } assert.equal(status,'cancelled'); }); + +test('an upload whose name carries .. still produces an id the attachment reader accepts', async (t) => { + const { base } = await fixture(t); + // The attachment reader refuses any id containing `..`, so the stored name must not carry it. + const response = await fetch(`${base}/api/uploads?name=${encodeURIComponent('report..final.txt')}`, { + method: 'POST', body: 'hello', headers: { 'content-type': 'application/octet-stream' }, + }); + const body = await response.json(); + assert.equal(response.status, 200); + assert.equal(body.upload.id.includes('..'), false, body.upload.id); + assert.equal(UPLOAD_NAME_RE.test(body.upload.id), true, body.upload.id); + // A normal name is left alone. + const plain = await fetch(`${base}/api/uploads?name=notes.txt`, { + method: 'POST', body: 'hello', headers: { 'content-type': 'application/octet-stream' }, + }); + assert.equal((await plain.json()).upload.name, 'notes.txt'); +}); + +test('an upload whose name carries .. keeps its extension, so it is still served and read as an image', async (t) => { + const { base, dataDir } = await fixture(t); + const bytes = Buffer.from('89504e470d0a1a0a0000000d49484452', 'hex'); + + // The attachment reader refuses any id containing `..`, so the stored name must not carry it. + // The extension decides the content type and whether a Bot reads the file as an image. + const response = await fetch(`${base}/api/uploads?name=${encodeURIComponent('photo..png')}`, { + method: 'POST', body: bytes, headers: { 'content-type': 'application/octet-stream' }, + }); + const body = await response.json(); + assert.equal(response.status, 200); + assert.equal(body.upload.id.includes('..'), false, body.upload.id); + assert.equal(UPLOAD_NAME_RE.test(body.upload.id), true, body.upload.id); + assert.equal(body.upload.name, 'photo.png', body.upload.name); + assert.equal(body.upload.kind, 'image', body.upload.kind); + + // Served back, it is a PNG and the bytes are the ones that went in. + const served = await fetch(`${base}/api/uploads/${encodeURIComponent(body.upload.id)}`); + assert.equal(served.status, 200); + assert.equal(served.headers.get('content-type'), 'image/png'); + assert.deepEqual(Buffer.from(await served.arrayBuffer()), bytes); + + // And the Bot that receives the attachment reads it as an image, not as a plain file. + const store = new Store(dataDir); + await store.init(); + const memory = new MemoryStore(dataDir); + await memory.init(); + const engine = new Engine({ store, memory, logger: { warn() {} }, broadcast() {}, retryDelaysMs: [] }); + const attachments = await engine.resolveAttachments([body.upload.id]); + assert.equal(attachments.length, 1); + assert.equal(attachments[0].kind, 'image', attachments[0].kind); + assert.equal(attachments[0].name, 'photo.png'); + engine.dispose(); + + // A name with the dots further from the extension keeps its extension too. + const other = await fetch(`${base}/api/uploads?name=${encodeURIComponent('report..final.txt')}`, { + method: 'POST', body: 'hello', headers: { 'content-type': 'application/octet-stream' }, + }); + const otherBody = await other.json(); + assert.equal(otherBody.upload.name, 'report_final.txt', otherBody.upload.name); + assert.equal(otherBody.upload.kind, 'file', otherBody.upload.kind); + + // A normal name is left alone. + const plain = await fetch(`${base}/api/uploads?name=notes.txt`, { + method: 'POST', body: 'hello', headers: { 'content-type': 'application/octet-stream' }, + }); + assert.equal((await plain.json()).upload.name, 'notes.txt'); +});