-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenclaw.js
More file actions
38 lines (32 loc) · 972 Bytes
/
openclaw.js
File metadata and controls
38 lines (32 loc) · 972 Bytes
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
const axios = require('axios');
const OPENCLAW_URL = process.env.OPENCLAW_URL;
const TIMEOUT_MS = 15_000;
async function queryAgent({ question, threadHistory, knowledgeSnippets }) {
const url = `${OPENCLAW_URL}/agent`;
const { data } = await axios.post(
url,
{
question,
thread_history: threadHistory,
knowledge_snippets: knowledgeSnippets,
},
{
timeout: TIMEOUT_MS,
headers: { 'Content-Type': 'application/json' },
}
);
// Validate expected shape
if (typeof data.final_answer !== 'string') {
throw new Error('OpenClaw response missing final_answer');
}
if (typeof data.confidence !== 'number') {
throw new Error('OpenClaw response missing confidence');
}
return {
final_answer: data.final_answer,
confidence: data.confidence,
escalate: Boolean(data.escalate),
escalation_question_for_aarav: data.escalation_question_for_aarav || '',
};
}
module.exports = { queryAgent };