Skip to content

Commit c24f0cf

Browse files
committed
Add a generic fallback block
1 parent 961bac7 commit c24f0cf

11 files changed

Lines changed: 149 additions & 147 deletions

File tree

runtime/ai/developer_agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ This may not relate to the user's task, but for context, the project's default O
161161
{{ if .default_olap_readwrite }} The default OLAP is in readwrite mode, so you can use it in models if you want.
162162
{{ else }} The default OLAP is in read-only mode, so you cannot create models in it. {{ end }}
163163
164-
Call "navigate" tool for the main file created/edited in the conversation. Use type "file" and pass the written file path.
164+
Call "navigate" tool for the main file created/edited in the conversation. Use kind "file" and pass the written file path.
165165
Prefer dashboard or metrics view files over other files.
166166
167167
Task: {{ .prompt }}

runtime/ai/navigate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ type NavigateArgs struct {
2121
Name string `json:"name" jsonschema:"The name of the item to navigate to."`
2222
}
2323

24-
type NavigateResult struct {
25-
}
24+
type NavigateResult struct {}
2625

2726
func (t *Navigate) Spec() *mcp.Tool {
2827
return &mcp.Tool{

web-common/src/features/chat/core/conversation.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,7 @@ export class Conversation {
319319
}
320320

321321
this.addMessageToCache(response.message);
322-
if (
323-
response.message.tool === ToolName.NAVIGATE &&
324-
response.message.type === MessageType.CALL
325-
) {
322+
if (response.message.type === MessageType.CALL) {
326323
const config = getToolConfig(response.message.tool);
327324
config?.onResult?.(response.message);
328325
}

web-common/src/features/chat/core/messages/Messages.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import UserMessage from "./text/UserMessage.svelte";
1515
import ThinkingBlock from "./thinking/ThinkingBlock.svelte";
1616
import WorkingBlock from "./working/WorkingBlock.svelte";
17+
import GenericBlock from "@rilldata/web-common/features/chat/core/messages/generic/GenericBlock.svelte";
1718
1819
export let conversationManager: ConversationManager;
1920
export let layout: "sidebar" | "fullpage";
@@ -123,6 +124,8 @@
123124
<ChartBlock {block} {tools} />
124125
{:else if block.type === "file-diff"}
125126
<FileDiffBlock {block} {tools} />
127+
{:else if block.type === "generic-block"}
128+
<GenericBlock {block} {tools} />
126129
{/if}
127130
{/each}
128131
{/if}

web-common/src/features/chat/core/messages/block-transform.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "./thinking/thinking-block";
1616
import { getToolConfig, type ToolConfig } from "./tools/tool-registry";
1717
import { shouldShowWorking, type WorkingBlock } from "./working/working-block";
18+
import type { GenericBlock } from "@rilldata/web-common/features/chat/core/messages/generic/generic-block.ts";
1819

1920
// =============================================================================
2021
// TYPES & TRANSFORMATION
@@ -25,7 +26,8 @@ export type Block =
2526
| ThinkingBlock
2627
| ChartBlock
2728
| FileDiffBlock
28-
| WorkingBlock;
29+
| WorkingBlock
30+
| GenericBlock;
2931

3032
// Re-export individual block types for convenience
3133
export type {
@@ -34,6 +36,7 @@ export type {
3436
TextBlock,
3537
ThinkingBlock,
3638
WorkingBlock,
39+
GenericBlock,
3740
};
3841

3942
/**
@@ -91,6 +94,7 @@ export function transformToBlocks(
9194
if (block) {
9295
blocks.push(block);
9396
}
97+
console.log(block);
9498
break;
9599
}
96100

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
Renders a file diff block with collapsible tool call header.
3+
Shows the diff visualization with expandable request/response details.
4+
-->
5+
<script lang="ts">
6+
import type { V1Tool } from "../../../../../runtime-client";
7+
import ToolCall from "../tools/ToolCall.svelte";
8+
import type { GenericBlock } from "@rilldata/web-common/features/chat/core/messages/generic/generic-block.ts";
9+
10+
export let block: GenericBlock;
11+
export let tools: V1Tool[] | undefined = undefined;
12+
</script>
13+
14+
<div class="generic-block">
15+
<ToolCall
16+
message={block.message}
17+
resultMessage={block.resultMessage}
18+
{tools}
19+
variant="block"
20+
/>
21+
</div>
22+
23+
<style lang="postcss">
24+
.generic-block {
25+
@apply w-full max-w-full self-start;
26+
}
27+
</style>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { V1Message } from "@rilldata/web-common/runtime-client";
2+
3+
/**
4+
* Generic block that doesnt really have specific rendering.
5+
*/
6+
export type GenericBlock = {
7+
type: "generic-block";
8+
id: string;
9+
message: V1Message;
10+
resultMessage: V1Message;
11+
};
12+
13+
export function createGenericBlock(
14+
message: V1Message,
15+
resultMessage: V1Message | undefined,
16+
): GenericBlock | null {
17+
if (!resultMessage) return null;
18+
return {
19+
type: "generic-block",
20+
id: `generic-block-${message.id}`,
21+
message,
22+
resultMessage,
23+
};
24+
}

web-common/src/features/chat/core/messages/tools/tool-registry.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
type FileDiffBlock,
1616
} from "../file-diff/file-diff-block";
1717
import { goto } from "$app/navigation";
18-
import { maybePrependSlash } from "@rilldata/web-common/features/entity-management/file-path-utils.ts";
18+
import { addLeadingSlash } from "@rilldata/web-common/features/entity-management/entity-mappers.ts";
19+
import {
20+
createGenericBlock,
21+
type GenericBlock,
22+
} from "@rilldata/web-common/features/chat/core/messages/generic/generic-block.ts";
1923

2024
// =============================================================================
2125
// RENDER MODES
@@ -34,7 +38,7 @@ export type ToolRenderMode = "inline" | "block" | "hidden";
3438
// =============================================================================
3539

3640
/** Block types that can be created by tools */
37-
export type ToolBlockType = ChartBlock | FileDiffBlock;
41+
export type ToolBlockType = ChartBlock | FileDiffBlock | GenericBlock;
3842

3943
/**
4044
* Configuration for a tool's rendering behavior.
@@ -89,7 +93,8 @@ const TOOL_CONFIGS: Partial<Record<string, ToolConfig>> = {
8993
},
9094

9195
[ToolName.NAVIGATE]: {
92-
renderMode: "hidden",
96+
renderMode: "block",
97+
createBlock: createGenericBlock,
9398
onResult: handleNavigateToolCall,
9499
},
95100

@@ -123,7 +128,7 @@ function handleNavigateToolCall(callMessage: V1Message) {
123128
if (!content.kind || !content.name) return;
124129
switch (content.kind) {
125130
case "file":
126-
void goto(`/files${maybePrependSlash(content.name)}`);
131+
void goto(`/files${addLeadingSlash(content.name)}`);
127132
}
128133
} catch (err) {
129134
console.error(err);

web-common/src/features/entity-management/entity-mappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function removeLeadingSlash(path: string): string {
115115
}
116116

117117
// Add a leading slash if it doesn't exist.
118-
// Temporary, we should eventually make sure this is added in all places
118+
// While all files returned by Repo APIs have this already, AI interactions might not always have it.
119119
export function addLeadingSlash(path: string): string {
120120
if (path.startsWith("/")) return path;
121121
return "/" + path;

web-common/src/features/entity-management/file-path-utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,3 @@ export function splitFolderFileNameAndExtension(
5050
export function getTopLevelFolder(filePath: string): string {
5151
return "/" + (filePath.split(FILE_PATH_SPLIT_REGEX)[1] ?? "");
5252
}
53-
54-
export function maybePrependSlash(path: string) {
55-
return path.startsWith("/") ? path : "/" + path;
56-
}

0 commit comments

Comments
 (0)