File size: 2,217 Bytes
f39c319
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import fs from 'fs';
import path from 'path';
import app from './src/index';

const PORT = 3002;
const BASE_URL = `http://localhost:${PORT}`;

const tc = {
    case_id: 'TC-05',
    sample_type: '缺 PRD',
    materials: {
      current_policy_text: '基本条款...',
      prd_text: '', // 故意置空触发 4001
      permission_items: [],
      sdk_items: []
    },
    peer_updates: [],
    regulatory_updates: []
};

async function post(url: string, data: any) {
  const start = Date.now();
  const res = await fetch(url, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(data)
  });
  const latency = Date.now() - start;
  const json = await res.json();
  if (!res.ok) {
    throw { status: res.status, latency, error: json };
  }
  return { data: json, latency };
}

const server = app.listen(PORT, async () => {
  console.log(`Server started on ${PORT}`);
  try {
      const baseContext = {
        case_id: tc.case_id,
        customer_id: 'CUST-TEST',
        customer_name: '测试银行',
        app_name: '测试银行APP',
        business_line: 'retail',
        language: 'zh-CN',
        materials: tc.materials,
        external_context: {
          peer_updates: tc.peer_updates,
          regulatory_updates: tc.regulatory_updates
        },
        metadata: {
          submitted_at: new Date().toISOString(),
          source: 'regression-test'
        }
      };

      const a1Res = await post(`${BASE_URL}/api/agents/peer-reg-summary`, {
        peer_updates: tc.peer_updates,
        regulatory_updates: tc.regulatory_updates,
        business_line: 'retail',
        app_name: '测试银行APP'
      });
      console.log('a1 done');
      
      const a2Res = await post(`${BASE_URL}/api/agents/policy-rewrite`, {
        case_context: baseContext,
        peer_reg_summary: a1Res.data
      });
      console.log('a2 done');
  } catch(err: any) {
      let rec = 'ERROR';
      if (err.error && (err.error.error_code === 'need_more_material' || (err.error.error && err.error.error.code === 4001))) {
         rec = 'need_more_material (4001)';
      }
      console.log('caught:', rec);
  }
  server.close();
  process.exit(0);
});