MCPcopy Index your code
hub / github.com/AI45Lab/Code / main

Function main

sdk/node/examples/basic/test_generate_object.ts:68–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66// ============================================================================
67
68async function main() {
69 console.log('='.repeat(70));
70 console.log('generate_object Integration Test (Node.js SDK + MiniMax)');
71 console.log('='.repeat(70));
72
73 const configContent = loadConfig();
74 const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'a3s-genobj-test-'));
75 console.log(`Workspace: ${workspace}\n`);
76
77 const agent = await Agent.create(configContent);
78 const session = agent.session(workspace, {
79 permissionPolicy: { defaultDecision: 'allow' },
80 });
81
82 // ── Test 1: Direct tool call — simple extraction ──────────────────────────
83
84 await runTest('generate_object: extract person info (tool mode)', async () => {
85 const result = await session.tool('generate_object', {
86 schema: {
87 type: 'object',
88 required: ['name', 'age', 'city'],
89 properties: {
90 name: { type: 'string' },
91 age: { type: 'integer' },
92 city: { type: 'string' },
93 },
94 },
95 prompt: 'Extract: "Alice Chen is 28 years old and lives in Shanghai."',
96 schema_name: 'person',
97 mode: 'tool',
98 });
99
100 if (result.exitCode !== 0) throw new Error(`Tool failed: ${result.output}`);
101 const parsed = JSON.parse(result.output);
102 const obj = parsed.object;
103 if (obj.name.toLowerCase() !== 'alice chen') throw new Error(`name: ${obj.name}`);
104 if (obj.age !== 28) throw new Error(`age: ${obj.age}`);
105 if (!obj.city.toLowerCase().includes('shanghai')) throw new Error(`city: ${obj.city}`);
106 console.log(` Result: ${JSON.stringify(obj)}`);
107 });
108
109 // ── Test 2: Enum classification ───────────────────────────────────────────
110
111 await runTest('generate_object: sentiment classification with enum', async () => {
112 const result = await session.tool('generate_object', {
113 schema: {
114 type: 'object',
115 required: ['sentiment', 'confidence'],
116 properties: {
117 sentiment: { type: 'string', enum: ['positive', 'negative', 'neutral'] },
118 confidence: { type: 'number', minimum: 0, maximum: 1 },
119 },
120 },
121 prompt: 'Classify sentiment: "This is the worst product I have ever used. Total waste of money."',
122 schema_name: 'sentiment',
123 });
124
125 if (result.exitCode !== 0) throw new Error(`Tool failed: ${result.output}`);

Callers 1

Calls 8

loadConfigFunction · 0.85
runTestFunction · 0.85
logMethod · 0.45
createMethod · 0.45
sessionMethod · 0.45
toolMethod · 0.45
parseMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected