Skip to content

Commit 6906a50

Browse files
authored
Add service catalog tool renderer (#573)
1 parent b1f1bd8 commit 6906a50

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, expect, test } from 'bun:test'
2+
3+
import { getGravityIndexDescription } from '../gravity-index'
4+
5+
describe('getGravityIndexDescription', () => {
6+
test('describes search queries', () => {
7+
expect(
8+
getGravityIndexDescription({
9+
action: 'search',
10+
query: 'transactional email for a Next.js app',
11+
}),
12+
).toBe('Searching transactional email for a Next.js app')
13+
})
14+
15+
test('describes browse category and keyword', () => {
16+
expect(
17+
getGravityIndexDescription({
18+
action: 'browse',
19+
category: 'Email',
20+
q: 'send',
21+
}),
22+
).toBe('Browsing Email for send')
23+
})
24+
25+
test('describes service detail lookups', () => {
26+
expect(
27+
getGravityIndexDescription({
28+
action: 'get_service',
29+
slug: 'sendgrid',
30+
}),
31+
).toBe('Getting sendgrid')
32+
})
33+
34+
test('describes completed integration reports', () => {
35+
expect(
36+
getGravityIndexDescription({
37+
action: 'report_integration',
38+
integrated_slug: 'sendgrid',
39+
}),
40+
).toBe('Reporting sendgrid integration')
41+
})
42+
43+
test('uses fallback text for unknown input', () => {
44+
expect(getGravityIndexDescription({ action: 'unknown' })).toBe(
45+
'Using service catalog',
46+
)
47+
expect(getGravityIndexDescription(null)).toBe('Using service catalog')
48+
})
49+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { SimpleToolCallItem } from './tool-call-item'
2+
import { defineToolComponent } from './types'
3+
4+
import type { ToolRenderConfig } from './types'
5+
6+
const asTrimmedString = (value: unknown): string =>
7+
typeof value === 'string' ? value.trim() : ''
8+
9+
export const getGravityIndexDescription = (input: unknown): string => {
10+
if (!input || typeof input !== 'object') {
11+
return 'Using service catalog'
12+
}
13+
14+
const params = input as Record<string, unknown>
15+
const action = asTrimmedString(params.action)
16+
17+
switch (action) {
18+
case 'search': {
19+
const query = asTrimmedString(params.query)
20+
return query ? `Searching ${query}` : 'Searching services'
21+
}
22+
case 'browse': {
23+
const category = asTrimmedString(params.category)
24+
const query = asTrimmedString(params.q)
25+
return ['Browsing', category || 'services', query ? `for ${query}` : '']
26+
.filter(Boolean)
27+
.join(' ')
28+
}
29+
case 'list_categories':
30+
return 'Listing service categories'
31+
case 'get_service': {
32+
const slug = asTrimmedString(params.slug)
33+
return slug ? `Getting ${slug}` : 'Getting service details'
34+
}
35+
case 'report_integration': {
36+
const slug = asTrimmedString(params.integrated_slug)
37+
return slug ? `Reporting ${slug} integration` : 'Reporting integration'
38+
}
39+
default:
40+
return 'Using service catalog'
41+
}
42+
}
43+
44+
/**
45+
* UI component for gravity_index.
46+
* Displays a one-line summary of what Gravity Index is searching or doing.
47+
*/
48+
export const GravityIndexComponent = defineToolComponent({
49+
toolName: 'gravity_index',
50+
51+
render(toolBlock): ToolRenderConfig {
52+
return {
53+
content: (
54+
<SimpleToolCallItem
55+
name="Service Catalog"
56+
description={getGravityIndexDescription(toolBlock.input)}
57+
/>
58+
),
59+
}
60+
},
61+
})

cli/src/components/tools/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ApplyPatchComponent } from './apply-patch'
22
import { CodeSearchComponent } from './code-search'
33
import { GlobComponent } from './glob'
4+
import { GravityIndexComponent } from './gravity-index'
45
import { ListDirectoryComponent } from './list-directory'
56
import { ReadDocsComponent } from './read-docs'
67
import { ReadFilesComponent } from './read-files'
@@ -31,6 +32,7 @@ const toolComponentRegistry = new Map<ToolName, ToolComponent>([
3132
[ApplyPatchComponent.toolName, ApplyPatchComponent],
3233
[CodeSearchComponent.toolName, CodeSearchComponent],
3334
[GlobComponent.toolName, GlobComponent],
35+
[GravityIndexComponent.toolName, GravityIndexComponent],
3436
[ListDirectoryComponent.toolName, ListDirectoryComponent],
3537
[RunTerminalCommandComponent.toolName, RunTerminalCommandComponent],
3638
[ReadDocsComponent.toolName, ReadDocsComponent],

0 commit comments

Comments
 (0)