Files
supabase/apps/studio/lib/ai/test-fixtures.ts
626eb30e77 Assistant action orientated approach (#38806)
* update onboarding

* update model and fix part issue

* action orientated assistant

* fix tool

* lock

* remove unused filter

* fix tests

* fix again

* update package

* update container

* fix tests

* refactor(ai assistant): break out message markdown and profile picture

* wip

* refactor(ai assistant): break up message component

* refactor: break ai assistant message down into multiple files

* refactor: simplify ReportBlock state

* fix: styling of draggable report block header

When the drag handle is showing, it overlaps with the block header.
Decrease the opacity of the header so the handle can be seen and the two
can be distinguished.

* fix: minor tweaks to tool ui

* refactor: simplify DisplayBlockRenderer state

* fix: remove double deploy button in edge function block

When the confirm footer is shown, the deploy button on the top right should be
hidden (not just disabled) to avoid confusion.

* refactor, test: message sanitization by opt-in level

Refactor the message sanitization to have more type safety and be more testable.
Add tests to ensure:

- Message sanitization always runs on generate-v4
- Message sanitization correctly works by opt-in level

* Fix conflicts in pnpm lock

* Couple of nits and refactors

* Revert casing for report block snippet

* adjust sanitised prompt

* Fix tests

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-09-29 03:57:36 +00:00

115 lines
2.8 KiB
TypeScript

import type { ToolUIPart, UIMessage } from 'ai'
export function createUserMessage(content: string, id = 'user-msg-1'): UIMessage {
return {
id,
role: 'user',
parts: [
{
type: 'text',
text: content,
},
],
}
}
export function createAssistantTextMessage(content: string, id = 'assistant-msg-1'): UIMessage {
return {
id,
role: 'assistant',
parts: [
{
type: 'text',
text: content,
},
],
}
}
export function createAssistantMessageWithExecuteSqlTool(
query: string,
results: Array<Record<string, any>> = [{ id: 1, name: 'test' }],
id = 'assistant-tool-msg-1'
): UIMessage {
return {
id,
role: 'assistant',
parts: [
{
type: 'text',
text: "I'll run that SQL query for you.",
},
{
type: 'tool-execute_sql',
state: 'output-available',
toolCallId: 'call-123',
input: { sql: query },
output: results,
} satisfies ToolUIPart,
],
}
}
export function createAssistantMessageWithMultipleTools(
id = 'assistant-multi-tool-msg-1'
): UIMessage {
return {
id,
role: 'assistant',
parts: [
{
type: 'text',
text: 'Let me check the database structure and run some queries.',
},
{
type: 'tool-execute_sql',
state: 'output-available',
toolCallId: 'call-456',
input: { sql: 'SELECT * FROM users LIMIT 5' },
output: [
{ id: 1, email: 'user1@example.com' },
{ id: 2, email: 'user2@example.com' },
],
} satisfies ToolUIPart,
{
type: 'tool-execute_sql',
state: 'output-available',
toolCallId: 'call-789',
toolName: 'execute_sql',
input: { sql: 'DESCRIBE users' },
output: [
{ column: 'id', type: 'integer', nullable: false },
{ column: 'email', type: 'varchar', nullable: false },
],
} as ToolUIPart,
],
}
}
export function createLongConversation(): Array<UIMessage> {
return [
createUserMessage('Show me all users', 'msg-1'),
createAssistantMessageWithExecuteSqlTool('SELECT * FROM users', [{ id: 1 }], 'msg-2'),
createUserMessage('How many users are there?', 'msg-3'),
createAssistantMessageWithExecuteSqlTool(
'SELECT COUNT(*) FROM users',
[{ count: 100 }],
'msg-4'
),
createUserMessage('Show me the schema', 'msg-5'),
createAssistantTextMessage("Here's the database schema...", 'msg-6'),
createUserMessage('Create a new table', 'msg-7'),
createAssistantMessageWithExecuteSqlTool(
'CREATE TABLE posts (id SERIAL PRIMARY KEY)',
[],
'msg-8'
),
createUserMessage('Add some data', 'msg-9'),
createAssistantMessageWithExecuteSqlTool(
"INSERT INTO posts (title) VALUES ('Test')",
[],
'msg-10'
),
]
}