@unikode/cli 1.0.16 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +23 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3680,36 +3680,46 @@ async function executeLocalTool(toolName, input, mode) {
|
|
|
3680
3680
|
}
|
|
3681
3681
|
case "webSearchTool": {
|
|
3682
3682
|
const { query, searchDepth, maxResults, includeAnswer } = toolInputSchemas.webSearchTool.parse(input);
|
|
3683
|
-
const
|
|
3684
|
-
const
|
|
3685
|
-
if (!
|
|
3683
|
+
const apiUrl = process.env.API_URL ?? "http://localhost:3000";
|
|
3684
|
+
const searchEndpointUrl = apiUrl + "/tools/webSearchTool";
|
|
3685
|
+
if (!searchEndpointUrl) {
|
|
3686
3686
|
return {
|
|
3687
3687
|
error: true,
|
|
3688
|
-
message: "
|
|
3688
|
+
message: "WEB_SEARCH_ENDPOINT_URL is not configured in the CLI environment."
|
|
3689
3689
|
};
|
|
3690
3690
|
}
|
|
3691
3691
|
try {
|
|
3692
|
-
const
|
|
3692
|
+
const auth = getAuth();
|
|
3693
|
+
const headers = {
|
|
3694
|
+
"Content-Type": "application/json"
|
|
3695
|
+
};
|
|
3696
|
+
if (auth) {
|
|
3697
|
+
headers["Authorization"] = `Bearer ${auth.token}`;
|
|
3698
|
+
}
|
|
3699
|
+
const response = await fetch(searchEndpointUrl, {
|
|
3693
3700
|
method: "POST",
|
|
3694
|
-
headers
|
|
3695
|
-
"Content-Type": "application/json"
|
|
3696
|
-
},
|
|
3701
|
+
headers,
|
|
3697
3702
|
body: JSON.stringify({
|
|
3698
|
-
api_key: apiKey,
|
|
3699
3703
|
query,
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3704
|
+
searchDepth,
|
|
3705
|
+
maxResults,
|
|
3706
|
+
includeAnswer
|
|
3703
3707
|
})
|
|
3704
3708
|
});
|
|
3705
3709
|
if (!response.ok) {
|
|
3706
3710
|
const errorText = await response.text();
|
|
3707
3711
|
return {
|
|
3708
3712
|
error: true,
|
|
3709
|
-
message: `
|
|
3713
|
+
message: `Web search service failed (${response.status}): ${errorText}`
|
|
3710
3714
|
};
|
|
3711
3715
|
}
|
|
3712
3716
|
const data = await response.json();
|
|
3717
|
+
if (data.error) {
|
|
3718
|
+
return {
|
|
3719
|
+
error: true,
|
|
3720
|
+
message: data.error
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3713
3723
|
return {
|
|
3714
3724
|
error: false,
|
|
3715
3725
|
query,
|