Skip to content

Commit 4d56616

Browse files
refactor: merge with main
2 parents 1806867 + 3215eed commit 4d56616

99 files changed

Lines changed: 3151 additions & 2801 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint-check.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,7 @@ jobs:
2626
with:
2727
version: 10.28.0
2828

29-
- name: Restore cached dependencies
30-
id: cache-restore
31-
uses: actions/cache@v3
32-
with:
33-
path: |
34-
node_modules
35-
~/.pnpm-store
36-
key: pnpm-${{ hashFiles('pnpm-lock.yaml') }}
37-
3829
- name: Install dependencies
39-
if: steps.cache-restore.outputs.cache-hit != 'true'
4030
run: pnpm install --frozen-lockfile --ignore-scripts
4131

4232
- name: Lint

.vscode/extensions.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"typescript.experimental.useTsgo": true,
32
// Disable the default formatter, use eslint instead
43
"prettier.enable": false,
54
"editor.formatOnSave": false,

apps/api/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ GITHUB_CLIENT_ID=
2222
GITHUB_CLIENT_SECRET=
2323
EXA_API_KEY=
2424
GITHUB_TOKEN=
25+
CONTEXT7_API_KEY=
2526
TODESKTOP_WEBHOOK_SECRET=

apps/api/.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ GITHUB_CLIENT_ID=
2222
GITHUB_CLIENT_SECRET=
2323
EXA_API_KEY=
2424
GITHUB_TOKEN=
25+
CONTEXT7_API_KEY=
2526
TODESKTOP_WEBHOOK_SECRET=

apps/api/ai-tools.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

apps/api/ai/tools/helpers.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { DynamicToolUIPart, InferUITools, ToolUIPart as ToolUIPartAi, UIDataTypes, UIMessage } from 'ai'
2+
import type { tools } from '.'
3+
import { isToolUIPart as isToolUIPartAi } from 'ai'
4+
5+
export type AppUIMessage = UIMessage<
6+
{
7+
updatedAt?: Date
8+
createdAt?: Date
9+
},
10+
UIDataTypes,
11+
InferUITools<typeof tools>
12+
>
13+
14+
export function convertToAppUIMessage(message: UIMessage): AppUIMessage {
15+
return message as AppUIMessage
16+
}
17+
18+
export type ToolUIPart = ToolUIPartAi<InferUITools<typeof tools>> | DynamicToolUIPart
19+
20+
export function isToolUIPart(part: UIMessage['parts'][number]): part is ToolUIPart {
21+
return isToolUIPartAi(part)
22+
}

apps/api/ai/tools/index.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { SQL_FILTERS_LIST } from '@conar/shared/filters/sql'
2+
import { webSearch } from '@exalabs/ai-sdk'
3+
import { queryDocs, resolveLibraryId } from '@upstash/context7-tools-ai-sdk'
4+
import { tool } from 'ai'
5+
import { type } from 'arktype'
6+
import { env } from '~/env'
7+
8+
export const tools = {
9+
columns: tool({
10+
description: 'Use this tool if you need to get the list of columns in a table.',
11+
inputSchema: type({
12+
tableAndSchema: type({
13+
tableName: 'string',
14+
schemaName: 'string',
15+
}),
16+
}),
17+
outputSchema: type({
18+
isEditable: 'boolean',
19+
isNullable: 'boolean',
20+
table: 'string',
21+
id: 'string',
22+
type: 'string',
23+
default: 'string | null',
24+
}).array(),
25+
}),
26+
enums: tool({
27+
description: 'Use this tool if you need to get the list of enums in a database',
28+
inputSchema: type({}),
29+
outputSchema: type({
30+
schema: 'string',
31+
name: 'string',
32+
value: 'string',
33+
}).array(),
34+
}),
35+
select: tool({
36+
description: [
37+
'Use this tool to select data from the database to improve your response.',
38+
'Do not abuse this tool, unless you are 100% sure that the data will help to answer the question.',
39+
'Do not select any sensitive data, like password, token, secret, card number, etc.',
40+
'Mask sensitive data with asterisks if need to select to answer the question.',
41+
'Do not use any tables and schemas that are not provided in the input.',
42+
'tableName and schemaName will be concatenated to "schemaName.tableName".',
43+
'For tableName use only table without schema prefix.',
44+
].join('\n'),
45+
inputSchema: type({
46+
whereConcatOperator: type('"AND" | "OR"').describe('The operator to use to concatenate the where clauses'),
47+
whereFilters: type({
48+
column: 'string',
49+
operator: type
50+
.enumerated(...SQL_FILTERS_LIST.map(filter => filter.operator))
51+
.describe('The operator to use in the where clause'),
52+
values: 'string[]',
53+
})
54+
.array()
55+
.describe('The columns to use in the where clause'),
56+
select: type('string[] | null').describe('The columns to select. If not provided, all columns will be selected'),
57+
limit: 'number',
58+
offset: 'number',
59+
orderBy: 'Record<string, "ASC" | "DESC"> | null',
60+
tableAndSchema: type({
61+
tableName: 'string',
62+
schemaName: 'string',
63+
}).describe('The name of the table and schema to query'),
64+
}).describe('Input schema for database select query with filters, ordering, and pagination'),
65+
outputSchema: type('unknown'),
66+
}),
67+
...(env.EXA_API_KEY && { webSearch: webSearch({ apiKey: env.EXA_API_KEY }) }),
68+
...(env.CONTEXT7_API_KEY && {
69+
resolveLibraryId: resolveLibraryId({ apiKey: env.CONTEXT7_API_KEY }),
70+
queryDocs: queryDocs({ apiKey: env.CONTEXT7_API_KEY }),
71+
}),
72+
}

apps/api/drizzle/schema/chats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AppUIMessage } from '~/ai-tools'
1+
import type { AppUIMessage } from '~/ai/tools/helpers'
22
import { createInsertSchema, createSelectSchema, createUpdateSchema } from 'drizzle-arktype'
33
import { relations } from 'drizzle-orm'
44
import { index, pgTable, text, uuid } from 'drizzle-orm/pg-core'

apps/api/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const envType = type({
2929
GITHUB_CLIENT_SECRET: 'string',
3030
BANNER_TEXT: 'string?',
3131
EXA_API_KEY: 'string',
32+
CONTEXT7_API_KEY: 'string',
3233
GITHUB_TOKEN: 'string',
3334
TODESKTOP_WEBHOOK_SECRET: 'string',
3435
})
@@ -51,6 +52,7 @@ const devOptionalEnvs = [
5152
'GITHUB_CLIENT_ID',
5253
'GITHUB_CLIENT_SECRET',
5354
'EXA_API_KEY',
55+
'CONTEXT7_API_KEY',
5456
'GITHUB_TOKEN',
5557
'TODESKTOP_WEBHOOK_SECRET',
5658
] satisfies (keyof typeof envType.infer)[]

0 commit comments

Comments
 (0)