diff --git a/.env.example b/.env.example index 9f33510..6ed0962 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,5 @@ # Agent Configuration AGENT_BASE_URL=http://127.0.0.1:3500 -AGENT_ID=agent_9ccc5545e93644bd9d7954e632a55a61 -# Alternative: You can also set the full URL instead of BASE_URL + ID -# AGENT_FULL_URL=http://127.0.0.1:3500/agent_9ccc5545e93644bd9d7954e632a55a61 \ No newline at end of file +# KV-store is hitting Agentuity Service API, this can be found in `agent-docs` after running `agentuity dev` +AGENTUITY_API_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 38bf69a..a45f3bb 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ next-env.d.ts .dev.vars # this is generated by the build process -content/docs.json \ No newline at end of file +content/docs.json diff --git a/README.md b/README.md index 87f9cc8..8042bd8 100644 --- a/README.md +++ b/README.md @@ -18,19 +18,24 @@ To make the search feature work, you must set up `.env.local` with the following cd agent-docs ``` -2. **Start the Agent:** +2. **Generate Agent Environment:** ```bash agentuity dev ``` + This will generate a `.env` file in the `agent-docs` directory with your SDK key. The key is required for the next steps. + + 3. **Copy Environment Configuration:** - For local development, copy the `.env.example` file to `.env.local`: + For local development, copy the `.env.example` file to `.env.local` in the root directory of the docs project: ```bash + # Make sure you are in the root directory, not in agent-docs + cd ../ cp .env.example .env.local ``` -4. **Update `AGENT_ID`:** - If you are a contributor from outside the Agentuity organization, ensure that you update the `AGENT_ID` in your `.env.local` file with your specific agent ID from the `agentuity dev` run. +4. **Update `AGENTUITY_API_KEY`:** + If you are a contributor from outside the Agentuity organization, ensure that you update the `AGENTUITY_API_KEY` in your `.env.local` file with your specific SDK key from the `agentuity dev` run. ## Running Docs Application diff --git a/middleware.ts b/middleware.ts index a3e0c38..667ee04 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,5 +1,6 @@ import type { NextRequest } from 'next/server'; import { NextResponse } from 'next/server'; +import { v4 as uuidv4 } from 'uuid'; const TYPE_MAP: Record = { agent: 'agents', @@ -11,9 +12,22 @@ const TYPE_MAP: Record = { sys: 'system', }; +const COOKIE_NAME = 'chat_user_id'; +const COOKIE_MAX_AGE = 24 * 60 * 60 * 14; // 14 days + export function middleware(request: NextRequest) { const { pathname } = request.nextUrl; - + let userId = request.cookies.get(COOKIE_NAME)?.value; + const response = NextResponse.next(); + if (!userId) { + userId = uuidv4(); + response.cookies.set(COOKIE_NAME, userId, { + maxAge: COOKIE_MAX_AGE, + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + sameSite: 'lax', + }); + } // Match error code URLs const errorMatch = pathname.match( /^\/errors\/((?:CLI|AUTH|PROJ|AGENT|DATA|INT|SYS)-\d+)$/ @@ -31,4 +45,6 @@ export function middleware(request: NextRequest) { return NextResponse.redirect(url); } + + return response; }