diff --git a/docs/api-chat.mdx b/docs/api-chat.mdx new file mode 100644 index 0000000..92f9c69 --- /dev/null +++ b/docs/api-chat.mdx @@ -0,0 +1,78 @@ +```markdown +# Chat API + +The Chat API allows you to send messages to the AI and receive responses. This endpoint is central to powering conversational experiences in your application. + +## Endpoint + +``` +POST /api/chat +``` + +## Request + +| Field | Type | Required | Description | +|-------------|--------|----------|------------------------------------------| +| message | string | Yes | The message to send to the AI. | +| conversationId | string | No | Optional ID for keeping a conversation thread. | + +### Example Request + +```json +{ + "message": "Hello, how are you?", + "conversationId": "abc123" // optional +} +``` + +## Response + +| Field | Type | Description | +|-------------|--------|-------------------------------------| +| response | string | AI's response to the message. | +| conversationId | string | The ID for the conversation, useful for threading and context retention. | + +### Example Response + +```json +{ + "response": "I'm good! How can I assist you today?", + "conversationId": "abc123" +} +``` + +## Errors + +- `400`: Missing or invalid input properties. +- `401`: Unauthorized. Token missing, expired or invalid. +- `500`: Internal server error. + +## SDK Usage Example + +If you're using the KiloCode SDK, you can access this functionality as follows: + +```typescript +import { KiloCodeSDK } from './sdk'; // adjust the import path as needed + +const sdk = new KiloCodeSDK('http://localhost:3000'); // use your API base URL + +async function chatWithAI() { + const userMessage = "Hello, how are you?"; + const response = await sdk.chat.sendMessage(userMessage, "abc123"); // conversationId is optional + if (response) { + console.log('AI says:', response.response); + } else { + console.error('Failed to get AI response.'); + } +} + +chatWithAI(); +``` + +## Notes + +- Use the same `conversationId` for sequential messages if you want the AI to remember previous messages in the conversation. +- For stateless interactions, omit the `conversationId`. + +--- +``` \ No newline at end of file diff --git a/docs/chat-interface.mdx b/docs/chat-interface.mdx index b299830..6d509ec 100644 --- a/docs/chat-interface.mdx +++ b/docs/chat-interface.mdx @@ -32,6 +32,35 @@ export default function YourComponent() { } ``` +## SDK Integration + +You can also interact with the chat backend programmatically using the provided SDK. + +For example, to send a message and receive an AI response: + +```typescript +import { KiloCodeSDK } from '../sdk'; + +const sdk = new KiloCodeSDK('http://localhost:3000'); + +async function sendMessage() { + const response = await sdk.chat.sendMessage("Hello, AI!"); + if (response) { + console.log("AI Response:", response.response); + } else { + console.error("Failed to get AI response."); + } +} + +sendMessage(); +``` + +> Make sure the `sdk` directory is added to your project and the API base URL matches your deployment. + ## Customization The chat interface can be customized through props and CSS styling. See the component documentation for available options. + +--- + +For more advanced usage such as user authentication, notification, and settings management, refer to the [SDK documentation](../sdk/README.md). \ No newline at end of file