(url: string, options: RequestInit = {})
| 129 | } |
| 130 | |
| 131 | fetch<T>(url: string, options: RequestInit = {}) { |
| 132 | const token = getToken() |
| 133 | if (!token) { |
| 134 | this.logout() |
| 135 | throw new Error("not logged in") |
| 136 | } |
| 137 | |
| 138 | return fetch(`${OAP_ROOT_URL}${url}`, { |
| 139 | ...options, |
| 140 | headers: { |
| 141 | ...options.headers, |
| 142 | Authorization: `Bearer ${token}`, |
| 143 | "User-Agent": `Dive Desktop(${CLIENT_ID})-${packageJson.version}`, |
| 144 | }, |
| 145 | }).then((res) => res.text() as Promise<T>) |
| 146 | .then(text => { |
| 147 | try { |
| 148 | return JSON.parse(text as string) as T |
| 149 | } catch (_error) { |
| 150 | return text as T |
| 151 | } |
| 152 | }) |
| 153 | } |
| 154 | |
| 155 | getMCPTags() { |
| 156 | return this.fetch<{ body: { tag: string, count: number }[], error: null, status_code: number, status_message: string }>("/api/v1/mcp/tags") |
no test coverage detected