// 测试：创建书籍时自动检测规模（200字描述）
// 直接观察最终传入prompt的字数

const http = require('http');

function request(options, postData) {
  return new Promise((resolve, reject) => {
    const req = http.request(options, (res) => {
      let data = '';
      res.on('data', chunk => data += chunk);
      res.on('end', () => resolve(data));
    });
    req.on('error', reject);
    if (postData) req.write(postData);
    req.end();
  });
}

async function main() {
  // 创建书籍：描述=生成200字文本，没选规模
  const body = JSON.stringify({
    title: '测试',
    description: '生成200字文本'
  });

  const result = await request({
    hostname: 'localhost',
    port: 3000,
    path: '/api/book-generator/langgraph/books',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(body)
    }
  }, body);

  const data = JSON.parse(result);
  console.log('\n========== 创建书籍结果 ==========');
  console.log(`bookId: ${data.data.book.id}`);
  console.log(`bookScale: ${data.data.book.bookScale}`);
  console.log(`totalChapters: ${data.data.book.totalChapters}`);
  console.log(`estimatedWords: ${data.data.book.estimatedWords}`);
  console.log(`aiPreparing: ${data.data.aiPreparing}`);
  console.log('\n说明: aiPreparing=true 表示AI正在异步检测规模');
  console.log('如果bookScale=1000且描述有"200字"，说明自动检测已生效');
}

main().catch(console.error);