u
This commit is contained in:
@@ -144,33 +144,40 @@ export function createSearchImagesTool({ googleAuthId }) {
|
||||
additionalProperties: false,
|
||||
required: ['query'],
|
||||
properties: {
|
||||
note: {
|
||||
type: ['string', 'null'],
|
||||
description: 'A note explaining what this image search is doing (or null). This note will be displayed to the user while executing.',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
description: 'Search query.',
|
||||
},
|
||||
count: {
|
||||
type: 'number',
|
||||
description: `Candidate count. Default ${DEFAULT_COUNT}, max ${MAX_COUNT}.`,
|
||||
type: ['number', 'null'],
|
||||
description: `Candidate count or null. Default ${DEFAULT_COUNT}, max ${MAX_COUNT}.`,
|
||||
},
|
||||
gl: {
|
||||
type: 'string',
|
||||
description: 'Country code. Default "de".',
|
||||
type: ['string', 'null'],
|
||||
description: 'Country code or null. Default "de".',
|
||||
},
|
||||
hl: {
|
||||
type: 'string',
|
||||
description: 'Language code. Default "de".',
|
||||
type: ['string', 'null'],
|
||||
description: 'Language code or null. Default "de".',
|
||||
},
|
||||
},
|
||||
},
|
||||
invoke: async ({ query, count = DEFAULT_COUNT, gl = 'de', hl = 'de' } = {}) => {
|
||||
invoke: async ({ query, count = DEFAULT_COUNT, gl = 'de', hl = 'de', note } = {}) => {
|
||||
const term = typeof query === 'string' ? query.trim() : '';
|
||||
if (!term) {
|
||||
throw new ToolError('search_images requires a non-empty "query" (e.g. " Mineralwasser Flasche Glas ").');
|
||||
}
|
||||
if (!Number.isInteger(count) || count < 1) {
|
||||
const resolvedCount = count != null ? Number(count) : DEFAULT_COUNT;
|
||||
if (!Number.isInteger(resolvedCount) || resolvedCount < 1) {
|
||||
throw new ToolError(`"count" must be a positive integer (received ${count}).`);
|
||||
}
|
||||
const wanted = Math.min(count, MAX_COUNT);
|
||||
const wanted = Math.min(resolvedCount, MAX_COUNT);
|
||||
const resolvedGl = gl || 'de';
|
||||
const resolvedHl = hl || 'de';
|
||||
|
||||
let apiKey = null;
|
||||
try {
|
||||
@@ -187,7 +194,7 @@ export function createSearchImagesTool({ googleAuthId }) {
|
||||
);
|
||||
}
|
||||
|
||||
const raw = await serperImageSearch(term, apiKey, { gl, hl });
|
||||
const raw = await serperImageSearch(term, apiKey, { gl: resolvedGl, hl: resolvedHl });
|
||||
if (raw.length === 0) {
|
||||
return {
|
||||
query: term,
|
||||
|
||||
Reference in New Issue
Block a user