MCPcopy
hub / github.com/7836246/cursor2api / sendSingleTurn

Function sendSingleTurn

test/e2e-prompt-ab.mjs:150–176  ·  view source on GitHub ↗
(userMessage, { tools = TOOLS, systemPrompt = '', toolChoice } = {})

Source from the content-addressed store, hash-verified

148
149// ─── 单轮请求发送器(用于第一轮分析) ──────────────────────────────────
150async function sendSingleTurn(userMessage, { tools = TOOLS, systemPrompt = '', toolChoice } = {}) {
151 const body = {
152 model: MODEL,
153 max_tokens: 4096,
154 system: systemPrompt || 'You are an AI coding assistant. Working directory: /project.',
155 tools,
156 ...(toolChoice ? { tool_choice: toolChoice } : {}),
157 messages: [{ role: 'user', content: userMessage }],
158 };
159
160 const t0 = Date.now();
161 const resp = await fetch(`${BASE_URL}/v1/messages`, {
162 method: 'POST',
163 headers: { 'Content-Type': 'application/json', 'x-api-key': 'dummy' },
164 body: JSON.stringify(body),
165 });
166
167 if (!resp.ok) {
168 const text = await resp.text();
169 throw new Error(`HTTP ${resp.status}: ${text.substring(0, 200)}`);
170 }
171
172 const data = await resp.json();
173 const latencyMs = Date.now() - t0;
174
175 return { data, latencyMs };
176}
177
178// ─── 多轮 Agentic 循环(用于完整任务分析) ─────────────────────────────
179async function runMultiTurn(userMessage, { tools = TOOLS, systemPrompt = '', toolChoice, maxTurns = MAX_TURNS } = {}) {

Callers 1

e2e-prompt-ab.mjsFile · 0.85

Calls 1

jsonMethod · 0.45

Tested by

no test coverage detected