Remove redundant error handling, move volume item to types file

This commit is contained in:
Theodore Li
2026-02-12 15:31:12 -08:00
parent fc97ce007d
commit 1130f8ddb2
3 changed files with 31 additions and 38 deletions

View File

@@ -1,5 +1,35 @@
import type { ToolResponse } from '@/tools/types'
/**
* Raw volume item from Google Books API response
*/
export interface GoogleBooksVolumeItem {
id: string
volumeInfo: {
title?: string
subtitle?: string
authors?: string[]
publisher?: string
publishedDate?: string
description?: string
pageCount?: number
categories?: string[]
averageRating?: number
ratingsCount?: number
language?: string
previewLink?: string
infoLink?: string
imageLinks?: {
thumbnail?: string
smallThumbnail?: string
}
industryIdentifiers?: Array<{
type: string
identifier: string
}>
}
}
/**
* Volume information structure shared between search and details responses
*/

View File

@@ -29,9 +29,6 @@ interface GoogleBooksVolumeResponse {
identifier: string
}>
}
error?: {
message?: string
}
}
export const googleBooksVolumeDetailsTool: ToolConfig<
@@ -84,10 +81,6 @@ export const googleBooksVolumeDetailsTool: ToolConfig<
transformResponse: async (response: Response) => {
const data: GoogleBooksVolumeResponse = await response.json()
if (data.error) {
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
}
if (!data.volumeInfo) {
throw new Error('Volume not found')
}

View File

@@ -1,37 +1,11 @@
import type {
GoogleBooksVolumeItem,
GoogleBooksVolumeSearchParams,
GoogleBooksVolumeSearchResponse,
VolumeInfo,
} from '@/tools/google_books/types'
import type { ToolConfig } from '@/tools/types'
interface GoogleBooksVolumeItem {
id: string
volumeInfo: {
title?: string
subtitle?: string
authors?: string[]
publisher?: string
publishedDate?: string
description?: string
pageCount?: number
categories?: string[]
averageRating?: number
ratingsCount?: number
language?: string
previewLink?: string
infoLink?: string
imageLinks?: {
thumbnail?: string
smallThumbnail?: string
}
industryIdentifiers?: Array<{
type: string
identifier: string
}>
}
}
function extractVolumeInfo(item: GoogleBooksVolumeItem): VolumeInfo {
const info = item.volumeInfo
const identifiers = info.industryIdentifiers ?? []
@@ -155,10 +129,6 @@ export const googleBooksVolumeSearchTool: ToolConfig<
transformResponse: async (response: Response) => {
const data = await response.json()
if (data.error) {
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
}
const items: GoogleBooksVolumeItem[] = data.items ?? []
const volumes = items.map(extractVolumeInfo)