mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-12 23:45:07 -05:00
Remove redundant error handling, move volume item to types file
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user