@vincentbanana/bananacli 0.8.2 → 0.8.3

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.
@@ -317,7 +317,7 @@ export async function startUiServer(options) {
317
317
  const provider = () => createProvider(config.current, config);
318
318
  const backups = (sessionId) => new BackupStore(join(bananaHome(), 'backups'), sessionId);
319
319
  const info = async (session) => ({
320
- version: '0.8.2',
320
+ version: '0.8.3',
321
321
  provider: { name: config.current, model: config.providers[config.current]?.model ?? '', protocol: config.providers[config.current]?.protocol ?? 'openai' },
322
322
  reasoning: {
323
323
  level: session.reasoning ?? 'standard',
@@ -344,7 +344,11 @@ export async function startUiServer(options) {
344
344
  session: {
345
345
  id: session.id,
346
346
  title: session.title,
347
- messages: session.messages,
347
+ // 图片 base64 和附件全文只用于请求模型,不必每次 /api/info 全量回传前端。
348
+ messages: session.messages.map(({ images, attachmentContext, ...message }) => ({
349
+ ...message,
350
+ ...(images?.length ? { imageCount: images.length } : {}),
351
+ })),
348
352
  todos: session.todos ?? [],
349
353
  usage: session.usage ?? { inputTokens: 0, outputTokens: 0 },
350
354
  mode: session.mode ?? 'build',
@@ -925,6 +929,9 @@ export async function startUiServer(options) {
925
929
  }
926
930
  if (path === '/api/chat' && req.method === 'POST') {
927
931
  const body = await readJson(req);
932
+ if (typeof body.message !== 'string' || !body.message.trim()) {
933
+ return json(res, 400, { error: '消息不能为空' });
934
+ }
928
935
  if (turn)
929
936
  return json(res, 409, { error: '当前正在跑一轮对话' });
930
937
  // 前端会带上会话 id:以它为准,避免新建对话后又被解析回旧对话
@@ -1449,8 +1456,15 @@ async function sendFile(res, name) {
1449
1456
  }
1450
1457
  async function readBody(req) {
1451
1458
  const chunks = [];
1452
- for await (const chunk of req)
1453
- chunks.push(Buffer.from(chunk));
1459
+ let size = 0;
1460
+ const max = 30 * 1024 * 1024;
1461
+ for await (const chunk of req) {
1462
+ const buffer = Buffer.from(chunk);
1463
+ size += buffer.byteLength;
1464
+ if (size > max)
1465
+ throw new Error('请求体过大');
1466
+ chunks.push(buffer);
1467
+ }
1454
1468
  return Buffer.concat(chunks).toString('utf8');
1455
1469
  }
1456
1470
  async function readJson(req) {
package/dist/ui/app.js CHANGED
@@ -794,17 +794,20 @@ function sessionToMarkdown(messages, title) {
794
794
  }
795
795
 
796
796
  async function downloadSession(format, id) {
797
- let session = state.info?.session;
798
- if (!session) return;
799
- // 导出别的会话时只读取,不切换当前会话。
800
- if (id && id !== session.id) {
801
- try {
802
- const result = await post('session', { action: 'load', ref: id });
803
- if (result?.session) session = result.session;
804
- } catch (error) {
805
- toast('导出失败:' + (error?.message ?? error));
806
- return;
807
- }
797
+ // 始终从服务端读取完整会话:/api/info 为了性能裁掉了图片 base64 和附件全文。
798
+ const targetId = id || state.info?.session?.id;
799
+ if (!targetId) return;
800
+ let session;
801
+ try {
802
+ const result = await post('session', { action: 'load', ref: targetId });
803
+ session = result?.session;
804
+ } catch (error) {
805
+ toast('导出失败:' + (error?.message ?? error));
806
+ return;
807
+ }
808
+ if (!session) {
809
+ toast('导出失败:没找到这个对话');
810
+ return;
808
811
  }
809
812
  const blob =
810
813
  format === 'json'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincentbanana/bananacli",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "A multi-provider AI agent for your terminal: file tools, shell, web search, persistent sessions, diff preview and undo",
5
5
  "type": "module",
6
6
  "engines": {