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
113 changes: 113 additions & 0 deletions rkix-studio/src/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# RKix Studio API Endpoints

All endpoints use Zite backend SDK with Zod validation.

## Chat Management

### `createChat.ts`
Create a new chat.
- **Input**: `{ title?: string }`
- **Output**: `{ id, title, createdAt }`

### `getChats.ts`
Retrieve all chats sorted by creation date (newest first).
- **Input**: `{}`
- **Output**: `{ chats: [{ id, title, createdAt }] }`
- **Limit**: 50 chats

### `updateChat.ts`
Update a chat's title.
- **Input**: `{ chatId: string, title: string }`
- **Output**: `{ id, title, createdAt }`

### `deleteChat.ts`
Delete a chat and all associated messages.
- **Input**: `{ chatId: string }`
- **Output**: `{ success: boolean }`

### `createChatWithAI.ts`
Create a chat and send an initial message in one operation.
- **Input**: `{ title?: string, initialMessage: string }`
- **Output**: `{ chatId, title, messageId, createdAt }`

## Message Management

### `createMessage.ts`
Create a new message in a chat.
- **Input**: `{ chatId: string, content: string, role?: string }`
- **Output**: `{ id, content, role, createdAt }`
- **Roles**: 'User', 'Assistant', or custom

### `getMessages.ts`
Retrieve all messages for a chat, sorted chronologically (oldest first).
- **Input**: `{ chatId: string }`
- **Output**: `{ messages: [{ id, content, role, createdAt }] }`
- **Limit**: 200 messages

## Task Management

### `createTask.ts`
Create a new task.
- **Input**: `{ title: string, context?: string, status?: string }`
- **Output**: `{ id, title, status, context, createdAt }`
- **Default Status**: 'Queued'

### `getTasks.ts`
Retrieve all tasks, optionally filtered by status.
- **Input**: `{ status?: string }`
- **Output**: `{ tasks: [{ id, title, status, context, log, filesChanged, createdAt }] }`
- **Limit**: 100 tasks
- **Sorting**: Newest first

### `getTask.ts`
Retrieve a single task by ID.
- **Input**: `{ taskId: string }`
- **Output**: `{ id, title, status, context, log, filesChanged, createdAt }`

### `updateTask.ts`
Update task fields (status, log, filesChanged).
- **Input**: `{ taskId: string, status?: string, log?: string, filesChanged?: string }`
- **Output**: `{ id, title, status, context, log, filesChanged, createdAt }`

### `deleteTask.ts`
Delete a task.
- **Input**: `{ taskId: string }`
- **Output**: `{ success: boolean }`

## Error Handling

All endpoints include try-catch blocks and return meaningful error messages.

## Data Schema

### Chat
```typescript
{
id: string;
title: string;
createdAt?: string;
}
```

### Message
```typescript
{
id: string;
content: string;
role: string; // 'user' or 'assistant'
createdAt?: string;
}
```

### Task
```typescript
{
id: string;
title: string;
status: string; // 'queued', 'running', 'completed', 'failed'
context?: string;
log?: string;
filesChanged?: string;
createdAt?: string;
}
```
46 changes: 46 additions & 0 deletions rkix-studio/src/api/createChatWithAI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { z } from 'zod';
import { createEndpoint, Chats, Messages } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Create a new chat and send initial message',
inputSchema: z.object({
title: z.string().optional(),
initialMessage: z.string()
}),
outputSchema: z.object({
chatId: z.string(),
title: z.string(),
messageId: z.string(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
// Create chat
const chat = await Chats.create({
record: {
title: input.title || 'New Chat',
createdAt: new Date().toISOString()
}
});

// Create initial message
const message = await Messages.create({
record: {
chat: chat.id,
content: input.initialMessage,
role: 'User',
createdAt: new Date().toISOString()
}
});

return {
chatId: chat.id,
title: chat.title || 'New Chat',
messageId: message.id,
createdAt: chat.createdAt
};
} catch (error) {
throw new Error(`Failed to create chat with AI: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
37 changes: 37 additions & 0 deletions rkix-studio/src/api/createMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { z } from 'zod';
import { createEndpoint, Messages } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Create a new message in a chat',
inputSchema: z.object({
chatId: z.string(),
content: z.string(),
role: z.string().default('User')
}),
outputSchema: z.object({
id: z.string(),
content: z.string(),
role: z.string(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
const message = await Messages.create({
record: {
chat: input.chatId,
content: input.content,
role: input.role,
createdAt: new Date().toISOString()
}
});
return {
id: message.id,
content: message.content || '',
role: (message.role || 'User').toLowerCase(),
createdAt: message.createdAt
};
} catch (error) {
throw new Error(`Failed to create message: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
39 changes: 39 additions & 0 deletions rkix-studio/src/api/createTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { z } from 'zod';
import { createEndpoint, Tasks } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Create a new task',
inputSchema: z.object({
title: z.string(),
context: z.string().optional(),
status: z.string().default('Queued')
}),
outputSchema: z.object({
id: z.string(),
title: z.string(),
status: z.string(),
context: z.string().optional(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
const task = await Tasks.create({
record: {
title: input.title,
context: input.context,
status: input.status || 'Queued',
createdAt: new Date().toISOString()
}
});
return {
id: task.id,
title: task.title || 'Untitled Task',
status: (task.status || 'Queued').toLowerCase(),
context: task.context,
createdAt: task.createdAt
};
} catch (error) {
throw new Error(`Failed to create task: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
16 changes: 16 additions & 0 deletions rkix-studio/src/api/deleteTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from 'zod';
import { createEndpoint, Tasks } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Delete a task',
inputSchema: z.object({ taskId: z.string() }),
outputSchema: z.object({ success: z.boolean() }),
execute: async ({ input }) => {
try {
await Tasks.delete({ id: input.taskId });
return { success: true };
} catch (error) {
throw new Error(`Failed to delete task: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
35 changes: 35 additions & 0 deletions rkix-studio/src/api/getTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { z } from 'zod';
import { createEndpoint, Tasks } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Get a single task by ID',
inputSchema: z.object({ taskId: z.string() }),
outputSchema: z.object({
id: z.string(),
title: z.string(),
status: z.string(),
context: z.string().optional(),
log: z.string().optional(),
filesChanged: z.string().optional(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
const task = await Tasks.findById({ id: input.taskId });
if (!task) {
throw new Error('Task not found');
}
return {
id: task.id,
title: task.title || 'Untitled Task',
status: (task.status || 'Queued').toLowerCase(),
context: task.context,
log: task.log,
filesChanged: task.filesChanged,
createdAt: task.createdAt
};
} catch (error) {
throw new Error(`Failed to fetch task: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
17 changes: 17 additions & 0 deletions rkix-studio/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Chat API Endpoints
export { default as createChat } from './createChat';
export { default as getChats } from './getChats';
export { default as updateChat } from './updateChat';
export { default as deleteChat } from './deleteChat';
export { default as createChatWithAI } from './createChatWithAI';

// Message API Endpoints
export { default as createMessage } from './createMessage';
export { default as getMessages } from './getMessages';

// Task API Endpoints
export { default as createTask } from './createTask';
export { default as getTasks } from './getTasks';
export { default as getTask } from './getTask';
export { default as updateTask } from './updateTask';
export { default as deleteTask } from './deleteTask';
30 changes: 30 additions & 0 deletions rkix-studio/src/api/updateChat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { z } from 'zod';
import { createEndpoint, Chats } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Update a chat title',
inputSchema: z.object({
chatId: z.string(),
title: z.string()
}),
outputSchema: z.object({
id: z.string(),
title: z.string(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
const chat = await Chats.update({
id: input.chatId,
record: { title: input.title }
});
return {
id: chat.id,
title: chat.title || 'New Chat',
createdAt: chat.createdAt
};
} catch (error) {
throw new Error(`Failed to update chat: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});
45 changes: 45 additions & 0 deletions rkix-studio/src/api/updateTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { z } from 'zod';
import { createEndpoint, Tasks } from 'zite-integrations-backend-sdk';

export default createEndpoint({
description: 'Update a task status, log, or other fields',
inputSchema: z.object({
taskId: z.string(),
status: z.string().optional(),
log: z.string().optional(),
filesChanged: z.string().optional()
}),
outputSchema: z.object({
id: z.string(),
title: z.string(),
status: z.string(),
context: z.string().optional(),
log: z.string().optional(),
filesChanged: z.string().optional(),
createdAt: z.string().optional()
}),
execute: async ({ input }) => {
try {
const updateData: Record<string, unknown> = {};
if (input.status) updateData.status = input.status;
if (input.log) updateData.log = input.log;
if (input.filesChanged) updateData.filesChanged = input.filesChanged;

const task = await Tasks.update({
id: input.taskId,
record: updateData
});
return {
id: task.id,
title: task.title || 'Untitled Task',
status: (task.status || 'Queued').toLowerCase(),
context: task.context,
log: task.log,
filesChanged: task.filesChanged,
createdAt: task.createdAt
};
} catch (error) {
throw new Error(`Failed to update task: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
},
});