Skip to content

Commit 5584a31

Browse files
committed
fix(copilot): show custom block names in read tool rows
1 parent 472532e commit 5584a31

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

apps/sim/lib/copilot/tools/client/read-block.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import { describe, expect, it, vi } from 'vitest'
55
import { getReadTargetBlock } from '@/lib/copilot/tools/client/read-block'
66

77
const gmailBlock = { type: 'gmail_v2', name: 'Gmail', icon: () => null }
8+
const customBlock = {
9+
type: 'custom_block_invoice_parser',
10+
name: 'Invoice Parser',
11+
icon: () => null,
12+
}
813

914
vi.mock('@/blocks/registry', () => ({
10-
getBlock: vi.fn((type: string) => (type === 'gmail_v2' ? gmailBlock : undefined)),
15+
getBlock: vi.fn((type: string) => {
16+
if (type === 'gmail_v2') return gmailBlock
17+
if (type === 'custom_block_invoice_parser') return customBlock
18+
return undefined
19+
}),
1120
getLatestBlock: vi.fn((baseType: string) => (baseType === 'gmail' ? gmailBlock : undefined)),
1221
}))
1322

@@ -21,6 +30,12 @@ describe('getReadTargetBlock', () => {
2130
expect(getReadTargetBlock('components/integrations/gmail')?.name).toBe('Gmail')
2231
})
2332

33+
it('resolves an organization custom-block read to its block', () => {
34+
expect(
35+
getReadTargetBlock('organization/custom-blocks/custom_block_invoice_parser.json')?.name
36+
).toBe('Invoice Parser')
37+
})
38+
2439
it('returns undefined for unknown blocks and non-component paths', () => {
2540
expect(getReadTargetBlock('components/blocks/unknown_block.json')).toBeUndefined()
2641
expect(getReadTargetBlock('workflows/My Workflow/meta.json')).toBeUndefined()

apps/sim/lib/copilot/tools/client/read-block.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ import { getBlock, getLatestBlock } from '@/blocks/registry'
22
import type { BlockConfig } from '@/blocks/types'
33

44
/**
5-
* Resolves the block a copilot `read` call targets when the path is a
6-
* component schema — `components/blocks/{type}.json` or
7-
* `components/integrations/{service}/{operation}.json` — so tool rows can show
8-
* the block's display name and brand icon instead of the raw type id
9-
* (e.g. "Gmail" instead of `gmail_v2`). Returns undefined for every other
10-
* path, leaving the generic read-target labeling untouched.
5+
* Resolves the block a copilot `read` call targets when the path references a
6+
* component schema or organization custom block, so tool rows can show the
7+
* block's display name and brand icon instead of its raw type id. Returns
8+
* undefined for every other path, leaving generic read-target labeling
9+
* untouched.
1110
*/
1211
export function getReadTargetBlock(path: string | undefined): BlockConfig | undefined {
1312
if (!path) return undefined
1413
const segments = path.trim().split('/').filter(Boolean)
14+
15+
if (segments[0] === 'organization' && segments[1] === 'custom-blocks' && segments.length === 3) {
16+
return getBlock(segments[2].replace(/\.json$/, ''))
17+
}
18+
1519
if (segments[0] !== 'components' || segments.length < 3) return undefined
1620
if (segments[1] === 'blocks' && segments.length === 3) {
1721
return getBlock(segments[2].replace(/\.json$/, ''))

apps/sim/lib/copilot/tools/client/store-utils.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@ import { resolveToolDisplay } from './store-utils'
88
import { ClientToolCallState } from './tool-call-state'
99

1010
const gmailBlock = { type: 'gmail_v2', name: 'Gmail', icon: () => null }
11+
const customBlock = {
12+
type: 'custom_block_invoice_parser',
13+
name: 'Invoice Parser',
14+
icon: () => null,
15+
}
1116

1217
vi.mock('@/blocks/registry', () => ({
13-
getBlock: vi.fn((type: string) => (type === 'gmail_v2' ? gmailBlock : undefined)),
18+
getBlock: vi.fn((type: string) => {
19+
if (type === 'gmail_v2') return gmailBlock
20+
if (type === 'custom_block_invoice_parser') return customBlock
21+
return undefined
22+
}),
1423
getLatestBlock: vi.fn((baseType: string) => (baseType === 'gmail' ? gmailBlock : undefined)),
1524
}))
1625

@@ -180,7 +189,7 @@ describe('resolveToolDisplay', () => {
180189
).toBe('Read style details for deck.pptx')
181190
})
182191

183-
it('shows the block display name for block and integration schema reads', () => {
192+
it('shows the block display name for block, integration, and custom-block reads', () => {
184193
expect(
185194
resolveToolDisplay(ReadTool.id, ClientToolCallState.success, {
186195
path: 'components/blocks/gmail_v2.json',
@@ -198,6 +207,12 @@ describe('resolveToolDisplay', () => {
198207
path: 'components/blocks/unknown_block.json',
199208
})?.text
200209
).toBe('Read Unknown block')
210+
211+
expect(
212+
resolveToolDisplay(ReadTool.id, ClientToolCallState.success, {
213+
path: 'organization/custom-blocks/custom_block_invoice_parser.json',
214+
})?.text
215+
).toBe('Read Invoice Parser')
201216
})
202217

203218
it('humanizes internal VFS resource identifiers', () => {

0 commit comments

Comments
 (0)