Skip to content

Commit 7c1ebb8

Browse files
author
Josselin Liebe
committed
fix(capturekit): address review feedback
- Keep the two response mappers in extract_content.ts, their only caller - Document the CaptureKitIcon export - Read the operation from the mapper context so agent tools coerce the screenshot's numeric inputs too
1 parent a4961af commit 7c1ebb8

5 files changed

Lines changed: 33 additions & 32 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+
/** CaptureKit logo, as used by the CaptureKit block. */
1046310464
export function CaptureKitIcon(props: SVGProps<SVGSVGElement>) {
1046410465
return (
1046510466
<svg viewBox='-0.3 1.2 20.6 20.6' fill='none' xmlns='http://www.w3.org/2000/svg' {...props}>

‎apps/sim/blocks/blocks/capturekit.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,23 @@ export const CaptureKitBlock: BlockConfig = {
173173
],
174174
config: {
175175
tool: (params) => `capturekit_${params.operation}`,
176-
params: (params) => {
176+
params: (params, context) => {
177+
const operation = context?.operation ?? params.operation
177178
const result: Record<string, unknown> = {}
178-
if (params.operation === 'screenshot') {
179+
if (operation === 'screenshot') {
179180
result.viewportWidth = parseOptionalNumberInput(params.viewportWidth, 'Viewport Width', {
180181
integer: true,
181182
min: 1,
182183
})
183184
}
184-
if (params.operation === 'screenshot') {
185+
if (operation === 'screenshot') {
185186
result.viewportHeight = parseOptionalNumberInput(
186187
params.viewportHeight,
187188
'Viewport Height',
188189
{ integer: true, min: 1 }
189190
)
190191
}
191-
if (params.operation === 'screenshot') {
192+
if (operation === 'screenshot') {
192193
result.delay = parseOptionalNumberInput(params.delay, 'Delay', { min: 0 })
193194
}
194195
return result

‎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+
/** CaptureKit logo, as used by the CaptureKit block. */
1046310464
export function CaptureKitIcon(props: SVGProps<SVGSVGElement>) {
1046410465
return (
1046510466
<svg viewBox='-0.3 1.2 20.6 20.6' fill='none' xmlns='http://www.w3.org/2000/svg' {...props}>

‎apps/sim/tools/capturekit/extract_content.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
import { toStringOrNull } from '@sim/utils/coerce'
2-
import { toRecord } from '@sim/utils/object'
2+
import { toArray, toRecord, toRecordOrNull } from '@sim/utils/object'
33
import type {
44
CaptureKitExtractContentParams,
55
CaptureKitExtractContentResponse,
6+
CaptureKitPageLinks,
7+
CaptureKitPageMetadata,
68
} from '@/tools/capturekit/types'
79
import {
810
CAPTURE_KIT_PAGE_LINKS_OUTPUT_PROPERTIES,
911
CAPTURE_KIT_PAGE_METADATA_OUTPUT_PROPERTIES,
1012
} from '@/tools/capturekit/types'
11-
import { mapCaptureKitPageLinks, mapCaptureKitPageMetadata } from '@/tools/capturekit/utils'
1213
import type { ToolConfig } from '@/tools/types'
1314

15+
/** Reads a `CaptureKitPageMetadata` from an untyped CaptureKit API payload. */
16+
function mapCaptureKitPageMetadata(value: unknown): CaptureKitPageMetadata | null {
17+
const record = toRecordOrNull(value)
18+
if (!record) return null
19+
return {
20+
title: toStringOrNull(record.title),
21+
description: toStringOrNull(record.description),
22+
favicon: toStringOrNull(record.favicon),
23+
ogImage: toStringOrNull(record.ogImage),
24+
}
25+
}
26+
27+
/** Reads a `CaptureKitPageLinks` from an untyped CaptureKit API payload. */
28+
function mapCaptureKitPageLinks(value: unknown): CaptureKitPageLinks | null {
29+
const record = toRecordOrNull(value)
30+
if (!record) return null
31+
return {
32+
internal: toArray(record.internal).filter((item): item is string => typeof item === 'string'),
33+
external: toArray(record.external).filter((item): item is string => typeof item === 'string'),
34+
social: toArray(record.social).filter((item): item is string => typeof item === 'string'),
35+
}
36+
}
37+
1438
export const capturekitExtractContentTool: ToolConfig<
1539
CaptureKitExtractContentParams,
1640
CaptureKitExtractContentResponse

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)