Skip to content

Commit 08564a0

Browse files
author
Josselin Liebe
committed
fix(autom): address review feedback
- Keep response mappers with a single caller in that tool's file - Document the AutomIcon export - Read the operation from the mapper context so agent tools coerce Page and Results per Page too
1 parent 55f8296 commit 08564a0

8 files changed

Lines changed: 66 additions & 68 deletions

File tree

‎apps/docs/components/icons.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10460,6 +10460,7 @@ export function PlaneIcon(props: SVGProps<SVGSVGElement>) {
1046010460
)
1046110461
}
1046210462

10463+
/** Autom logo, as used by the Autom block. */
1046310464
export function AutomIcon(props: SVGProps<SVGSVGElement>) {
1046410465
return (
1046510466
<svg viewBox='-1 1 22 22' fill='none' xmlns='http://www.w3.org/2000/svg' {...props}>

‎apps/sim/blocks/blocks/autom.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export const AutomBlock: BlockConfig = {
173173
],
174174
config: {
175175
tool: (params) => `autom_${params.operation}`,
176-
params: (params) => {
176+
params: (params, context) => {
177+
const operation = context?.operation ?? params.operation
177178
const result: Record<string, unknown> = {}
178179
if (
179180
[
@@ -184,11 +185,11 @@ export const AutomBlock: BlockConfig = {
184185
'duckduckgo_search',
185186
'yahoo_search',
186187
'brave_search',
187-
].includes(params.operation)
188+
].includes(operation)
188189
) {
189190
result.page = parseOptionalNumberInput(params.page, 'Page', { integer: true, min: 1 })
190191
}
191-
if (['google_search', 'google_news', 'bing_search'].includes(params.operation)) {
192+
if (['google_search', 'google_news', 'bing_search'].includes(operation)) {
192193
result.numResults = parseOptionalNumberInput(params.numResults, 'Results per Page', {
193194
integer: true,
194195
min: 1,

‎apps/sim/components/icons.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10460,6 +10460,7 @@ export function PlaneIcon(props: SVGProps<SVGSVGElement>) {
1046010460
)
1046110461
}
1046210462

10463+
/** Autom logo, as used by the Autom block. */
1046310464
export function AutomIcon(props: SVGProps<SVGSVGElement>) {
1046410465
return (
1046510466
<svg viewBox='-1 1 22 22' fill='none' xmlns='http://www.w3.org/2000/svg' {...props}>

‎apps/sim/tools/autom/find_google_locations.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import { toArray } from '@sim/utils/object'
1+
import { toNumberOrNull, toStringOrNull } from '@sim/utils/coerce'
2+
import { toArray, toRecordOrNull } from '@sim/utils/object'
23
import type {
34
AutomFindGoogleLocationsParams,
45
AutomFindGoogleLocationsResponse,
56
AutomLocation,
67
} from '@/tools/autom/types'
78
import { AUTOM_LOCATION_OUTPUT_PROPERTIES } from '@/tools/autom/types'
8-
import { mapAutomLocation } from '@/tools/autom/utils'
99
import type { ToolConfig } from '@/tools/types'
1010

11+
/** Reads a `AutomLocation` from an untyped Autom API payload. */
12+
function mapAutomLocation(value: unknown): AutomLocation | null {
13+
const record = toRecordOrNull(value)
14+
if (!record) return null
15+
return {
16+
canonicalName: toStringOrNull(record.canonical_name),
17+
name: toStringOrNull(record.name),
18+
targetType: toStringOrNull(record.target_type),
19+
countryCode: toStringOrNull(record.country_code),
20+
reach: toNumberOrNull(record.reach),
21+
googleId: toNumberOrNull(record.google_id),
22+
}
23+
}
24+
1125
export const automFindGoogleLocationsTool: ToolConfig<
1226
AutomFindGoogleLocationsParams,
1327
AutomFindGoogleLocationsResponse

‎apps/sim/tools/autom/google_autocomplete.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
import { toArray, toRecord } from '@sim/utils/object'
1+
import { toStringOrNull } from '@sim/utils/coerce'
2+
import { toArray, toRecord, toRecordOrNull } from '@sim/utils/object'
23
import type {
34
AutomGoogleAutocompleteParams,
45
AutomGoogleAutocompleteResponse,
56
AutomSuggestion,
67
} from '@/tools/autom/types'
78
import { AUTOM_SUGGESTION_OUTPUT_PROPERTIES } from '@/tools/autom/types'
8-
import { mapAutomSuggestion } from '@/tools/autom/utils'
99
import type { ToolConfig } from '@/tools/types'
1010

11+
/** Reads a `AutomSuggestion` from an untyped Autom API payload. */
12+
function mapAutomSuggestion(value: unknown): AutomSuggestion | null {
13+
const record = toRecordOrNull(value)
14+
if (!record) return null
15+
return {
16+
value: toStringOrNull(record.value),
17+
}
18+
}
19+
1120
export const automGoogleAutocompleteTool: ToolConfig<
1221
AutomGoogleAutocompleteParams,
1322
AutomGoogleAutocompleteResponse

‎apps/sim/tools/autom/google_maps.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
import { toArray } from '@sim/utils/object'
1+
import { toNumberOrNull, toStringOrNull } from '@sim/utils/coerce'
2+
import { toArray, toRecordOrNull } from '@sim/utils/object'
23
import type {
34
AutomGoogleMapsParams,
45
AutomGoogleMapsResponse,
56
AutomPlace,
67
} from '@/tools/autom/types'
78
import { AUTOM_PLACE_OUTPUT_PROPERTIES } from '@/tools/autom/types'
8-
import { mapAutomPlace } from '@/tools/autom/utils'
99
import type { ToolConfig } from '@/tools/types'
1010

11+
/** Reads a `AutomPlace` from an untyped Autom API payload. */
12+
function mapAutomPlace(value: unknown): AutomPlace | null {
13+
const record = toRecordOrNull(value)
14+
if (!record) return null
15+
return {
16+
title: toStringOrNull(record.title),
17+
address: toStringOrNull(record.address),
18+
website: toStringOrNull(record.website),
19+
phoneNumber: toStringOrNull(record.phone_number),
20+
latitude: toNumberOrNull(record.lat),
21+
longitude: toNumberOrNull(record.long),
22+
placeId: toStringOrNull(record.fid),
23+
}
24+
}
25+
1126
export const automGoogleMapsTool: ToolConfig<AutomGoogleMapsParams, AutomGoogleMapsResponse> = {
1227
id: 'autom_google_maps',
1328
name: 'Autom Google Maps',

‎apps/sim/tools/autom/google_search.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
import { toBooleanOrNull, toNumberOrNull } from '@sim/utils/coerce'
2-
import { toArray, toRecord } from '@sim/utils/object'
1+
import { toBooleanOrNull, toNumberOrNull, toStringOrNull } from '@sim/utils/coerce'
2+
import { toArray, toRecord, toRecordOrNull } from '@sim/utils/object'
33
import type {
44
AutomGoogleSearchParams,
55
AutomGoogleSearchResponse,
6+
AutomKnowledgeGraph,
67
AutomSearchResult,
78
} from '@/tools/autom/types'
89
import {
910
AUTOM_KNOWLEDGE_GRAPH_OUTPUT_PROPERTIES,
1011
AUTOM_SEARCH_RESULT_OUTPUT_PROPERTIES,
1112
} from '@/tools/autom/types'
12-
import { mapAutomKnowledgeGraph, mapAutomSearchResult } from '@/tools/autom/utils'
13+
import { mapAutomSearchResult } from '@/tools/autom/utils'
1314
import type { ToolConfig } from '@/tools/types'
1415

16+
/** Reads a `AutomKnowledgeGraph` from an untyped Autom API payload. */
17+
function mapAutomKnowledgeGraph(value: unknown): AutomKnowledgeGraph | null {
18+
const record = toRecordOrNull(value)
19+
if (!record) return null
20+
return {
21+
title: toStringOrNull(record.title),
22+
type: toStringOrNull(record.type),
23+
website: toStringOrNull(record.website),
24+
}
25+
}
26+
1527
export const automGoogleSearchTool: ToolConfig<AutomGoogleSearchParams, AutomGoogleSearchResponse> =
1628
{
1729
id: 'autom_google_search',

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

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { toNumberOrNull, toStringOrNull } from '@sim/utils/coerce'
22
import { toRecordOrNull } from '@sim/utils/object'
3-
import type {
4-
AutomKnowledgeGraph,
5-
AutomLocation,
6-
AutomPlace,
7-
AutomSearchResult,
8-
AutomSuggestion,
9-
} from '@/tools/autom/types'
3+
import type { AutomSearchResult } from '@/tools/autom/types'
104

115
/** Reads a `AutomSearchResult` from an untyped Autom API payload. */
126
export function mapAutomSearchResult(value: unknown): AutomSearchResult | null {
@@ -23,52 +17,3 @@ export function mapAutomSearchResult(value: unknown): AutomSearchResult | null {
2317
date: toStringOrNull(record.date),
2418
}
2519
}
26-
27-
/** Reads a `AutomKnowledgeGraph` from an untyped Autom API payload. */
28-
export function mapAutomKnowledgeGraph(value: unknown): AutomKnowledgeGraph | null {
29-
const record = toRecordOrNull(value)
30-
if (!record) return null
31-
return {
32-
title: toStringOrNull(record.title),
33-
type: toStringOrNull(record.type),
34-
website: toStringOrNull(record.website),
35-
}
36-
}
37-
38-
/** Reads a `AutomPlace` from an untyped Autom API payload. */
39-
export function mapAutomPlace(value: unknown): AutomPlace | null {
40-
const record = toRecordOrNull(value)
41-
if (!record) return null
42-
return {
43-
title: toStringOrNull(record.title),
44-
address: toStringOrNull(record.address),
45-
website: toStringOrNull(record.website),
46-
phoneNumber: toStringOrNull(record.phone_number),
47-
latitude: toNumberOrNull(record.lat),
48-
longitude: toNumberOrNull(record.long),
49-
placeId: toStringOrNull(record.fid),
50-
}
51-
}
52-
53-
/** Reads a `AutomSuggestion` from an untyped Autom API payload. */
54-
export function mapAutomSuggestion(value: unknown): AutomSuggestion | null {
55-
const record = toRecordOrNull(value)
56-
if (!record) return null
57-
return {
58-
value: toStringOrNull(record.value),
59-
}
60-
}
61-
62-
/** Reads a `AutomLocation` from an untyped Autom API payload. */
63-
export function mapAutomLocation(value: unknown): AutomLocation | null {
64-
const record = toRecordOrNull(value)
65-
if (!record) return null
66-
return {
67-
canonicalName: toStringOrNull(record.canonical_name),
68-
name: toStringOrNull(record.name),
69-
targetType: toStringOrNull(record.target_type),
70-
countryCode: toStringOrNull(record.country_code),
71-
reach: toNumberOrNull(record.reach),
72-
googleId: toNumberOrNull(record.google_id),
73-
}
74-
}

0 commit comments

Comments
 (0)