Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(tools): use shared api-client for auth headers
yushen53cffe923b4b
diff --git a/packages/core/src/agent/tools/data/finance/api.ts b/packages/core/src/agent/tools/data/finance/api.tsindex 8a2b01deef..367927a1ed 100644--- a/packages/core/src/agent/tools/data/finance/api.ts+++ b/packages/core/src/agent/tools/data/finance/api.ts@@ -5,9 +5,8 @@* All endpoints use GET with query parameters.*/-import { getLocalAuth } from "../../../../hub/auth-store.js";+import { API_BASE_URL, getAuthHeaders } from "../../../../hub/api-client.js";-const BASE_URL = "https://api-dev.copilothub.ai";const PATH_PREFIX = "/api/v1/financial";const TIMEOUT_MS = 30_000;@@ -23,14 +22,9 @@ export async function financeFetch<T = Record<string, unknown>>(params: Record<string, string | string[] | number | boolean | undefined>,signal?: AbortSignal,): Promise<{ data: T; url: string }> {- const auth = getLocalAuth();- if (!auth) {- throw new Error(- "Not logged in. Please sign in via the Desktop app to use financial data tools.",- );- }+ const authHeaders = getAuthHeaders();- const url = new URL(PATH_PREFIX + path, BASE_URL);+ const url = new URL(PATH_PREFIX + path, API_BASE_URL);for (const [key, value] of Object.entries(params)) {if (value === undefined || value === null) continue;if (Array.isArray(value)) {@@ -51,9 +45,7 @@ export async function financeFetch<T = Record<string, unknown>>(method: "GET",headers: {Accept: "application/json",- sid: auth.sid,- "device-id": auth.deviceId,- "os-type": "3",+ ...authHeaders,},signal: combinedSignal,});diff --git a/packages/core/src/agent/tools/web/web-search.ts b/packages/core/src/agent/tools/web/web-search.tsindex 81d045ebe6..3b508b26f7 100644--- a/packages/core/src/agent/tools/web/web-search.ts+++ b/packages/core/src/agent/tools/web/web-search.ts@@ -1,7 +1,7 @@import { Type } from "@sinclair/typebox";import type { AgentTool } from "@mariozechner/pi-agent-core";-import { getLocalAuth } from "../../../hub/auth-store.js";+import { API_BASE_URL, getAuthHeaders } from "../../../hub/api-client.js";import {DEFAULT_CACHE_TTL_MINUTES,DEFAULT_TIMEOUT_SECONDS,@@ -14,7 +14,7 @@ import {import type { CacheEntry } from "./cache.js";import { jsonResult, readStringParam } from "./param-helpers.js";-const WEB_SEARCH_ENDPOINT = "https://api-dev.copilothub.ai/api/v1/web-search";+const WEB_SEARCH_PATH = "/api/v1/web-search";const SEARCH_CACHE = new Map<string, CacheEntry<Record<string, unknown>>>();@@ -59,18 +59,13 @@ async function runDevvSearch(params: {snippet: string;}>;}> {- const auth = getLocalAuth();- if (!auth) {- throw new Error("Not logged in. Please sign in via the Desktop app to use web search.");- }+ const authHeaders = getAuthHeaders();- const res = await fetch(WEB_SEARCH_ENDPOINT, {+ const res = await fetch(`${API_BASE_URL}${WEB_SEARCH_PATH}`, {method: "POST",headers: {"Content-Type": "application/json",- sid: auth.sid,- "device-id": auth.deviceId,- "os-type": "3",+ ...authHeaders,},body: JSON.stringify({ q: params.query }),signal: withTimeout(undefined, params.timeoutSeconds * 1000),