Skip to content
Merged
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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Default local ports: API and Socket.IO on 8080 (`API_PORT`), Keycloak on 8081, w

### Tests

The api only has **e2e tests** (`apps/api/tests/*.e2e-spec.ts`), and the web app has none. `test` and `test:e2e` both run the same Jest suite. The tests boot the full `AppModule` and create and delete real users through the Keycloak admin API, so they need Postgres, Keycloak and a complete `.env` (including `OPENAI_API_KEY`, since env validation fails without it).
The api only has **e2e tests** (`apps/api/tests/*.e2e-spec.ts`), and the web app has none. `test` and `test:e2e` both run the same Jest suite. The tests boot the full `AppModule` and create and delete real users through the Keycloak admin API, so they need Postgres, Keycloak and a complete `.env`. The AI keys are optional: without them the bots stay off. `tests/ai-bots.spec.ts` is a plain unit test that needs no infrastructure.

The api is ESM (`"type": "module"`), so relative and `@/` imports carry the `.js` extension. The tests, however, are compiled to CommonJS by ts-jest (Jest's ESM loader trips on a `require(esm)` cycle inside the Nest packages), and the scripts run Jest as `node --experimental-vm-modules .../jest.js` so it can `require()` the ESM-only Nest 12, uuid and jwks-rsa (jose). Use the `test` script rather than a bare `jest`. Node >= 26.13 (current LTS) is required.

Expand Down Expand Up @@ -116,7 +116,7 @@ tsgolint does not support `baseUrl`, so the api `tsconfig.json` has `paths` with
- Presence is `PresenceService`, an in-memory map that broadcasts its own changes and assumes a single API instance.
- Inbound events are manual `socket.on` listeners, not `@SubscribeMessage`, because the global guard and interceptor assume HTTP.

**AI bots (`src/modules/ai/`).** Three bot users with hard-coded UUIDs (`IAUserModels`) are upserted on module init and are always shown online. When a non-bot message matches a bot's name pattern, `MessageService` generates the reply asynchronously (fire-and-forget) through OpenAI and toggles the bot's typing status.
**AI bots (`src/modules/ai/`).** Three bots are defined as data in `BOTS` (`bots.ts`: hard-coded user UUIDs, trigger regex, system prompt); their users are upserted on module init and are always shown online. When a non-bot message matches a bot's trigger, `MessageService` loads the last 30 channel messages and generates the reply asynchronously (fire-and-forget) through the Vercel AI SDK, toggling the bot's typing status. The model comes from `AI_MODEL` (`provider:model`: `anthropic`, `openai`, or `ollama` through its OpenAI-compatible API at `OLLAMA_BASE_URL`; default `anthropic:claude-haiku-5-5`); without that provider's key the bots stay off (Ollama needs none).

## Web architecture (`apps/web`)

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ The ports are fixed, because the Keycloak realm's redirect URIs use them, and
the demo users and data live in `docker/`.

> [!NOTE]
> **AI bots and `OPENAI_API_KEY`.** The api needs the variable to boot, so
> `compose.yaml` passes the placeholder `not-set` when it is missing; the bots
> still show up online, but stay silent. To give them a real key, set
> `OPENAI_API_KEY` in the shell or in a root `.env` (git-ignored, so it is the
> right place for it). Even with a valid key the bots do not answer yet: v3
> still asks for `gpt-3.5-turbo`, which OpenAI has retired. (ima changed it to the sdk from vercel in the next prs i hope)
> **AI bots.** They are optional: without a key they show up online but stay
> silent. To turn them on, set `ANTHROPIC_API_KEY` in the shell or in a root
> `.env` (git-ignored, so it is the right place for it). The model defaults to
> `anthropic:claude-haiku-5-5`; set `AI_MODEL=openai:gpt-6-luna` (the
> recommended OpenAI model) and `OPENAI_API_KEY` to use OpenAI instead, or
> `AI_MODEL=ollama:<model>` (no key) to use an Ollama running on the host.

## Infrastructure services

Expand Down
6 changes: 5 additions & 1 deletion apps/api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ KEYCLOAK_CLIENT_SECRET=
AUTH_CALLBACK_URL=http://localhost:3000/api/v1/auth/callback
PUBLIC_WEB_URL=http://localhost:3000/

# chat yipiti
# AI bots. Format provider:model (anthropic | openai | ollama). Bots stay off without the provider's key;
# recommended: anthropic:claude-haiku-5-5 (default) or openai:gpt-6-luna. ollama needs no key (e.g. AI_MODEL=ollama:llama3.2).
AI_MODEL=anthropic:claude-haiku-5-5
ANTHROPIC_API_KEY=
OPENAI_API_KEY=
OLLAMA_BASE_URL=http://localhost:11434/v1
5 changes: 4 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"typecheck": "tsc --noEmit -p tsconfig.json"
},
"dependencies": {
"@ai-sdk/anthropic": "^4.0.105",
"@ai-sdk/openai": "^4.0.118",
"@ai-sdk/openai-compatible": "^3.0.92",
"@fastify/compress": "^9.3.0",
"@fastify/helmet": "^13.2.0",
"@fastify/static": "^10.1.8",
Expand All @@ -41,6 +44,7 @@
"@nestjs/throttler": "^6.7.1",
"@nestjs/websockets": "^12.3.2",
"@sentry/nestjs": "^11.10.0",
"ai": "^7.0.173",
"class-transformer": "^0.5.1",
"class-validator": "^0.15.1",
"dotenv": "^18.0.9",
Expand All @@ -49,7 +53,6 @@
"jsonwebtoken": "^9.0.3",
"jwks-rsa": "^4.1.0",
"nestjs-pino": "^5.3.1",
"openai": "^7.47.0",
"pg": "^8.23.1",
"pino": "^10.4.0",
"pino-http": "^11.0.0",
Expand Down
20 changes: 18 additions & 2 deletions apps/api/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEnum, IsNumber, IsOptional, IsString, Min } from 'class-validator';
import { IsEnum, IsNumber, IsOptional, IsString, Matches, Min } from 'class-validator';

export enum Environment {
Development = 'development',
Expand Down Expand Up @@ -62,6 +62,22 @@ export class EnvironmentVariables implements IEnvironmentVariables {
@IsString()
PUBLIC_WEB_URL!: string;

// AI bots
@IsOptional()
@Matches(/^(anthropic|openai|ollama):.+$/, {
message: 'AI_MODEL must look like anthropic:<model>, openai:<model> or ollama:<model>',
})
AI_MODEL?: string;

@IsOptional()
@IsString()
ANTHROPIC_API_KEY?: string;

@IsOptional()
@IsString()
OPENAI_API_KEY?: string;

@IsOptional()
@IsString()
OPENAI_API_KEY!: string;
OLLAMA_BASE_URL?: string;
}
295 changes: 0 additions & 295 deletions apps/api/src/modules/ai/ai-command.service.ts

This file was deleted.

Loading
Loading