@unikode/cli 1.0.15 → 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.
Files changed (2) hide show
  1. package/dist/index.js +27 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1609,6 +1609,7 @@ var ThemeDialogContent = () => {
1609
1609
  };
1610
1610
  // src/lib/oauth.ts
1611
1611
  import open from "open";
1612
+ import os from "os";
1612
1613
  var LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
1613
1614
  function toBase64Url(input) {
1614
1615
  return Buffer.from(input).toString("base64url");
@@ -1645,6 +1646,7 @@ async function performLogin() {
1645
1646
  return new Promise((resolve, reject) => {
1646
1647
  const server = Bun.serve({
1647
1648
  port: 0,
1649
+ hostname: "0.0.0.0",
1648
1650
  async fetch(req) {
1649
1651
  const url = new URL(req.url);
1650
1652
  if (url.pathname !== "/callback") {
@@ -1714,7 +1716,8 @@ async function performLogin() {
1714
1716
  reject(new Error("Failed to start callback server"));
1715
1717
  return;
1716
1718
  }
1717
- const state = encodeState({ port, nonce });
1719
+ const cliHost = os.hostname();
1720
+ const state = encodeState({ port, nonce, cliHost });
1718
1721
  const redirectUri = `${apiUrl}/auth/callback`;
1719
1722
  const authorizeUrl = new URL(`${clerkFrontendApi}/oauth/authorize`);
1720
1723
  authorizeUrl.searchParams.set("response_type", "code");
@@ -3677,36 +3680,46 @@ async function executeLocalTool(toolName, input, mode) {
3677
3680
  }
3678
3681
  case "webSearchTool": {
3679
3682
  const { query, searchDepth, maxResults, includeAnswer } = toolInputSchemas.webSearchTool.parse(input);
3680
- const apiKey = process.env.TAVILY_API_KEY;
3681
- const tavilyapiurl = process.env.TAVILY_API_URL;
3682
- if (!apiKey) {
3683
+ const apiUrl = process.env.API_URL ?? "http://localhost:3000";
3684
+ const searchEndpointUrl = apiUrl + "/tools/webSearchTool";
3685
+ if (!searchEndpointUrl) {
3683
3686
  return {
3684
3687
  error: true,
3685
- message: "TAVILY_API_KEY is not set in the environment. Add it to your .env file to enable web search."
3688
+ message: "WEB_SEARCH_ENDPOINT_URL is not configured in the CLI environment."
3686
3689
  };
3687
3690
  }
3688
3691
  try {
3689
- const response = await fetch(`${tavilyapiurl}`, {
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, {
3690
3700
  method: "POST",
3691
- headers: {
3692
- "Content-Type": "application/json"
3693
- },
3701
+ headers,
3694
3702
  body: JSON.stringify({
3695
- api_key: apiKey,
3696
3703
  query,
3697
- search_depth: searchDepth,
3698
- max_results: maxResults,
3699
- include_answer: includeAnswer
3704
+ searchDepth,
3705
+ maxResults,
3706
+ includeAnswer
3700
3707
  })
3701
3708
  });
3702
3709
  if (!response.ok) {
3703
3710
  const errorText = await response.text();
3704
3711
  return {
3705
3712
  error: true,
3706
- message: `Tavily API request failed (${response.status}): ${errorText}`
3713
+ message: `Web search service failed (${response.status}): ${errorText}`
3707
3714
  };
3708
3715
  }
3709
3716
  const data = await response.json();
3717
+ if (data.error) {
3718
+ return {
3719
+ error: true,
3720
+ message: data.error
3721
+ };
3722
+ }
3710
3723
  return {
3711
3724
  error: false,
3712
3725
  query,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unikode/cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {