|
| 1 | +import { GoogleBooksIcon } from '@/components/icons' |
| 2 | +import type { BlockConfig } from '@/blocks/types' |
| 3 | + |
| 4 | +export const GoogleBooksBlock: BlockConfig = { |
| 5 | + type: 'google_books', |
| 6 | + name: 'Google Books', |
| 7 | + description: 'Search and retrieve book information', |
| 8 | + longDescription: |
| 9 | + 'Search for books using the Google Books API. Find volumes by title, author, ISBN, or keywords, and retrieve detailed information about specific books including descriptions, ratings, and publication details.', |
| 10 | + docsLink: 'https://docs.sim.ai/tools/google_books', |
| 11 | + category: 'tools', |
| 12 | + bgColor: '#E0E0E0', |
| 13 | + icon: GoogleBooksIcon, |
| 14 | + |
| 15 | + subBlocks: [ |
| 16 | + { |
| 17 | + id: 'operation', |
| 18 | + title: 'Operation', |
| 19 | + type: 'dropdown', |
| 20 | + options: [ |
| 21 | + { label: 'Search Volumes', id: 'volume_search' }, |
| 22 | + { label: 'Get Volume Details', id: 'volume_details' }, |
| 23 | + ], |
| 24 | + value: () => 'volume_search', |
| 25 | + }, |
| 26 | + { |
| 27 | + id: 'apiKey', |
| 28 | + title: 'API Key', |
| 29 | + type: 'short-input', |
| 30 | + password: true, |
| 31 | + placeholder: 'Enter your Google Books API key', |
| 32 | + required: true, |
| 33 | + }, |
| 34 | + { |
| 35 | + id: 'query', |
| 36 | + title: 'Search Query', |
| 37 | + type: 'short-input', |
| 38 | + placeholder: 'e.g., intitle:harry potter inauthor:rowling', |
| 39 | + condition: { field: 'operation', value: 'volume_search' }, |
| 40 | + required: { field: 'operation', value: 'volume_search' }, |
| 41 | + }, |
| 42 | + { |
| 43 | + id: 'filter', |
| 44 | + title: 'Filter', |
| 45 | + type: 'dropdown', |
| 46 | + options: [ |
| 47 | + { label: 'None', id: '' }, |
| 48 | + { label: 'Partial Preview', id: 'partial' }, |
| 49 | + { label: 'Full Preview', id: 'full' }, |
| 50 | + { label: 'Free eBooks', id: 'free-ebooks' }, |
| 51 | + { label: 'Paid eBooks', id: 'paid-ebooks' }, |
| 52 | + { label: 'All eBooks', id: 'ebooks' }, |
| 53 | + ], |
| 54 | + condition: { field: 'operation', value: 'volume_search' }, |
| 55 | + mode: 'advanced', |
| 56 | + }, |
| 57 | + { |
| 58 | + id: 'printType', |
| 59 | + title: 'Print Type', |
| 60 | + type: 'dropdown', |
| 61 | + options: [ |
| 62 | + { label: 'All', id: 'all' }, |
| 63 | + { label: 'Books', id: 'books' }, |
| 64 | + { label: 'Magazines', id: 'magazines' }, |
| 65 | + ], |
| 66 | + value: () => 'all', |
| 67 | + condition: { field: 'operation', value: 'volume_search' }, |
| 68 | + mode: 'advanced', |
| 69 | + }, |
| 70 | + { |
| 71 | + id: 'orderBy', |
| 72 | + title: 'Order By', |
| 73 | + type: 'dropdown', |
| 74 | + options: [ |
| 75 | + { label: 'Relevance', id: 'relevance' }, |
| 76 | + { label: 'Newest', id: 'newest' }, |
| 77 | + ], |
| 78 | + value: () => 'relevance', |
| 79 | + condition: { field: 'operation', value: 'volume_search' }, |
| 80 | + mode: 'advanced', |
| 81 | + }, |
| 82 | + { |
| 83 | + id: 'maxResults', |
| 84 | + title: 'Max Results', |
| 85 | + type: 'short-input', |
| 86 | + placeholder: 'Number of results (1-40)', |
| 87 | + condition: { field: 'operation', value: 'volume_search' }, |
| 88 | + mode: 'advanced', |
| 89 | + }, |
| 90 | + { |
| 91 | + id: 'startIndex', |
| 92 | + title: 'Start Index', |
| 93 | + type: 'short-input', |
| 94 | + placeholder: 'Starting index for pagination', |
| 95 | + condition: { field: 'operation', value: 'volume_search' }, |
| 96 | + mode: 'advanced', |
| 97 | + }, |
| 98 | + { |
| 99 | + id: 'langRestrict', |
| 100 | + title: 'Language', |
| 101 | + type: 'short-input', |
| 102 | + placeholder: 'ISO 639-1 code (e.g., en, es, fr)', |
| 103 | + condition: { field: 'operation', value: 'volume_search' }, |
| 104 | + mode: 'advanced', |
| 105 | + }, |
| 106 | + { |
| 107 | + id: 'volumeId', |
| 108 | + title: 'Volume ID', |
| 109 | + type: 'short-input', |
| 110 | + placeholder: 'Google Books volume ID', |
| 111 | + condition: { field: 'operation', value: 'volume_details' }, |
| 112 | + required: { field: 'operation', value: 'volume_details' }, |
| 113 | + }, |
| 114 | + { |
| 115 | + id: 'projection', |
| 116 | + title: 'Projection', |
| 117 | + type: 'dropdown', |
| 118 | + options: [ |
| 119 | + { label: 'Full', id: 'full' }, |
| 120 | + { label: 'Lite', id: 'lite' }, |
| 121 | + ], |
| 122 | + value: () => 'full', |
| 123 | + mode: 'advanced', |
| 124 | + }, |
| 125 | + ], |
| 126 | + |
| 127 | + tools: { |
| 128 | + access: ['google_books_volume_search', 'google_books_volume_details'], |
| 129 | + config: { |
| 130 | + tool: (params) => `google_books_${params.operation}`, |
| 131 | + params: (params) => { |
| 132 | + const { operation, ...rest } = params |
| 133 | + |
| 134 | + let maxResults: number | undefined |
| 135 | + if (params.maxResults) { |
| 136 | + maxResults = Number.parseInt(params.maxResults, 10) |
| 137 | + if (Number.isNaN(maxResults)) { |
| 138 | + maxResults = undefined |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + let startIndex: number | undefined |
| 143 | + if (params.startIndex) { |
| 144 | + startIndex = Number.parseInt(params.startIndex, 10) |
| 145 | + if (Number.isNaN(startIndex)) { |
| 146 | + startIndex = undefined |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + return { |
| 151 | + ...rest, |
| 152 | + maxResults, |
| 153 | + startIndex, |
| 154 | + filter: params.filter || undefined, |
| 155 | + printType: params.printType || undefined, |
| 156 | + orderBy: params.orderBy || undefined, |
| 157 | + projection: params.projection || undefined, |
| 158 | + } |
| 159 | + }, |
| 160 | + }, |
| 161 | + }, |
| 162 | + |
| 163 | + inputs: { |
| 164 | + operation: { type: 'string', description: 'Operation to perform' }, |
| 165 | + apiKey: { type: 'string', description: 'Google Books API key' }, |
| 166 | + query: { type: 'string', description: 'Search query' }, |
| 167 | + filter: { type: 'string', description: 'Filter by availability' }, |
| 168 | + printType: { type: 'string', description: 'Print type filter' }, |
| 169 | + orderBy: { type: 'string', description: 'Sort order' }, |
| 170 | + maxResults: { type: 'string', description: 'Maximum number of results' }, |
| 171 | + startIndex: { type: 'string', description: 'Starting index for pagination' }, |
| 172 | + langRestrict: { type: 'string', description: 'Language restriction' }, |
| 173 | + volumeId: { type: 'string', description: 'Volume ID for details' }, |
| 174 | + projection: { type: 'string', description: 'Projection level' }, |
| 175 | + }, |
| 176 | + |
| 177 | + outputs: { |
| 178 | + totalItems: { type: 'number', description: 'Total number of matching results' }, |
| 179 | + volumes: { type: 'json', description: 'List of matching volumes' }, |
| 180 | + id: { type: 'string', description: 'Volume ID' }, |
| 181 | + title: { type: 'string', description: 'Book title' }, |
| 182 | + subtitle: { type: 'string', description: 'Book subtitle' }, |
| 183 | + authors: { type: 'json', description: 'List of authors' }, |
| 184 | + publisher: { type: 'string', description: 'Publisher name' }, |
| 185 | + publishedDate: { type: 'string', description: 'Publication date' }, |
| 186 | + description: { type: 'string', description: 'Book description' }, |
| 187 | + pageCount: { type: 'number', description: 'Number of pages' }, |
| 188 | + categories: { type: 'json', description: 'Book categories' }, |
| 189 | + averageRating: { type: 'number', description: 'Average rating (1-5)' }, |
| 190 | + ratingsCount: { type: 'number', description: 'Number of ratings' }, |
| 191 | + language: { type: 'string', description: 'Language code' }, |
| 192 | + previewLink: { type: 'string', description: 'Link to preview on Google Books' }, |
| 193 | + infoLink: { type: 'string', description: 'Link to info page' }, |
| 194 | + thumbnailUrl: { type: 'string', description: 'Book cover thumbnail URL' }, |
| 195 | + isbn10: { type: 'string', description: 'ISBN-10 identifier' }, |
| 196 | + isbn13: { type: 'string', description: 'ISBN-13 identifier' }, |
| 197 | + }, |
| 198 | +} |
0 commit comments