Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"name": "minimax-bot-team",
"displayName": "MiniMax Bot Team / MiniMax Bot 团队",
"version": "1.0.0",
"version": "1.0.1",
"description": "现在的 bot 像一个人轮流带着几个面具跟你聊天。MiniMax Bot Team 给你的是一支真正各有能力、各有性格的团队,各自守着一个领域,也能围坐一起,从不同角度讨论同一个问题。 / Today's bot is one person wearing several masks, taking turns with you. MiniMax Bot Team gives you a team instead: members with different skills and different temperaments, each guarding one field, and they can sit down together and argue about the same question from different angles.",
"author": "antianqi",
"icon": "icon.png",
Expand Down
2 changes: 1 addition & 1 deletion plugins/antianqi/minimax-bot-team/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bot Team gives you a team instead: members with different skills and different
temperaments, each guarding one field, and they can sit down together and argue about the
same question from different angles.

Author: [antianqi](https://github.com/antianqi) - Version: `1.0.0`
Author: [antianqi](https://github.com/antianqi) - Version: `1.0.1`

## What it does

Expand Down
2 changes: 1 addition & 1 deletion plugins/antianqi/minimax-bot-team/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
现在的 bot 像一个人轮流带着几个面具跟你聊天。MiniMax Bot Team 给你的是一支真正各有
能力、各有性格的团队,各自守着一个领域,也能围坐一起,从不同角度讨论同一个问题。

作者:[antianqi](https://github.com/antianqi) - 版本:`1.0.0`
作者:[antianqi](https://github.com/antianqi) - 版本:`1.0.1`

## 它做什么

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
export const PLUGIN_ID = 'minimax-bot-team';

/** The version the Host and the MCP tools report. */
export const PLUGIN_VERSION = '1.0.0';
export const PLUGIN_VERSION = '1.0.1';
9 changes: 7 additions & 2 deletions plugins/antianqi/minimax-bot-team/miniapp/node/store.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,17 @@ export class Store {

async deleteChat(chatId) {
await this.getMessages(chatId);
// The transcript is the one thing here that cannot be rebuilt, so the state that
// forgets this chat goes to disk first. A failed state write then leaves the chat and
// its messages both as they were, and the caller can simply try again.
await this.enqueue(async () => {
const sessions = { ...this.state.sessions };
delete sessions[chatId];
await writeJsonAtomic(this.statePath, { ...this.state, sessions });
delete this.state.sessions[chatId];
await this.writeMessages(chatId, []);
this.messageCache.set(chatId, []);
delete this.state.sessions[chatId];
});
await this.save();
}

/** Sidebar summary of one chat, read from the warm cache. */
Expand Down
2 changes: 1 addition & 1 deletion plugins/antianqi/minimax-bot-team/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minimax-bot-team",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"type": "module",
"mcode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Use this skill when the user wants to build or change a team of Min
license: Apache-2.0
metadata:
author: antianqi
version: 1.0.0
version: 1.0.1
---

# MiniMax Bot 团队搭建
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @ts-check
// Deleting a chat must not lose its messages when the state write fails.
//
// The transcript is the one thing that cannot be rebuilt, so the state that forgets the
// chat goes to disk first. A failed write then leaves the chat and its messages both as
// they were, and the caller can simply try again. This file fails if that order flips
// back: the failure injection below replaces state.json with a directory of the same name,
// so every write to it fails.

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

import { Store } from '../miniapp/node/store.mjs';

async function fixture(t) {
const dir = await mkdtemp(join(tmpdir(), 'bot-delete-chat-'));
t.after(() => rm(dir, { recursive: true, force: true }));
const store = new Store(dir);
await store.init();
return { dir, store, chat: store.chatIds()[0] };
}

test('a failed state write leaves the chat and its messages untouched', async (t) => {
const { dir, store, chat } = await fixture(t);
await store.appendMessage(chat, { role: 'user', text: 'the greeting' });
await store.appendMessage(chat, { role: 'bot', text: 'the answer' });
store.state.sessions[chat] = { sessionId: 's_1', stamp: 1, lastSeen: 1 };
await store.save();
// The store seeds a greeting of its own, so the count is read, never assumed.
const before = (await store.getMessages(chat)).length;
assert.ok(before >= 2, 'the chat has a transcript to lose');

// The state file becomes a directory: every write to it fails.
const statePath = join(dir, 'state.json');
const saved = await readFile(statePath, 'utf8');
await rm(statePath, { force: true });
await mkdir(statePath, { recursive: true });

await assert.rejects(() => store.deleteChat(chat));

// The transcript is still on disk, and the live state still knows the chat.
const onDisk = JSON.parse(await readFile(store.messagePath(chat), 'utf8'));
assert.equal(onDisk.length, before, 'the messages are still on disk');
assert.ok(store.state.sessions[chat], 'the live state still knows the chat');

// Put the state file back and restart: the chat is still there with its messages.
await rm(statePath, { recursive: true, force: true });
await writeFile(statePath, saved, 'utf8');
const restarted = new Store(dir);
await restarted.init();
const messages = await restarted.getMessages(chat);
assert.equal(messages.length, before, 'the messages survive the restart');
assert.ok(messages.some((message) => message.text === 'the greeting'), 'the greeting is still there');
assert.ok(restarted.state.sessions[chat], 'the session survives the restart');
});

test('a delete that succeeds clears the transcript and forgets the chat', async (t) => {
const { dir, store, chat } = await fixture(t);
await store.appendMessage(chat, { role: 'user', text: 'the greeting' });
await store.appendMessage(chat, { role: 'bot', text: 'the answer' });
store.state.sessions[chat] = { sessionId: 's_1', stamp: 1, lastSeen: 1 };
await store.save();

await store.deleteChat(chat);

assert.equal((await store.getMessages(chat)).length, 0, 'the transcript is empty');
assert.equal(store.state.sessions[chat], undefined, 'the chat is forgotten');
const restarted = new Store(dir);
await restarted.init();
assert.equal((await restarted.getMessages(chat)).length, 0, 'the transcript stays empty');
assert.equal(restarted.state.sessions[chat], undefined, 'the chat stays forgotten');
});
Loading