Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
30c00e5
feat(ai): add Context7 documentation tools integration
illyadmitriev Jan 12, 2026
470e51c
refactor: improve Context7 integration and tool UI readability
illyadmitriev Jan 12, 2026
6d4576d
refactor: complete Zod to ArkType migration and enhance AI tools
illyadmitriev Jan 12, 2026
6479813
refactor(tools): centralize tool creation and improve performance
illyadmitriev Jan 12, 2026
42828f8
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri Jan 14, 2026
8511c00
feat(ai): add Context7 documentation tools integration
illyadmitriev Jan 12, 2026
9639279
refactor: improve Context7 integration and tool UI readability
illyadmitriev Jan 12, 2026
e8f6e60
refactor: complete Zod to ArkType migration and enhance AI tools
illyadmitriev Jan 12, 2026
ebee7ad
refactor(tools): centralize tool creation and improve performance
illyadmitriev Jan 12, 2026
0e50898
fix(orpc): add explicit output types to prevent ToJsonSchemaError
illyadmitriev Jan 14, 2026
b649e25
fix: return `webSecurity` operator
illyadmitriev Jan 14, 2026
cb4b748
chore: update context7 aisdk dep
letstri Jan 14, 2026
594efa7
refactor(ai): improve schema validation and filter handling
illyadmitriev Jan 14, 2026
9b81e02
Merge branch 'feat/context-implementation' of https://github.com/wann…
letstri Jan 14, 2026
8f09ecb
Merge branch 'feat/context-implementation' of https://github.com/wann…
letstri Jan 14, 2026
02684d1
chore: remove zod dependency
letstri Jan 14, 2026
517fd4d
refactor: simplify error handling
letstri Jan 14, 2026
d42a20b
refactor: enhance input schema descriptions
letstri Jan 14, 2026
f672d83
refactor: enhance schema descriptions
letstri Jan 14, 2026
aad50f0
refactor: streamline component structure
letstri Jan 14, 2026
36459d8
refactor(ai): update input schema and improve null handling
letstri Jan 14, 2026
f169ded
refactor(chat): enhance tool state handling and icon management
letstri Jan 14, 2026
1603a8a
refactor: integrate new tool types
letstri Jan 14, 2026
d525d96
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri Jan 14, 2026
b47aa32
refactor: remove unused ai dependency
letstri Jan 14, 2026
49b5764
refactor(chat): improve tool title generation and update component st…
letstri Jan 15, 2026
1cdafc8
Merge branch 'main' of https://github.com/wannabespace/conar into fea…
letstri Jan 16, 2026
d8d92ed
refactor(chat): enhance ChatMessageTool component
letstri Jan 18, 2026
626a6a1
refactor(chat): streamline error handling and state management in Cha…
letstri Jan 18, 2026
c640e48
refactor(chat): improve title generation and error message extraction…
letstri Jan 18, 2026
76e6a30
refactor(chat): enhance ChatMessageTool component
letstri Jan 18, 2026
3305c53
refactor(chat): reintroduce tool-queryDocs functionality in ChatMessa…
letstri Jan 18, 2026
7a5b29a
refactor(chat): allow dynamic language selection in MonacoOutput comp…
letstri Jan 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
EXA_API_KEY=
GITHUB_TOKEN=
CONTEXT7_API_KEY=
TODESKTOP_WEBHOOK_SECRET=
1 change: 1 addition & 0 deletions apps/api/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
EXA_API_KEY=
GITHUB_TOKEN=
CONTEXT7_API_KEY=
TODESKTOP_WEBHOOK_SECRET=
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@posthog/ai": "catalog:",
"@react-email/components": "catalog:",
"@toon-format/toon": "catalog:",
"@upstash/context7-tools-ai-sdk": "catalog:",
"ai": "catalog:",
"ai-retry": "catalog:",
"arktype": "catalog:",
Expand Down
41 changes: 36 additions & 5 deletions apps/api/src/ai-tools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import type { InferUITools, UIDataTypes, UIMessage } from 'ai'
import type { InferUITools, Tool, UIDataTypes, UIMessage } from 'ai'
import { SQL_FILTERS_LIST } from '@conar/shared/filters/sql'
import { webSearch } from '@exalabs/ai-sdk'
import {
AGENT_PROMPT as CONTEXT7_AGENT_PROMPT,
GET_LIBRARY_DOCS_DESCRIPTION,
getLibraryDocs,
RESOLVE_LIBRARY_DESCRIPTION,
resolveLibrary,
} from '@upstash/context7-tools-ai-sdk'
import { tool } from 'ai'
import * as z from 'zod'
import { env } from '~/env'
Expand All @@ -15,12 +22,15 @@ export const tools = {
}),
}),
outputSchema: z.array(z.object({
isEditable: z.boolean(),
isNullable: z.boolean(),
schema: z.string(),
table: z.string(),
id: z.string(),
type: z.string(),
default: z.string().nullable(),
type: z.string(),
enum: z.string().optional(),
isArray: z.boolean().optional(),
isEditable: z.boolean(),
isNullable: z.boolean(),
})),
}),
enums: tool({
Expand Down Expand Up @@ -58,11 +68,32 @@ export const tools = {
schemaName: z.string().describe('The name of the schema to query'),
}).describe('The name of the table and schema to query'),
}),
outputSchema: z.any(),
outputSchema: z.union([
z.array(z.record(z.string(), z.unknown())),
z.object({ error: z.string() }),
]),
}),
webSearch: webSearch({ apiKey: env.EXA_API_KEY }),
}

export function createContext7Tools(): Record<string, Tool> {
const config = { apiKey: env.CONTEXT7_API_KEY, defaultMaxResults: 15 }

return {
resolveLibrary: resolveLibrary(config),
getLibraryDocs: getLibraryDocs(config),
}
}

export function getContext7SystemPrompt(): string {
return CONTEXT7_AGENT_PROMPT
}
Comment thread
ifeelBALANCED marked this conversation as resolved.
Outdated

export const context7ToolDescriptions = {
resolveLibrary: RESOLVE_LIBRARY_DESCRIPTION,
getLibraryDocs: GET_LIBRARY_DOCS_DESCRIPTION,
}

export type AppUIMessage = UIMessage<
{
updatedAt?: Date
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const envType = type({
GITHUB_CLIENT_SECRET: 'string',
BANNER_TEXT: 'string?',
EXA_API_KEY: 'string',
CONTEXT7_API_KEY: 'string',
GITHUB_TOKEN: 'string',
TODESKTOP_WEBHOOK_SECRET: 'string',
})
Expand All @@ -51,6 +52,7 @@ const devOptionalEnvs = [
'GITHUB_CLIENT_ID',
'GITHUB_CLIENT_SECRET',
'EXA_API_KEY',
'CONTEXT7_API_KEY',
'GITHUB_TOKEN',
'TODESKTOP_WEBHOOK_SECRET',
] satisfies (keyof typeof envType.infer)[]
Expand Down
27 changes: 22 additions & 5 deletions apps/api/src/orpc/routers/ai/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { type } from 'arktype'
import { consola } from 'consola'
import { asc, eq } from 'drizzle-orm'
import { v7 } from 'uuid'
import { convertToAppUIMessage, tools } from '~/ai-tools'
import { context7ToolDescriptions, convertToAppUIMessage, createContext7Tools, getContext7SystemPrompt, tools } from '~/ai-tools'
import { chats, chatsMessages, db } from '~/drizzle'
import { withPosthog } from '~/lib/posthog'
import { orpc, requireSubscriptionMiddleware } from '~/orpc'
Expand Down Expand Up @@ -73,7 +73,12 @@ async function generateStream({
partsCount: message.parts.length,
})), null, 2))

const context7Tools = createContext7Tools()
const modelMessages = await convertToModelMessages(messages)
const allTools = {
...tools,
...context7Tools,
}

return streamText({
messages: [
Expand All @@ -100,10 +105,22 @@ async function generateStream({
'Additional information:',
`- Current date and time: ${new Date().toISOString()}`,
'',
'You can use the following tools to help you generate the SQL code:',
`- ${Object.entries(tools).map(([tool, { description }]) => `${tool}: ${description}`).join('\n')}`,
'## Available Tools',
'',
'### Database Tools',
`${Object.entries(tools).map(([toolName, { description }]) => `- **${toolName}**: ${description}`).join('\n')}`,
'',
'### Context7 Documentation Tools',
'Use these tools to search for up-to-date library documentation when users ask about programming concepts, APIs, or need code examples.',
'',
`- **resolveLibrary**: ${context7ToolDescriptions.resolveLibrary}`,
'',
`- **getLibraryDocs**: ${context7ToolDescriptions.getLibraryDocs}`,
'',
'### Context7 Workflow',
getContext7SystemPrompt(),
'',
'User provided context:',
'## User Provided Context',
context,
].join('\n'),
},
Expand All @@ -116,7 +133,7 @@ async function generateStream({
userId,
}),
experimental_transform: smoothStream(),
tools,
tools: allTools,
})
}

Expand Down
Loading