Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ SLACK_SIGNING_SECRET=
# Context folder (to change for your setup)
NAO_DEFAULT_PROJECT_PATH=/Users/blef/Work/naolabs/chat/example

# Build metadata (optional)
APP_VERSION=dev
APP_COMMIT=unknown
APP_BUILD_DATE=

# SMTP server Configuration
SMTP_HOST= # smtp.yourservice.com
SMTP_SSL=false
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
cache-to: type=gha,mode=max
build-args: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
APP_VERSION=${{ steps.sha.outputs.short_sha }}
APP_COMMIT=${{ github.sha }}
APP_BUILD_DATE=${{ github.event.head_commit.timestamp }}

- name: Update Docker Hub description
if: github.event_name != 'pull_request'
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ RUN uv pip install --system .
# =============================================================================
FROM python:3.12-slim AS runtime

ARG APP_VERSION=dev
ARG APP_COMMIT=unknown
ARG APP_BUILD_DATE=

# Install Node.js, Bun, git, and supervisor
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
Expand Down Expand Up @@ -128,6 +132,9 @@ ENV MODE=prod
ENV NODE_ENV=production
ENV BETTER_AUTH_URL=http://localhost:5005
ENV FASTAPI_PORT=8005
ENV APP_VERSION=$APP_VERSION
ENV APP_COMMIT=$APP_COMMIT
ENV APP_BUILD_DATE=$APP_BUILD_DATE
ENV NAO_DEFAULT_PROJECT_PATH=/app/example
ENV NAO_CONTEXT_SOURCE=local

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ docker run -d \
-e BETTER_AUTH_URL=http://localhost:5005 \
-v /path/to/your/nao-project:/app/project \
-e NAO_DEFAULT_PROJECT_PATH=/app/project \
getnao/nao:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this?

```

Access the UI at http://localhost:5005

Expand Down Expand Up @@ -216,3 +214,4 @@ nao Labs is a proud Y Combinator company!
## 📄 License

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.
```
4 changes: 2 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"build": "tsup src/index.ts --format esm --target node20 --minify",
"build:standalone": "bun build src/cli.ts --compile --outfile nao-chat-server",
"start": "node dist/index.js",
"test": "vitest run",
"test": "vitest --config ./vitest.config.ts run",
"lint": "tsc --noEmit && eslint",
"lint:fix": "eslint --fix",
"db:generate": "bash scripts/db.generate.sh",
Expand All @@ -28,7 +28,7 @@
"db:reset": "rm db.sqlite",
"db:check-migrations": "bun scripts/db.check-migrations.ts",
"format": "prettier --write .",
"test:tool-outputs": "PRINT_OUTPUT=true vitest run tests/tool-outputs/"
"test:tool-outputs": "PRINT_OUTPUT=true vitest --config ../frontend/vite.config.ts run tests/tool-outputs/"
},
"dependencies": {
"@ai-sdk/anthropic": "^3.0.15",
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/src/agents/tools/execute-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export default tool<executeSql.Input, executeSql.Output>({

export async function executeQuery({ sql_query, database_id }: executeSql.Input): Promise<executeSql.Output> {
const naoProjectFolder = getProjectFolder();
const executeSqlUrl = new URL('/execute_sql', `http://127.0.0.1:${env.FASTAPI_PORT}`).toString();

const response = await fetch(`http://localhost:${env.FASTAPI_PORT}/execute_sql`, {
const response = await fetch(executeSqlUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const envSchema = z.object({

FASTAPI_PORT: z.coerce.number().default(8005),

APP_VERSION: z.string().default('dev'),
APP_COMMIT: z.string().default('unknown'),
APP_BUILD_DATE: z.string().default(''),

NAO_DEFAULT_PROJECT_PATH: z.string().optional(),

MCP_JSON_FILE_PATH: z.string().optional(),
Expand Down
8 changes: 4 additions & 4 deletions apps/backend/src/trpc/google.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const googleRoutes = {
authDomains: z.string(),
}),
)
.mutation(({ input }) => {
.mutation(({ input: _input }) => {
//TO DO : Save google settings in a secure store or database

// process.env.GOOGLE_CLIENT_ID = input.clientId;
// process.env.GOOGLE_CLIENT_SECRET = input.clientSecret;
// process.env.GOOGLE_AUTH_DOMAINS = input.authDomains;
// process.env.GOOGLE_CLIENT_ID = _input.clientId;
// process.env.GOOGLE_CLIENT_SECRET = _input.clientSecret;
// process.env.GOOGLE_AUTH_DOMAINS = _input.authDomains;

return { success: true };
}),
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/trpc/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { googleRoutes } from './google.routes';
import { mcpRoutes } from './mcp.routes';
import { posthogRoutes } from './posthog.routes';
import { projectRoutes } from './project.routes';
import { systemRoutes } from './system.routes';
import { router } from './trpc';
import { usageRoutes } from './usage.routes';
import { userRoutes } from './user.routes';
Expand All @@ -19,6 +20,7 @@ export const trpcRouter = router({
google: googleRoutes,
account: accountRoutes,
mcp: mcpRoutes,
system: systemRoutes,
});

export type TrpcRouter = typeof trpcRouter;
10 changes: 10 additions & 0 deletions apps/backend/src/trpc/system.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { env } from '../env';
import { adminProtectedProcedure } from './trpc';

export const systemRoutes = {
version: adminProtectedProcedure.query(() => ({
version: env.APP_VERSION,
commit: env.APP_COMMIT,
buildDate: env.APP_BUILD_DATE,
})),
};
4 changes: 2 additions & 2 deletions apps/backend/tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { NewUser } from '../src/db/abstractSchema';
import { user } from '../src/db/pgSchema';
import * as pgSchema from '../src/db/pgSchema';

const db = drizzle(process.env.DB_URI!, { schema: pgSchema });
const db = drizzle(process.env.DB_URI || '', { schema: pgSchema });

describe('userTable', () => {
(process.env.DB_URI ? describe : describe.skip)('userTable', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why u need to change this.

const testUser: NewUser = {
id: 'test-user-id',
name: 'John',
Expand Down
13 changes: 13 additions & 0 deletions apps/backend/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config';

Check warning on line 1 in apps/backend/vitest.config.ts

View workflow job for this annotation

GitHub Actions / ESLint, Prettier and Database Migration Checks

Run autofix to sort these imports!
import base from '../frontend/vite.config';

const baseConfig = base as unknown as { test?: Record<string, unknown> };

export default defineConfig({
...base,
test: {
...(baseConfig.test ?? {}),
// Run migrations once in the main process before workers start
globalSetup: './vitest.setup.ts',
},
});
54 changes: 54 additions & 0 deletions apps/backend/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import fs from 'fs';

Check warning on line 1 in apps/backend/vitest.setup.ts

View workflow job for this annotation

GitHub Actions / ESLint, Prettier and Database Migration Checks

Run autofix to sort these imports!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a few eslint warnings.

import path from 'path';
import Database from 'better-sqlite3';

async function runMigrations() {
// Ensure a fresh sqlite DB for tests
const DB_PATH = path.resolve(process.cwd(), 'db.sqlite');
if (fs.existsSync(DB_PATH)) {
try {
fs.unlinkSync(DB_PATH);
} catch {
// ignore
}
}

// Create DB file and run sqlite migrations
const db = new Database(DB_PATH);
const migrationsDir = path.resolve(process.cwd(), 'migrations-sqlite');
if (fs.existsSync(migrationsDir)) {
const files = fs
.readdirSync(migrationsDir)
.filter((f) => f.endsWith('.sql'))
.sort();
for (const file of files) {
const content = fs.readFileSync(path.join(migrationsDir, file), 'utf8');
const stmts = content
.split('--> statement-breakpoint')
.map((s) => s.trim())
.filter(Boolean);
for (const stmt of stmts) {
if (stmt) {
try {
db.exec(stmt);
} catch (err: unknown) {
let msg = '';
if (err instanceof Error) msg = err.message;

Check warning on line 36 in apps/backend/vitest.setup.ts

View workflow job for this annotation

GitHub Actions / ESLint, Prettier and Database Migration Checks

Expected { after 'if' condition
else msg = String(err);

Check warning on line 37 in apps/backend/vitest.setup.ts

View workflow job for this annotation

GitHub Actions / ESLint, Prettier and Database Migration Checks

Expected { after 'else'
// Ignore "already exists" / duplicate column errors so setup is idempotent
if (/already exists|duplicate column/i.test(msg)) {
continue;
}
throw err;
}
}
}
}
}

db.close();
}

export default async function () {
await runMigrations();
}
54 changes: 53 additions & 1 deletion apps/frontend/src/routes/_sidebar-layout.settings.project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ function ProjectPage() {
const { tab } = Route.useSearch();
const activeTab = tab ?? 'project';
const project = useQuery(trpc.project.getCurrent.queryOptions());

const isAdmin = project.data?.userRole === 'admin';
const appVersion = useQuery({
...trpc.system.version.queryOptions(),
enabled: isAdmin,
});

return (
<div className='flex flex-row gap-6'>
Expand Down Expand Up @@ -90,6 +93,55 @@ function ProjectPage() {
<SettingsCard title='Google Credentials'>
<GoogleConfigSection isAdmin={isAdmin} />
</SettingsCard>

{isAdmin && (
<SettingsCard title='Application'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using inputs can you make the design flatter? I know we use input for project parameters, but it's because we might make them editable, where here it does not makes sense to edit.

<div className='grid gap-4'>
<div className='grid gap-2'>
<label
htmlFor='app-version'
className='text-sm font-medium text-foreground'
>
Version
</label>
<Input
id='app-version'
value={appVersion.data?.version ?? 'unknown'}
readOnly
className='bg-muted/50 font-mono text-sm'
/>
</div>
<div className='grid gap-2'>
<label
htmlFor='app-commit'
className='text-sm font-medium text-foreground'
>
Commit
</label>
<Input
id='app-commit'
value={appVersion.data?.commit ?? 'unknown'}
readOnly
className='bg-muted/50 font-mono text-sm'
/>
</div>
<div className='grid gap-2'>
<label
htmlFor='app-build-date'
className='text-sm font-medium text-foreground'
>
Build date
</label>
<Input
id='app-build-date'
value={appVersion.data?.buildDate || 'unknown'}
readOnly
className='bg-muted/50 font-mono text-sm'
/>
</div>
</div>
</SettingsCard>
)}
</div>
)}

Expand Down
Loading