Skip to content

Commit 0d21e40

Browse files
committed
fix(youcom): validate per-endpoint values in tools, live-verified fields
1 parent b17b3c6 commit 0d21e40

6 files changed

Lines changed: 76 additions & 29 deletions

File tree

‎apps/sim/blocks/blocks/youcom.ts‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ const ANSWER_LANGUAGE_OPTIONS = [
102102
{ label: 'Vietnamese', id: 'VI' },
103103
]
104104

105-
const ANSWER_LANGUAGE_IDS = new Set(
106-
ANSWER_LANGUAGE_OPTIONS.map((option) => option.id).filter((id) => id !== '')
107-
)
108-
109-
const FINANCE_RESEARCH_EFFORTS = new Set(['deep', 'exhaustive'])
110-
111105
const SEARCH_ONLY_LANGUAGES = [
112106
{ label: 'Chinese (Simplified)', id: 'ZH-HANS' },
113107
{ label: 'Chinese (Traditional)', id: 'ZH-HANT' },
@@ -510,25 +504,10 @@ export const YouComBlock: BlockConfig = {
510504
const maxAge = toOptionalNumber(params.maxAge)
511505
if (maxAge !== undefined) result.maxAge = maxAge
512506

513-
// Operations share field ids, so a value set under one operation can carry over to
514-
// another. Drop values the active endpoint rejects so it falls back to its default.
515-
if (
516-
params.operation === ANSWER &&
517-
params.language &&
518-
!ANSWER_LANGUAGE_IDS.has(params.language)
519-
) {
520-
result.language = undefined
521-
}
522-
const isFinanceEffort = FINANCE_RESEARCH_EFFORTS.has(params.researchEffort)
523-
if (params.operation === FINANCE_RESEARCH && params.researchEffort && !isFinanceEffort) {
524-
result.researchEffort = undefined
525-
}
526-
const effort = 'researchEffort' in result ? result.researchEffort : params.researchEffort
527-
const isSyncResearch =
528-
params.operation === FINANCE_RESEARCH ||
529-
(params.operation === RESEARCH && params.background !== true && effort !== 'frontier')
530-
if (isSyncResearch && effort === 'exhaustive')
507+
// Keyed on effort, not operation: Agent tool rows store the operation outside these params
508+
if (params.researchEffort === 'exhaustive' && params.background !== true) {
531509
result.timeout = EXHAUSTIVE_REQUEST_TIMEOUT_MS
510+
}
532511
return result
533512
},
534513
},

‎apps/sim/tools/generated/tool-outputs.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/youcom/answer.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { toArray, toRecordOrNull } from '@sim/utils/object'
33
import type { ToolConfig } from '@/tools/types'
44
import type { YouComAnswerParams, YouComAnswerResponse } from '@/tools/youcom/types'
55
import {
6+
ANSWER_LANGUAGES,
67
buildDomainFilters,
78
YOUCOM_API_BASE_URL,
89
youComApiKeyParam,
@@ -84,7 +85,7 @@ export const youComAnswerTool: ToolConfig<YouComAnswerParams, YouComAnswerRespon
8485
}
8586
if (params.freshness) body.freshness = params.freshness.trim()
8687
if (params.country) body.country = params.country
87-
if (params.language) body.language = params.language
88+
if (params.language && ANSWER_LANGUAGES.has(params.language)) body.language = params.language
8889
if (params.safesearch) body.safesearch = params.safesearch
8990
return body
9091
},

‎apps/sim/tools/youcom/finance_research.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { toRecordOrNull } from '@sim/utils/object'
1+
import { toArray, toRecordOrNull } from '@sim/utils/object'
22
import type { ToolConfig } from '@/tools/types'
33
import type {
44
YouComFinanceResearchParams,
55
YouComFinanceResearchResponse,
66
} from '@/tools/youcom/types'
77
import {
8+
FINANCE_RESEARCH_EFFORTS,
89
mapResearchSources,
910
RESEARCH_SOURCES_OUTPUT,
11+
RESEARCH_WARNINGS_OUTPUT,
1012
YOUCOM_API_BASE_URL,
1113
youComApiKeyParam,
1214
youComHeaders,
@@ -48,7 +50,9 @@ export const youComFinanceResearchTool: ToolConfig<
4850
headers: youComHeaders,
4951
body: (params) => {
5052
const body: Record<string, unknown> = { input: params.input }
51-
if (params.researchEffort) body.research_effort = params.researchEffort
53+
if (params.researchEffort && FINANCE_RESEARCH_EFFORTS.has(params.researchEffort)) {
54+
body.research_effort = params.researchEffort
55+
}
5256
return body
5357
},
5458
},
@@ -63,6 +67,7 @@ export const youComFinanceResearchTool: ToolConfig<
6367
content: String(output.content ?? ''),
6468
contentType: String(output.content_type ?? 'text'),
6569
sources: mapResearchSources(output.sources),
70+
warnings: toArray(data.warnings).map(String),
6671
},
6772
}
6873
},
@@ -74,5 +79,6 @@ export const youComFinanceResearchTool: ToolConfig<
7479
},
7580
contentType: { type: 'string', description: 'Format of content (text)' },
7681
sources: RESEARCH_SOURCES_OUTPUT,
82+
warnings: RESEARCH_WARNINGS_OUTPUT,
7783
},
7884
}

‎apps/sim/tools/youcom/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export interface YouComFinanceResearchResponse extends ToolResponse {
181181
content: string
182182
contentType: string
183183
sources: YouComResearchSource[]
184+
warnings: string[]
184185
}
185186
}
186187

‎apps/sim/tools/youcom/utils.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,62 @@ import type { YouComDomainFilterParams, YouComResearchSource } from '@/tools/you
66
export const YOUCOM_INDEX_BASE_URL = 'https://ydc-index.io/v1'
77
export const YOUCOM_API_BASE_URL = 'https://api.you.com/v1'
88

9+
/**
10+
* Languages the Answer endpoint accepts. Search also accepts ZH-HANS, ZH-HANT, JA, PT-BR, and
11+
* PT-PT; Answer rejects those, so a value carried over from Search is dropped instead of sent.
12+
*/
13+
export const ANSWER_LANGUAGES: ReadonlySet<string> = new Set([
14+
'AR',
15+
'EU',
16+
'BN',
17+
'BG',
18+
'CA',
19+
'HR',
20+
'CS',
21+
'DA',
22+
'NL',
23+
'EN',
24+
'EN-GB',
25+
'ET',
26+
'FI',
27+
'FR',
28+
'GL',
29+
'DE',
30+
'EL',
31+
'GU',
32+
'HE',
33+
'HI',
34+
'HU',
35+
'IS',
36+
'IT',
37+
'KN',
38+
'KO',
39+
'LV',
40+
'LT',
41+
'MS',
42+
'ML',
43+
'MR',
44+
'NB',
45+
'PL',
46+
'PA',
47+
'RO',
48+
'RU',
49+
'SR',
50+
'SK',
51+
'SL',
52+
'ES',
53+
'SV',
54+
'TA',
55+
'TE',
56+
'TH',
57+
'TR',
58+
'UK',
59+
'VI',
60+
])
61+
62+
/** Effort levels the Finance Research endpoint accepts; others fall back to its `deep` default. */
63+
export const FINANCE_RESEARCH_EFFORTS: ReadonlySet<string> = new Set(['deep', 'exhaustive'])
64+
965
export const youComApiKeyParam = {
1066
type: 'string',
1167
required: true,
@@ -40,13 +96,17 @@ export function parseList(value: unknown): string[] | undefined {
4096

4197
/**
4298
* Builds the `include_domains` / `exclude_domains` / `boost_domains` slice. You.com rejects
43-
* `include_domains` combined with either of the others with a 422, which is surfaced as-is.
99+
* `include_domains` combined with either of the others with a bare "invalid request parameter(s)"
100+
* 422, so the combination is rejected here with an actionable message instead.
44101
*/
45102
export function buildDomainFilters(params: YouComDomainFilterParams): Record<string, string[]> {
46103
const filters: Record<string, string[]> = {}
47104
const include = parseList(params.includeDomains)
48105
const exclude = parseList(params.excludeDomains)
49106
const boost = parseList(params.boostDomains)
107+
if (include && (exclude || boost)) {
108+
throw new Error('Include domains cannot be combined with exclude or boost domains')
109+
}
50110
if (include) filters.include_domains = include
51111
if (exclude) filters.exclude_domains = exclude
52112
if (boost) filters.boost_domains = boost

0 commit comments

Comments
 (0)