reorganise types in next.js app

This commit is contained in:
ramnique 2025-02-14 13:36:01 +05:30
parent 2cdc25ab7e
commit 2bafa5be49
46 changed files with 919 additions and 855 deletions

View file

@ -1,5 +1,25 @@
'use server';
import { SimulationData, EmbeddingDoc, GetInformationToolResult, AgenticAPIChatRequest, convertFromAgenticAPIChatMessages, WebpageCrawlResponse, Workflow, WorkflowAgent, CopilotAPIRequest, CopilotAPIResponse, CopilotMessage, CopilotWorkflow, convertToCopilotWorkflow, convertToCopilotApiMessage, convertToCopilotMessage, CopilotAssistantMessage, CopilotChatContext, convertToCopilotApiChatContext, WorkflowTool, WorkflowPrompt, EmbeddingRecord } from "../lib/types";
import { convertToCopilotWorkflow } from "../lib/types/copilot_types";
import { convertFromAgenticAPIChatMessages } from "../lib/types/agents_api_types";
import { convertToCopilotMessage } from "../lib/types/copilot_types";
import { convertToCopilotApiMessage } from "../lib/types/copilot_types";
import { convertToCopilotApiChatContext } from "../lib/types/copilot_types";
import { CopilotAPIResponse } from "../lib/types/copilot_types";
import { CopilotAPIRequest } from "../lib/types/copilot_types";
import { CopilotChatContext } from "../lib/types/copilot_types";
import { CopilotMessage } from "../lib/types/copilot_types";
import { CopilotAssistantMessage } from "../lib/types/copilot_types";
import { AgenticAPIChatRequest } from "../lib/types/agents_api_types";
import { CopilotWorkflow } from "../lib/types/copilot_types";
import { Workflow } from "../lib/types/workflow_types";
import { WorkflowTool } from "../lib/types/workflow_types";
import { WorkflowPrompt } from "../lib/types/workflow_types";
import { WorkflowAgent } from "../lib/types/workflow_types";
import { EmbeddingRecord } from "../lib/types/datasource_types";
import { WebpageCrawlResponse } from "../lib/types/tool_types";
import { GetInformationToolResult } from "../lib/types/tool_types";
import { EmbeddingDoc } from "../lib/types/datasource_types";
import { SimulationData } from "../lib/types/testing_types";
import { generateObject, generateText, embed } from "ai";
import { dataSourceDocsCollection, dataSourcesCollection, embeddingsCollection, webpagesCollection } from "../lib/mongodb";
import { z } from 'zod';

View file

@ -6,7 +6,9 @@ import { z } from 'zod';
import { GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { projectAuthCheck } from "./project_actions";
import { DataSource, DataSourceDoc, WithStringId } from "../lib/types";
import { WithStringId } from "../lib/types/types";
import { DataSourceDoc } from "../lib/types/datasource_types";
import { DataSource } from "../lib/types/datasource_types";
import { uploadsS3Client } from "../lib/uploads_s3_client";
export async function getDataSource(projectId: string, sourceId: string): Promise<WithStringId<z.infer<typeof DataSource>>> {

View file

@ -7,7 +7,9 @@ import crypto from 'crypto';
import { revalidatePath } from "next/cache";
import { templates } from "../lib/project_templates";
import { authCheck } from "./actions";
import { ApiKey, WithStringId, Project } from "../lib/types";
import { WithStringId } from "../lib/types/types";
import { ApiKey } from "../lib/types/project_types";
import { Project } from "../lib/types/project_types";
export async function projectAuthCheck(projectId: string) {
const user = await authCheck();

View file

@ -2,7 +2,8 @@
import { ObjectId } from "mongodb";
import { scenariosCollection } from "../lib/mongodb";
import { z } from 'zod';
import { Scenario, WithStringId } from "../lib/types";
import { WithStringId } from "../lib/types/types";
import { Scenario } from "../lib/types/testing_types";
import { projectAuthCheck } from "./project_actions";
export async function getScenarios(projectId: string): Promise<WithStringId<z.infer<typeof Scenario>>[]> {

View file

@ -4,8 +4,9 @@ import { ObjectId } from "mongodb";
import { scenariosCollection } from "../lib/mongodb";
import { z } from 'zod';
import { projectAuthCheck } from "./project_actions";
import { Scenario, type WithStringId } from "../lib/types";
import { SimulationScenarioData } from "../lib/types";
import { type WithStringId } from "../lib/types/types";
import { Scenario } from "../lib/types/testing_types";
import { SimulationScenarioData } from "../lib/types/testing_types";
export async function getScenarios(projectId: string): Promise<WithStringId<z.infer<typeof Scenario>>[]> {
await projectAuthCheck(projectId);

View file

@ -4,7 +4,8 @@ import { projectsCollection, agentWorkflowsCollection } from "../lib/mongodb";
import { z } from 'zod';
import { templates } from "../lib/project_templates";
import { projectAuthCheck } from "./project_actions";
import { Workflow, WithStringId } from "../lib/types";
import { WithStringId } from "../lib/types/types";
import { Workflow } from "../lib/types/workflow_types";
export async function createWorkflow(projectId: string): Promise<WithStringId<z.infer<typeof Workflow>>> {
await projectAuthCheck(projectId);

View file

@ -3,7 +3,11 @@ import { agentWorkflowsCollection, db, projectsCollection } from "../../../../li
import { z } from "zod";
import { ObjectId } from "mongodb";
import { authCheck } from "../../utils";
import { convertFromApiToAgenticApiMessages, convertFromAgenticApiToApiMessages, AgenticAPIChatRequest, ApiRequest, ApiResponse, convertWorkflowToAgenticAPI } from "../../../../lib/types";
import { ApiRequest, ApiResponse } from "../../../../lib/types/types";
import { convertFromAgenticApiToApiMessages } from "../../../../lib/types/agents_api_types";
import { convertFromApiToAgenticApiMessages } from "../../../../lib/types/agents_api_types";
import { convertWorkflowToAgenticAPI } from "../../../../lib/types/agents_api_types";
import { AgenticAPIChatRequest } from "../../../../lib/types/agents_api_types";
import { getAgenticApiResponse } from "../../../../lib/utils";
import { check_query_limit } from "../../../../lib/rate_limiting";

View file

@ -4,7 +4,10 @@ import { agentWorkflowsCollection, db, projectsCollection } from "../../../../..
import { z } from "zod";
import { ObjectId, WithId } from "mongodb";
import { authCheck } from "../../../utils";
import { AgenticAPIChatRequest, convertFromAgenticAPIChatMessages, convertToAgenticAPIChatMessages, convertWorkflowToAgenticAPI } from "../../../../../../lib/types";
import { convertFromAgenticAPIChatMessages } from "../../../../../../lib/types/agents_api_types";
import { convertToAgenticAPIChatMessages } from "../../../../../../lib/types/agents_api_types";
import { convertWorkflowToAgenticAPI } from "../../../../../../lib/types/agents_api_types";
import { AgenticAPIChatRequest } from "../../../../../../lib/types/agents_api_types";
import { callClientToolWebhook, getAgenticApiResponse } from "../../../../../../lib/utils";
import { check_query_limit } from "../../../../../../lib/rate_limiting";

View file

@ -1,5 +1,13 @@
import { MongoClient } from "mongodb";
import { PlaygroundChat, DataSource, EmbeddingDoc, Project, Webpage, ChatClientId, Workflow, Scenario, ProjectMember, ApiKey, DataSourceDoc } from "./types";
import { PlaygroundChat, Webpage, ChatClientId } from "./types/types";
import { Workflow } from "./types/workflow_types";
import { ApiKey } from "./types/project_types";
import { ProjectMember } from "./types/project_types";
import { Project } from "./types/project_types";
import { EmbeddingDoc } from "./types/datasource_types";
import { DataSourceDoc } from "./types/datasource_types";
import { DataSource } from "./types/datasource_types";
import { Scenario } from "./types/testing_types";
import { z } from 'zod';
const client = new MongoClient(process.env["MONGODB_CONNECTION_STRING"] || "mongodb://localhost:27017");

View file

@ -1,4 +1,4 @@
import { WorkflowTemplate } from './types';
import { WorkflowTemplate } from "./types/workflow_types";
import { z } from 'zod';
export const templates: { [key: string]: z.infer<typeof WorkflowTemplate> } = {

View file

@ -1,817 +0,0 @@
import { CoreMessage, ToolCallPart } from "ai";
import { z } from "zod";
import { apiV1 } from "rowboat-shared";
export const SimulationArticleData = z.object({
articleUrl: z.string(),
articleTitle: z.string().default('').optional(),
articleContent: z.string().default('').optional(),
});
export const Scenario = z.object({
projectId: z.string(),
name: z.string().min(1, "Name cannot be empty"),
description: z.string().min(1, "Description cannot be empty"),
context: z.string().default(''),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
});
export const SimulationScenarioData = z.object({
scenario: z.string(),
context: z.string().default(''),
});
export const SimulationChatMessagesData = z.object({
chatMessages: z.string(),
});
export const SimulationData = z.union([SimulationArticleData, SimulationScenarioData, SimulationChatMessagesData]);
export const PlaygroundChat = z.object({
createdAt: z.string().datetime(),
projectId: z.string(),
title: z.string().optional(),
messages: z.array(apiV1.ChatMessage),
simulated: z.boolean().default(false).optional(),
simulationData: SimulationData.optional(),
simulationComplete: z.boolean().default(false).optional(),
agenticState: z.unknown().optional(),
systemMessage: z.string().optional(),
});
export const Webpage = z.object({
_id: z.string(),
title: z.string(),
contentSimple: z.string(),
lastUpdatedAt: z.string().datetime(),
});
export const ChatClientId = z.object({
_id: z.string(),
projectId: z.string(),
});
export const DataSource = z.object({
name: z.string(),
projectId: z.string(),
active: z.boolean().default(true),
status: z.union([
z.literal('pending'),
z.literal('ready'),
z.literal('error'),
z.literal('deleted'),
]),
version: z.number(),
error: z.string().optional(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime().optional(),
attempts: z.number(),
lastAttemptAt: z.string().datetime().optional(),
pendingRefresh: z.boolean().default(false).optional(),
data: z.discriminatedUnion('type', [
z.object({
type: z.literal('urls'),
}),
z.object({
type: z.literal('files'),
}),
]),
});
export const DataSourceDoc = z.object({
sourceId: z.string(),
name: z.string(),
version: z.number(),
status: z.union([
z.literal('pending'),
z.literal('ready'),
z.literal('error'),
z.literal('deleted'),
]),
content: z.string().optional(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime().optional(),
error: z.string().optional(),
data: z.discriminatedUnion('type', [
z.object({
type: z.literal('url'),
url: z.string(),
}),
z.object({
type: z.literal('file'),
name: z.string(),
size: z.number(),
mimeType: z.string(),
s3Key: z.string(),
}),
]),
})
export const EmbeddingDoc = z.object({
content: z.string(),
sourceId: z.string(),
embeddings: z.array(z.number()),
metadata: z.object({
sourceURL: z.string(),
title: z.string(),
score: z.number().optional(),
}),
});
export const Project = z.object({
_id: z.string().uuid(),
name: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
createdByUserId: z.string(),
secret: z.string(),
chatClientId: z.string(),
webhookUrl: z.string().optional(),
publishedWorkflowId: z.string().optional(),
nextWorkflowNumber: z.number().optional(),
});
export const ProjectMember = z.object({
userId: z.string(),
projectId: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
});
export const ApiKey = z.object({
projectId: z.string(),
key: z.string(),
createdAt: z.string().datetime(),
lastUsedAt: z.string().datetime().optional(),
});
export const GetInformationToolResultItem = z.object({
title: z.string(),
name: z.string(),
content: z.string(),
docId: z.string(),
sourceId: z.string(),
});
export const GetInformationToolResult = z.object({
results: z.array(GetInformationToolResultItem)
});
export const WebpageCrawlResponse = z.object({
title: z.string(),
content: z.string(),
});
export const AgenticAPIChatMessage = z.object({
role: z.union([z.literal('user'), z.literal('assistant'), z.literal('tool'), z.literal('system')]),
content: z.string().nullable(),
tool_calls: z.array(z.object({
id: z.string(),
function: z.object({
name: z.string(),
arguments: z.string(),
}),
type: z.literal('function'),
})).nullable(),
tool_call_id: z.string().nullable(),
tool_name: z.string().nullable(),
sender: z.string().nullable(),
response_type: z.union([
z.literal('internal'),
z.literal('external'),
]).optional(),
});
export const EmbeddingRecord = z.object({
id: z.string().uuid(),
vector: z.array(z.number()),
payload: z.object({
projectId: z.string(),
sourceId: z.string(),
docId: z.string(),
content: z.string(),
title: z.string(),
name: z.string(),
}),
});
export const WorkflowAgent = z.object({
name: z.string(),
type: z.union([
z.literal('conversation'),
z.literal('post_process'),
z.literal('escalation'),
]),
description: z.string(),
disabled: z.boolean().default(false).optional(),
instructions: z.string(),
examples: z.string().optional(),
prompts: z.array(z.string()),
tools: z.array(z.string()),
model: z.union([
z.literal('gpt-4o'),
z.literal('gpt-4o-mini'),
]),
locked: z.boolean().default(false).describe('Whether this agent is locked and cannot be deleted').optional(),
toggleAble: z.boolean().default(true).describe('Whether this agent can be enabled or disabled').optional(),
global: z.boolean().default(false).describe('Whether this agent is a global agent, in which case it cannot be connected to other agents').optional(),
ragDataSources: z.array(z.string()).optional(),
ragReturnType: z.union([z.literal('chunks'), z.literal('content')]).default('chunks'),
ragK: z.number().default(3),
connectedAgents: z.array(z.string()),
controlType: z.union([z.literal('retain'), z.literal('relinquish_to_parent'), z.literal('relinquish_to_start')]).default('retain').describe('Whether this agent retains control after a turn, relinquishes to the parent agent, or relinquishes to the start agent'),
});
export const WorkflowPrompt = z.object({
name: z.string(),
type: z.union([
z.literal('base_prompt'),
z.literal('style_prompt'),
]),
prompt: z.string(),
});
export const WorkflowTool = z.object({
name: z.string(),
description: z.string(),
mockInPlayground: z.boolean().default(false).optional(),
autoSubmitMockedResponse: z.boolean().default(false).optional(),
parameters: z.object({
type: z.literal('object'),
properties: z.record(z.object({
type: z.string(),
description: z.string(),
})),
required: z.array(z.string()).optional(),
}),
});
export const AgenticAPIAgent = WorkflowAgent
.omit({
disabled: true,
examples: true,
prompts: true,
locked: true,
toggleAble: true,
global: true,
ragDataSources: true,
ragReturnType: true,
ragK: true,
})
.extend({
hasRagSources: z.boolean().default(false).optional(),
});
export const AgenticAPIPrompt = WorkflowPrompt;
export const AgenticAPITool = WorkflowTool.omit({
mockInPlayground: true,
autoSubmitMockedResponse: true,
});
export const Workflow = z.object({
name: z.string().optional(),
agents: z.array(WorkflowAgent),
prompts: z.array(WorkflowPrompt),
tools: z.array(WorkflowTool),
startAgent: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
projectId: z.string(),
});
export const WorkflowTemplate = Workflow
.omit({
projectId: true,
lastUpdatedAt: true,
createdAt: true,
})
.extend({
name: z.string(),
description: z.string(),
});
export type WithStringId<T> = T & { _id: string };
export const CopilotWorkflow = Workflow.omit({
lastUpdatedAt: true,
projectId: true,
});
export const AgenticAPIChatRequest = z.object({
messages: z.array(AgenticAPIChatMessage),
state: z.unknown(),
agents: z.array(AgenticAPIAgent),
tools: z.array(AgenticAPITool),
prompts: z.array(WorkflowPrompt),
startAgent: z.string(),
});
export const AgenticAPIChatResponse = z.object({
messages: z.array(AgenticAPIChatMessage),
state: z.unknown(),
});
export const CopilotUserMessage = z.object({
role: z.literal('user'),
content: z.string(),
});
export const CopilotAssistantMessageTextPart = z.object({
type: z.literal("text"),
content: z.string(),
});
export const CopilotAssistantMessageActionPart = z.object({
type: z.literal("action"),
content: z.object({
config_type: z.union([z.literal('tool'), z.literal('agent'), z.literal('prompt')]),
action: z.union([z.literal('create_new'), z.literal('edit')]),
name: z.string(),
change_description: z.string(),
config_changes: z.record(z.string(), z.unknown()),
error: z.string().optional(),
})
});
export const CopilotAssistantMessage = z.object({
role: z.literal('assistant'),
content: z.object({
thoughts: z.string().optional(),
response: z.array(z.union([CopilotAssistantMessageTextPart, CopilotAssistantMessageActionPart])),
}),
});
export const CopilotMessage = z.union([CopilotUserMessage, CopilotAssistantMessage]);
export const CopilotApiMessage = z.object({
role: z.union([z.literal('assistant'), z.literal('user')]),
content: z.string(),
});
export const CopilotChatContext = z.union([
z.object({
type: z.literal('chat'),
messages: z.array(apiV1.ChatMessage),
}),
z.object({
type: z.literal('agent'),
name: z.string(),
}),
z.object({
type: z.literal('tool'),
name: z.string(),
}),
z.object({
type: z.literal('prompt'),
name: z.string(),
}),
]);
export const CopilotApiChatContext = z.union([
z.object({
type: z.literal('chat'),
messages: z.array(AgenticAPIChatMessage),
}),
z.object({
type: z.literal('agent'),
agentName: z.string(),
}),
z.object({
type: z.literal('tool'),
toolName: z.string(),
}),
z.object({
type: z.literal('prompt'),
promptName: z.string(),
}),
]);
export const CopilotAPIRequest = z.object({
messages: z.array(CopilotApiMessage),
workflow_schema: z.string(),
current_workflow_config: z.string(),
context: CopilotApiChatContext.nullable(),
});
export const CopilotAPIResponse = z.union([
z.object({
response: z.string(),
}),
z.object({
error: z.string(),
}),
]);
export const ClientToolCallRequestBody = z.object({
toolCall: apiV1.AssistantMessageWithToolCalls.shape.tool_calls.element,
});
export const ClientToolCallJwt = z.object({
requestId: z.string().uuid(),
projectId: z.string(),
bodyHash: z.string(),
iat: z.number(),
exp: z.number(),
});
export const ClientToolCallRequest = z.object({
requestId: z.string().uuid(),
content: z.string(), // json stringified ClientToolCallRequestBody
});
export const ClientToolCallResponse = z.unknown();
export function convertToCopilotApiChatContext(context: z.infer<typeof CopilotChatContext>): z.infer<typeof CopilotApiChatContext> {
switch (context.type) {
case 'chat':
return {
type: 'chat',
messages: convertToAgenticAPIChatMessages(context.messages),
};
case 'agent':
return {
type: 'agent',
agentName: context.name,
};
case 'tool':
return {
type: 'tool',
toolName: context.name,
};
case 'prompt':
return {
type: 'prompt',
promptName: context.name,
};
}
}
export function convertToCopilotApiMessage(message: z.infer<typeof CopilotMessage>): z.infer<typeof CopilotApiMessage> {
return {
role: message.role,
content: JSON.stringify(message.content),
};
}
export function convertToCopilotMessage(message: z.infer<typeof CopilotApiMessage>): z.infer<typeof CopilotMessage> {
switch (message.role) {
case 'assistant':
return CopilotAssistantMessage.parse({
role: 'assistant',
content: JSON.parse(message.content),
});
case 'user':
return {
role: 'user',
content: message.content,
};
default:
throw new Error(`Unknown role: ${message.role}`);
}
}
export function convertWorkflowToAgenticAPI(workflow: z.infer<typeof Workflow>): {
agents: z.infer<typeof AgenticAPIAgent>[],
tools: z.infer<typeof AgenticAPITool>[],
prompts: z.infer<typeof AgenticAPIPrompt>[],
startAgent: string,
} {
return {
agents: workflow.agents
.filter(agent => !agent.disabled)
.map(agent => ({
name: agent.name,
type: agent.type,
description: agent.description,
instructions: agent.instructions +
'\n\n' + agent.prompts.map(prompt =>
workflow.prompts.find(p => p.name === prompt)?.prompt
).join('\n\n') +
(agent.examples ? '\n\n# Examples\n' + agent.examples : ''),
tools: agent.tools,
model: agent.model,
hasRagSources: agent.ragDataSources ? agent.ragDataSources.length > 0 : false,
connectedAgents: agent.connectedAgents,
controlType: agent.controlType,
})),
tools: workflow.tools.map(tool => {
const { mockInPlayground, autoSubmitMockedResponse, ...rest } = tool;
return {
...rest,
};
}),
prompts: workflow.prompts,
startAgent: workflow.startAgent,
};
}
export function convertToCoreMessages(messages: z.infer<typeof apiV1.ChatMessage>[]): CoreMessage[] {
// convert to core messages
const coreMessages: CoreMessage[] = [];
for (const m of messages) {
switch (m.role) {
case 'system':
coreMessages.push({
role: 'system',
content: m.content,
});
break;
case 'user':
coreMessages.push({
role: 'user',
content: m.content,
});
break;
case 'assistant':
if ('tool_calls' in m) {
const toolCallParts: ToolCallPart[] = m.tool_calls.map((toolCall) => ({
type: 'tool-call',
toolCallId: toolCall.id,
toolName: toolCall.function.name,
args: JSON.parse(toolCall.function.arguments),
}));
if (m.content) {
coreMessages.push({
role: 'assistant',
content: [
{
type: 'text',
text: m.content,
},
...toolCallParts,
]
});
} else {
coreMessages.push({
role: 'assistant',
content: toolCallParts,
});
}
} else {
coreMessages.push({
role: 'assistant',
content: m.content,
});
}
break;
case 'tool':
coreMessages.push({
role: 'tool',
content: [
{
type: 'tool-result',
toolCallId: m.tool_call_id,
toolName: m.tool_name,
result: JSON.parse(m.content),
}
]
});
break;
}
}
return coreMessages;
}
export function convertToAgenticAPIChatMessages(messages: z.infer<typeof apiV1.ChatMessage>[]): z.infer<typeof AgenticAPIChatMessage>[] {
const converted: z.infer<typeof AgenticAPIChatMessage>[] = [];
for (const m of messages) {
const baseMessage: z.infer<typeof AgenticAPIChatMessage> = {
content: null,
role: m.role,
sender: null,
tool_calls: null,
tool_call_id: null,
tool_name: null,
};
switch (m.role) {
case 'system':
converted.push({
...baseMessage,
content: m.content,
});
break;
case 'user':
converted.push({
...baseMessage,
content: m.content,
});
break;
case 'assistant':
if ('tool_calls' in m) {
converted.push({
...baseMessage,
tool_calls: m.tool_calls,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType,
});
} else {
converted.push({
...baseMessage,
content: m.content,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType,
});
}
break;
case 'tool':
converted.push({
...baseMessage,
content: m.content,
tool_call_id: m.tool_call_id,
tool_name: m.tool_name,
});
break;
default:
continue;
}
}
return converted;
}
export function convertFromAgenticAPIChatMessages(messages: z.infer<typeof AgenticAPIChatMessage>[]): z.infer<typeof apiV1.ChatMessage>[] {
const converted: z.infer<typeof apiV1.ChatMessage>[] = [];
for (const m of messages) {
const baseMessage = {
version: 'v1' as const,
chatId: '',
createdAt: new Date().toISOString(),
};
switch (m.role) {
case 'user':
converted.push({
...baseMessage,
role: 'user',
content: m.content ?? '',
});
break;
case 'assistant':
if (m.tool_calls) {
// TODO: handle tool calls
converted.push({
...baseMessage,
role: 'assistant',
tool_calls: m.tool_calls,
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
} else {
converted.push({
...baseMessage,
role: 'assistant',
content: m.content ?? '',
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
}
break;
case 'tool':
converted.push({
...baseMessage,
role: 'tool',
content: m.content ?? '',
tool_call_id: m.tool_call_id ?? '',
tool_name: m.tool_name ?? '',
});
break;
}
}
return converted;
}
export function convertToCopilotWorkflow(workflow: z.infer<typeof Workflow>): z.infer<typeof CopilotWorkflow> {
const { lastUpdatedAt, projectId, ...rest } = workflow;
return {
...rest,
};
}
export const ApiMessage = z.union([
apiV1.SystemMessage,
apiV1.UserMessage,
apiV1.AssistantMessage,
apiV1.AssistantMessageWithToolCalls,
apiV1.ToolMessage,
]);
export const ApiRequest = z.object({
messages: z.array(ApiMessage),
state: z.unknown(),
});
export const ApiResponse = z.object({
messages: z.array(ApiMessage),
state: z.unknown(),
});
export function convertFromApiToAgenticApiMessages(messages: z.infer<typeof ApiMessage>[]): z.infer<typeof AgenticAPIChatMessage>[] {
return messages.map(m => {
switch (m.role) {
case 'system':
return {
role: 'system',
content: m.content,
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
};
case 'user':
return {
role: 'user',
content: m.content,
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
};
case 'assistant':
if ('tool_calls' in m) {
return {
role: 'assistant',
content: m.content ?? null,
tool_calls: m.tool_calls,
tool_call_id: null,
tool_name: null,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType ?? 'external',
};
} else {
return {
role: 'assistant',
content: m.content ?? null,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType ?? 'external',
tool_call_id: null,
tool_calls: null,
tool_name: null,
};
}
case 'tool':
return {
role: 'tool',
content: m.content ?? null,
tool_calls: null,
tool_call_id: m.tool_call_id ?? null,
tool_name: m.tool_name ?? null,
sender: null,
};
default:
return {
role: "user",
content: "foo",
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
}
}
});
}
export function convertFromAgenticApiToApiMessages(messages: z.infer<typeof AgenticAPIChatMessage>[]): z.infer<typeof ApiMessage>[] {
const converted: z.infer<typeof ApiMessage>[] = [];
for (const m of messages) {
switch (m.role) {
case 'user':
converted.push({
role: 'user',
content: m.content ?? '',
});
break;
case 'assistant':
if (m.tool_calls) {
converted.push({
role: 'assistant',
tool_calls: m.tool_calls,
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
} else {
converted.push({
role: 'assistant',
content: m.content ?? '',
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
}
break;
case 'tool':
converted.push({
role: 'tool',
content: m.content ?? '',
tool_call_id: m.tool_call_id ?? '',
tool_name: m.tool_name ?? '',
});
break;
}
}
return converted;
}

View file

@ -0,0 +1,302 @@
import { z } from "zod";
import { Workflow, WorkflowAgent, WorkflowPrompt, WorkflowTool } from "./workflow_types";
import { apiV1 } from "rowboat-shared";
import { ApiMessage } from "./types";
export const AgenticAPIChatMessage = z.object({
role: z.union([z.literal('user'), z.literal('assistant'), z.literal('tool'), z.literal('system')]),
content: z.string().nullable(),
tool_calls: z.array(z.object({
id: z.string(),
function: z.object({
name: z.string(),
arguments: z.string(),
}),
type: z.literal('function'),
})).nullable(),
tool_call_id: z.string().nullable(),
tool_name: z.string().nullable(),
sender: z.string().nullable(),
response_type: z.union([
z.literal('internal'),
z.literal('external'),
]).optional(),
});export const AgenticAPIAgent = WorkflowAgent
.omit({
disabled: true,
examples: true,
prompts: true,
locked: true,
toggleAble: true,
global: true,
ragDataSources: true,
ragReturnType: true,
ragK: true,
})
.extend({
hasRagSources: z.boolean().default(false).optional(),
});
export const AgenticAPIPrompt = WorkflowPrompt;
export const AgenticAPITool = WorkflowTool.omit({
mockInPlayground: true,
autoSubmitMockedResponse: true,
});
export const AgenticAPIChatRequest = z.object({
messages: z.array(AgenticAPIChatMessage),
state: z.unknown(),
agents: z.array(AgenticAPIAgent),
tools: z.array(AgenticAPITool),
prompts: z.array(WorkflowPrompt),
startAgent: z.string(),
});
export const AgenticAPIChatResponse = z.object({
messages: z.array(AgenticAPIChatMessage),
state: z.unknown(),
});
export function convertWorkflowToAgenticAPI(workflow: z.infer<typeof Workflow>): {
agents: z.infer<typeof AgenticAPIAgent>[];
tools: z.infer<typeof AgenticAPITool>[];
prompts: z.infer<typeof AgenticAPIPrompt>[];
startAgent: string;
} {
return {
agents: workflow.agents
.filter(agent => !agent.disabled)
.map(agent => ({
name: agent.name,
type: agent.type,
description: agent.description,
instructions: agent.instructions +
'\n\n' + agent.prompts.map(prompt => workflow.prompts.find(p => p.name === prompt)?.prompt
).join('\n\n') +
(agent.examples ? '\n\n# Examples\n' + agent.examples : ''),
tools: agent.tools,
model: agent.model,
hasRagSources: agent.ragDataSources ? agent.ragDataSources.length > 0 : false,
connectedAgents: agent.connectedAgents,
controlType: agent.controlType,
})),
tools: workflow.tools.map(tool => {
const { mockInPlayground, autoSubmitMockedResponse, ...rest } = tool;
return {
...rest,
};
}),
prompts: workflow.prompts,
startAgent: workflow.startAgent,
};
}
export function convertToAgenticAPIChatMessages(messages: z.infer<typeof apiV1.ChatMessage>[]): z.infer<typeof AgenticAPIChatMessage>[] {
const converted: z.infer<typeof AgenticAPIChatMessage>[] = [];
for (const m of messages) {
const baseMessage: z.infer<typeof AgenticAPIChatMessage> = {
content: null,
role: m.role,
sender: null,
tool_calls: null,
tool_call_id: null,
tool_name: null,
};
switch (m.role) {
case 'system':
converted.push({
...baseMessage,
content: m.content,
});
break;
case 'user':
converted.push({
...baseMessage,
content: m.content,
});
break;
case 'assistant':
if ('tool_calls' in m) {
converted.push({
...baseMessage,
tool_calls: m.tool_calls,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType,
});
} else {
converted.push({
...baseMessage,
content: m.content,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType,
});
}
break;
case 'tool':
converted.push({
...baseMessage,
content: m.content,
tool_call_id: m.tool_call_id,
tool_name: m.tool_name,
});
break;
default:
continue;
}
}
return converted;
}
export function convertFromAgenticAPIChatMessages(messages: z.infer<typeof AgenticAPIChatMessage>[]): z.infer<typeof apiV1.ChatMessage>[] {
const converted: z.infer<typeof apiV1.ChatMessage>[] = [];
for (const m of messages) {
const baseMessage = {
version: 'v1' as const,
chatId: '',
createdAt: new Date().toISOString(),
};
switch (m.role) {
case 'user':
converted.push({
...baseMessage,
role: 'user',
content: m.content ?? '',
});
break;
case 'assistant':
if (m.tool_calls) {
// TODO: handle tool calls
converted.push({
...baseMessage,
role: 'assistant',
tool_calls: m.tool_calls,
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
} else {
converted.push({
...baseMessage,
role: 'assistant',
content: m.content ?? '',
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
}
break;
case 'tool':
converted.push({
...baseMessage,
role: 'tool',
content: m.content ?? '',
tool_call_id: m.tool_call_id ?? '',
tool_name: m.tool_name ?? '',
});
break;
}
}
return converted;
}
export function convertFromApiToAgenticApiMessages(messages: z.infer<typeof ApiMessage>[]): z.infer<typeof AgenticAPIChatMessage>[] {
return messages.map(m => {
switch (m.role) {
case 'system':
return {
role: 'system',
content: m.content,
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
};
case 'user':
return {
role: 'user',
content: m.content,
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
};
case 'assistant':
if ('tool_calls' in m) {
return {
role: 'assistant',
content: m.content ?? null,
tool_calls: m.tool_calls,
tool_call_id: null,
tool_name: null,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType ?? 'external',
};
} else {
return {
role: 'assistant',
content: m.content ?? null,
sender: m.agenticSender ?? null,
response_type: m.agenticResponseType ?? 'external',
tool_call_id: null,
tool_calls: null,
tool_name: null,
};
}
case 'tool':
return {
role: 'tool',
content: m.content ?? null,
tool_calls: null,
tool_call_id: m.tool_call_id ?? null,
tool_name: m.tool_name ?? null,
sender: null,
};
default:
return {
role: "user",
content: "foo",
tool_calls: null,
tool_call_id: null,
tool_name: null,
sender: null,
};
}
});
}
export function convertFromAgenticApiToApiMessages(messages: z.infer<typeof AgenticAPIChatMessage>[]): z.infer<typeof ApiMessage>[] {
const converted: z.infer<typeof ApiMessage>[] = [];
for (const m of messages) {
switch (m.role) {
case 'user':
converted.push({
role: 'user',
content: m.content ?? '',
});
break;
case 'assistant':
if (m.tool_calls) {
converted.push({
role: 'assistant',
tool_calls: m.tool_calls,
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
} else {
converted.push({
role: 'assistant',
content: m.content ?? '',
agenticSender: m.sender ?? undefined,
agenticResponseType: m.response_type ?? 'internal',
});
}
break;
case 'tool':
converted.push({
role: 'tool',
content: m.content ?? '',
tool_call_id: m.tool_call_id ?? '',
tool_name: m.tool_name ?? '',
});
break;
}
}
return converted;
}

View file

@ -0,0 +1,144 @@
import { z } from "zod";
import { Workflow } from "./workflow_types";
import { apiV1 } from "rowboat-shared"
import { AgenticAPIChatMessage } from "./agents_api_types";
import { convertToAgenticAPIChatMessages } from "./agents_api_types";
export const CopilotWorkflow = Workflow.omit({
lastUpdatedAt: true,
projectId: true,
});export const CopilotUserMessage = z.object({
role: z.literal('user'),
content: z.string(),
});
export const CopilotAssistantMessageTextPart = z.object({
type: z.literal("text"),
content: z.string(),
});
export const CopilotAssistantMessageActionPart = z.object({
type: z.literal("action"),
content: z.object({
config_type: z.union([z.literal('tool'), z.literal('agent'), z.literal('prompt')]),
action: z.union([z.literal('create_new'), z.literal('edit')]),
name: z.string(),
change_description: z.string(),
config_changes: z.record(z.string(), z.unknown()),
error: z.string().optional(),
})
});
export const CopilotAssistantMessage = z.object({
role: z.literal('assistant'),
content: z.object({
thoughts: z.string().optional(),
response: z.array(z.union([CopilotAssistantMessageTextPart, CopilotAssistantMessageActionPart])),
}),
});
export const CopilotMessage = z.union([CopilotUserMessage, CopilotAssistantMessage]);
export const CopilotApiMessage = z.object({
role: z.union([z.literal('assistant'), z.literal('user')]),
content: z.string(),
});
export const CopilotChatContext = z.union([
z.object({
type: z.literal('chat'),
messages: z.array(apiV1.ChatMessage),
}),
z.object({
type: z.literal('agent'),
name: z.string(),
}),
z.object({
type: z.literal('tool'),
name: z.string(),
}),
z.object({
type: z.literal('prompt'),
name: z.string(),
}),
]);
export const CopilotApiChatContext = z.union([
z.object({
type: z.literal('chat'),
messages: z.array(AgenticAPIChatMessage),
}),
z.object({
type: z.literal('agent'),
agentName: z.string(),
}),
z.object({
type: z.literal('tool'),
toolName: z.string(),
}),
z.object({
type: z.literal('prompt'),
promptName: z.string(),
}),
]);
export const CopilotAPIRequest = z.object({
messages: z.array(CopilotApiMessage),
workflow_schema: z.string(),
current_workflow_config: z.string(),
context: CopilotApiChatContext.nullable(),
});
export const CopilotAPIResponse = z.union([
z.object({
response: z.string(),
}),
z.object({
error: z.string(),
}),
]);
export function convertToCopilotApiChatContext(context: z.infer<typeof CopilotChatContext>): z.infer<typeof CopilotApiChatContext> {
switch (context.type) {
case 'chat':
return {
type: 'chat',
messages: convertToAgenticAPIChatMessages(context.messages),
};
case 'agent':
return {
type: 'agent',
agentName: context.name,
};
case 'tool':
return {
type: 'tool',
toolName: context.name,
};
case 'prompt':
return {
type: 'prompt',
promptName: context.name,
};
}
}
export function convertToCopilotApiMessage(message: z.infer<typeof CopilotMessage>): z.infer<typeof CopilotApiMessage> {
return {
role: message.role,
content: JSON.stringify(message.content),
};
}
export function convertToCopilotMessage(message: z.infer<typeof CopilotApiMessage>): z.infer<typeof CopilotMessage> {
switch (message.role) {
case 'assistant':
return CopilotAssistantMessage.parse({
role: 'assistant',
content: JSON.parse(message.content),
});
case 'user':
return {
role: 'user',
content: message.content,
};
default:
throw new Error(`Unknown role: ${message.role}`);
}
}
export function convertToCopilotWorkflow(workflow: z.infer<typeof Workflow>): z.infer<typeof CopilotWorkflow> {
const { lastUpdatedAt, projectId, ...rest } = workflow;
return {
...rest,
};
}

View file

@ -0,0 +1,78 @@
import { z } from "zod";
export const DataSource = z.object({
name: z.string(),
projectId: z.string(),
active: z.boolean().default(true),
status: z.union([
z.literal('pending'),
z.literal('ready'),
z.literal('error'),
z.literal('deleted'),
]),
version: z.number(),
error: z.string().optional(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime().optional(),
attempts: z.number(),
lastAttemptAt: z.string().datetime().optional(),
pendingRefresh: z.boolean().default(false).optional(),
data: z.discriminatedUnion('type', [
z.object({
type: z.literal('urls'),
}),
z.object({
type: z.literal('files'),
}),
]),
});export const DataSourceDoc = z.object({
sourceId: z.string(),
name: z.string(),
version: z.number(),
status: z.union([
z.literal('pending'),
z.literal('ready'),
z.literal('error'),
z.literal('deleted'),
]),
content: z.string().optional(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime().optional(),
error: z.string().optional(),
data: z.discriminatedUnion('type', [
z.object({
type: z.literal('url'),
url: z.string(),
}),
z.object({
type: z.literal('file'),
name: z.string(),
size: z.number(),
mimeType: z.string(),
s3Key: z.string(),
}),
]),
});
export const EmbeddingDoc = z.object({
content: z.string(),
sourceId: z.string(),
embeddings: z.array(z.number()),
metadata: z.object({
sourceURL: z.string(),
title: z.string(),
score: z.number().optional(),
}),
});
export const EmbeddingRecord = z.object({
id: z.string().uuid(),
vector: z.array(z.number()),
payload: z.object({
projectId: z.string(),
sourceId: z.string(),
docId: z.string(),
content: z.string(),
title: z.string(),
name: z.string(),
}),
});

View file

@ -0,0 +1,25 @@
import { z } from "zod";
export const Project = z.object({
_id: z.string().uuid(),
name: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
createdByUserId: z.string(),
secret: z.string(),
chatClientId: z.string(),
webhookUrl: z.string().optional(),
publishedWorkflowId: z.string().optional(),
nextWorkflowNumber: z.number().optional(),
});export const ProjectMember = z.object({
userId: z.string(),
projectId: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
});
export const ApiKey = z.object({
projectId: z.string(),
key: z.string(),
createdAt: z.string().datetime(),
lastUsedAt: z.string().datetime().optional(),
});

View file

@ -0,0 +1,22 @@
import { z } from "zod";
export const Scenario = z.object({
projectId: z.string(),
name: z.string().min(1, "Name cannot be empty"),
description: z.string().min(1, "Description cannot be empty"),
context: z.string().default(''),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
});export const SimulationArticleData = z.object({
articleUrl: z.string(),
articleTitle: z.string().default('').optional(),
articleContent: z.string().default('').optional(),
});
export const SimulationScenarioData = z.object({
scenario: z.string(),
context: z.string().default(''),
});
export const SimulationChatMessagesData = z.object({
chatMessages: z.string(),
});
export const SimulationData = z.union([SimulationArticleData, SimulationScenarioData, SimulationChatMessagesData]);

View file

@ -0,0 +1,32 @@
import { z } from "zod";
import { apiV1 } from "rowboat-shared"
export const GetInformationToolResultItem = z.object({
title: z.string(),
name: z.string(),
content: z.string(),
docId: z.string(),
sourceId: z.string(),
});export const GetInformationToolResult = z.object({
results: z.array(GetInformationToolResultItem)
});
export const WebpageCrawlResponse = z.object({
title: z.string(),
content: z.string(),
});
export const ClientToolCallRequestBody = z.object({
toolCall: apiV1.AssistantMessageWithToolCalls.shape.tool_calls.element,
});
export const ClientToolCallJwt = z.object({
requestId: z.string().uuid(),
projectId: z.string(),
bodyHash: z.string(),
iat: z.number(),
exp: z.number(),
});
export const ClientToolCallRequest = z.object({
requestId: z.string().uuid(),
content: z.string(), // json stringified ClientToolCallRequestBody
});
export const ClientToolCallResponse = z.unknown();

View file

@ -0,0 +1,115 @@
import { CoreMessage, ToolCallPart } from "ai";
import { z } from "zod";
import { apiV1 } from "rowboat-shared";
import { SimulationData } from "./testing_types";
export const PlaygroundChat = z.object({
createdAt: z.string().datetime(),
projectId: z.string(),
title: z.string().optional(),
messages: z.array(apiV1.ChatMessage),
simulated: z.boolean().default(false).optional(),
simulationData: SimulationData.optional(),
simulationComplete: z.boolean().default(false).optional(),
agenticState: z.unknown().optional(),
systemMessage: z.string().optional(),
});
export const Webpage = z.object({
_id: z.string(),
title: z.string(),
contentSimple: z.string(),
lastUpdatedAt: z.string().datetime(),
});
export const ChatClientId = z.object({
_id: z.string(),
projectId: z.string(),
});
export type WithStringId<T> = T & { _id: string };
export function convertToCoreMessages(messages: z.infer<typeof apiV1.ChatMessage>[]): CoreMessage[] {
// convert to core messages
const coreMessages: CoreMessage[] = [];
for (const m of messages) {
switch (m.role) {
case 'system':
coreMessages.push({
role: 'system',
content: m.content,
});
break;
case 'user':
coreMessages.push({
role: 'user',
content: m.content,
});
break;
case 'assistant':
if ('tool_calls' in m) {
const toolCallParts: ToolCallPart[] = m.tool_calls.map((toolCall) => ({
type: 'tool-call',
toolCallId: toolCall.id,
toolName: toolCall.function.name,
args: JSON.parse(toolCall.function.arguments),
}));
if (m.content) {
coreMessages.push({
role: 'assistant',
content: [
{
type: 'text',
text: m.content,
},
...toolCallParts,
]
});
} else {
coreMessages.push({
role: 'assistant',
content: toolCallParts,
});
}
} else {
coreMessages.push({
role: 'assistant',
content: m.content,
});
}
break;
case 'tool':
coreMessages.push({
role: 'tool',
content: [
{
type: 'tool-result',
toolCallId: m.tool_call_id,
toolName: m.tool_name,
result: JSON.parse(m.content),
}
]
});
break;
}
}
return coreMessages;
}
export const ApiMessage = z.union([
apiV1.SystemMessage,
apiV1.UserMessage,
apiV1.AssistantMessage,
apiV1.AssistantMessageWithToolCalls,
apiV1.ToolMessage,
]);
export const ApiRequest = z.object({
messages: z.array(ApiMessage),
state: z.unknown(),
});
export const ApiResponse = z.object({
messages: z.array(ApiMessage),
state: z.unknown(),
});

View file

@ -0,0 +1,70 @@
import { z } from "zod";
export const WorkflowAgent = z.object({
name: z.string(),
type: z.union([
z.literal('conversation'),
z.literal('post_process'),
z.literal('escalation'),
]),
description: z.string(),
disabled: z.boolean().default(false).optional(),
instructions: z.string(),
examples: z.string().optional(),
prompts: z.array(z.string()),
tools: z.array(z.string()),
model: z.union([
z.literal('gpt-4o'),
z.literal('gpt-4o-mini'),
]),
locked: z.boolean().default(false).describe('Whether this agent is locked and cannot be deleted').optional(),
toggleAble: z.boolean().default(true).describe('Whether this agent can be enabled or disabled').optional(),
global: z.boolean().default(false).describe('Whether this agent is a global agent, in which case it cannot be connected to other agents').optional(),
ragDataSources: z.array(z.string()).optional(),
ragReturnType: z.union([z.literal('chunks'), z.literal('content')]).default('chunks'),
ragK: z.number().default(3),
connectedAgents: z.array(z.string()),
controlType: z.union([z.literal('retain'), z.literal('relinquish_to_parent'), z.literal('relinquish_to_start')]).default('retain').describe('Whether this agent retains control after a turn, relinquishes to the parent agent, or relinquishes to the start agent'),
});
export const WorkflowPrompt = z.object({
name: z.string(),
type: z.union([
z.literal('base_prompt'),
z.literal('style_prompt'),
]),
prompt: z.string(),
});
export const WorkflowTool = z.object({
name: z.string(),
description: z.string(),
mockInPlayground: z.boolean().default(false).optional(),
autoSubmitMockedResponse: z.boolean().default(false).optional(),
parameters: z.object({
type: z.literal('object'),
properties: z.record(z.object({
type: z.string(),
description: z.string(),
})),
required: z.array(z.string()).optional(),
}),
});
export const Workflow = z.object({
name: z.string().optional(),
agents: z.array(WorkflowAgent),
prompts: z.array(WorkflowPrompt),
tools: z.array(WorkflowTool),
startAgent: z.string(),
createdAt: z.string().datetime(),
lastUpdatedAt: z.string().datetime(),
projectId: z.string(),
});
export const WorkflowTemplate = Workflow
.omit({
projectId: true,
lastUpdatedAt: true,
createdAt: true,
})
.extend({
name: z.string(),
description: z.string(),
});

View file

@ -1,4 +1,11 @@
import { AgenticAPIChatMessage, AgenticAPIChatRequest, AgenticAPIChatResponse, ClientToolCallJwt, ClientToolCallRequest, ClientToolCallRequestBody, convertFromAgenticAPIChatMessages, Workflow } from "../lib/types";
import { convertFromAgenticAPIChatMessages } from "./types/agents_api_types";
import { ClientToolCallRequest } from "./types/tool_types";
import { ClientToolCallJwt } from "./types/tool_types";
import { ClientToolCallRequestBody } from "./types/tool_types";
import { AgenticAPIChatResponse } from "./types/agents_api_types";
import { AgenticAPIChatRequest } from "./types/agents_api_types";
import { Workflow } from "./types/workflow_types";
import { AgenticAPIChatMessage } from "./types/agents_api_types";
import { z } from "zod";
import { projectsCollection } from "./mongodb";
import { apiV1 } from "rowboat-shared";

View file

@ -7,7 +7,8 @@ import { getProjectConfig, updateProjectName, updateWebhookUrl, createApiKey, de
import { CopyButton } from "../../../lib/components/copy-button";
import { EditableField } from "../../../lib/components/editable-field";
import { EyeIcon, EyeOffIcon, CopyIcon, MoreVerticalIcon, PlusIcon, EllipsisVerticalIcon } from "lucide-react";
import { WithStringId, ApiKey } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { ApiKey } from "../../../lib/types/project_types";
import { z } from "zod";
import { RelativeTime } from "@primer/react";
import { Label } from "../../../lib/components/label";

View file

@ -2,7 +2,10 @@
import { Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Spinner } from "@nextui-org/react";
import { useEffect, useState, useMemo, useCallback } from "react";
import { z } from "zod";
import { PlaygroundChat, SimulationData, SimulationScenarioData, Workflow } from "../../../lib/types";
import { PlaygroundChat } from "../../../lib/types/types";
import { Workflow } from "../../../lib/types/workflow_types";
import { SimulationData } from "../../../lib/types/testing_types";
import { SimulationScenarioData } from "../../../lib/types/testing_types";
import { SimulateScenarioOption, SimulateURLOption } from "./simulation-options";
import { Chat } from "./chat";
import { useSearchParams, useRouter } from "next/navigation";

View file

@ -3,7 +3,11 @@ import { getAssistantResponse, simulateUserResponse } from "../../../actions/act
import { useEffect, useState } from "react";
import { Messages } from "./messages";
import z from "zod";
import { AgenticAPIChatRequest, convertToAgenticAPIChatMessages, convertWorkflowToAgenticAPI, PlaygroundChat, Workflow } from "../../../lib/types";
import { PlaygroundChat } from "../../../lib/types/types";
import { convertToAgenticAPIChatMessages } from "../../../lib/types/agents_api_types";
import { convertWorkflowToAgenticAPI } from "../../../lib/types/agents_api_types";
import { AgenticAPIChatRequest } from "../../../lib/types/agents_api_types";
import { Workflow } from "../../../lib/types/workflow_types";
import { ComposeBox } from "./compose-box";
import { Button, Spinner } from "@nextui-org/react";
import { apiV1 } from "rowboat-shared";

View file

@ -2,7 +2,10 @@
import { Button, Spinner, Textarea } from "@nextui-org/react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import z from "zod";
import { GetInformationToolResult, WebpageCrawlResponse, Workflow, WorkflowTool } from "../../../lib/types";
import { Workflow } from "../../../lib/types/workflow_types";
import { WorkflowTool } from "../../../lib/types/workflow_types";
import { WebpageCrawlResponse } from "../../../lib/types/tool_types";
import { GetInformationToolResult } from "../../../lib/types/tool_types";
import { executeClientTool, getInformationTool, scrapeWebpage, suggestToolResponse } from "../../../actions/actions";
import MarkdownContent from "../../../lib/components/markdown-content";
import Link from "next/link";

View file

@ -3,7 +3,8 @@
import { Button, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Input, Spinner, Textarea } from "@nextui-org/react";
import { useState, useEffect } from "react";
import { getScenarios, createScenario, updateScenario, deleteScenario } from "../../../actions/scenario_actions";
import { Scenario, WithStringId } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { Scenario } from "../../../lib/types/testing_types";
import { z } from "zod";
import { EditableField } from "../../../lib/components/editable-field";
import { EllipsisVerticalIcon, PlayIcon, PlusIcon } from "lucide-react";

View file

@ -1,7 +1,7 @@
'use client';
import { Input, Textarea } from "@nextui-org/react";
import { FormStatusButton } from "../../../lib/components/FormStatusButton";
import { SimulationData } from "../../../lib/types";
import { SimulationData } from "../../../lib/types/testing_types";
import { z } from "zod";
import { scrapeWebpage } from "../../../actions/actions";
import { ScenarioList } from "./scenario-list";

View file

@ -9,7 +9,8 @@ import {
updateScenario,
deleteScenario,
} from '../../../actions/simulation_actions';
import { Scenario, type WithStringId } from '../../../lib/types';
import { type WithStringId } from '../../../lib/types/types';
import { Scenario } from "../../../lib/types/testing_types";
import { z } from 'zod';
type ScenarioType = WithStringId<z.infer<typeof Scenario>>;

View file

@ -1,6 +1,8 @@
"use client";
import { PageSection } from "../../../../lib/components/PageSection";
import { DataSource, DataSourceDoc, WithStringId } from "../../../../lib/types";
import { WithStringId } from "../../../../lib/types/types";
import { DataSourceDoc } from "../../../../lib/types/datasource_types";
import { DataSource } from "../../../../lib/types/datasource_types";
import { z } from "zod";
import { useCallback, useEffect, useState } from "react";
import { useDropzone } from "react-dropzone";

View file

@ -1,6 +1,8 @@
"use client";
import { PageSection } from "../../../../lib/components/PageSection";
import { DataSource, DataSourceDoc, WithStringId } from "../../../../lib/types";
import { WithStringId } from "../../../../lib/types/types";
import { DataSourceDoc } from "../../../../lib/types/datasource_types";
import { DataSource } from "../../../../lib/types/datasource_types";
import { z } from "zod";
import { Recrawl } from "./web-recrawl";
import { deleteDocsFromDataSource, listDocsInDataSource, recrawlWebDataSource, addDocsToDataSource } from "../../../../actions/datasource_actions";

View file

@ -1,5 +1,6 @@
'use client';
import { DataSource, WithStringId } from "../../../../lib/types";
import { WithStringId } from "../../../../lib/types/types";
import { DataSource } from "../../../../lib/types/datasource_types";
import { PageSection } from "../../../../lib/components/PageSection";
import { ToggleSource } from "../toggle-source";
import { Spinner } from "@nextui-org/react";

View file

@ -1,6 +1,6 @@
'use client';
import { getDataSource } from "../../../actions/datasource_actions";
import { DataSource } from "../../../lib/types";
import { DataSource } from "../../../lib/types/datasource_types";
import { useEffect, useState } from "react";
import { z } from 'zod';
import { SourceStatus } from "./source-status";

View file

@ -1,4 +1,4 @@
import { DataSource } from "../../../lib/types";
import { DataSource } from "../../../lib/types/datasource_types";
import { Spinner } from "@nextui-org/react";
import { Link } from "@nextui-org/react";
import { z } from 'zod';

View file

@ -5,7 +5,8 @@ import { ToggleSource } from "./toggle-source";
import { SelfUpdatingSourceStatus } from "./self-updating-source-status";
import { DataSourceIcon } from "../../../lib/components/datasource-icon";
import { useEffect, useState } from "react";
import { DataSource, WithStringId } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { DataSource } from "../../../lib/types/datasource_types";
import { z } from "zod";
import { listDataSources } from "../../../actions/datasource_actions";

View file

@ -1,5 +1,9 @@
"use client";
import { AgenticAPITool, DataSource, WithStringId, WorkflowAgent, WorkflowPrompt } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { AgenticAPITool } from "../../../lib/types/agents_api_types";
import { WorkflowPrompt } from "../../../lib/types/workflow_types";
import { WorkflowAgent } from "../../../lib/types/workflow_types";
import { DataSource } from "../../../lib/types/datasource_types";
import { Button, Divider, Dropdown, DropdownItem, DropdownMenu, DropdownTrigger, Input, Radio, RadioGroup, Select, SelectItem } from "@nextui-org/react";
import { z } from "zod";
import { DataSourceIcon } from "../../../lib/components/datasource-icon";

View file

@ -1,5 +1,7 @@
"use client";
import { DataSource, Workflow, WithStringId } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { Workflow } from "../../../lib/types/workflow_types";
import { DataSource } from "../../../lib/types/datasource_types";
import { z } from "zod";
import { useCallback, useEffect, useState } from "react";
import { WorkflowEditor } from "./workflow_editor";

View file

@ -2,7 +2,12 @@
import { Button, Textarea } from "@nextui-org/react";
import { ActionButton, Pane } from "./pane";
import { useEffect, useRef, useState, createContext, useContext, useCallback } from "react";
import { CopilotAssistantMessage, CopilotMessage, CopilotUserMessage, Workflow, CopilotChatContext, CopilotAssistantMessageActionPart } from "../../../lib/types";
import { CopilotChatContext } from "../../../lib/types/copilot_types";
import { CopilotMessage } from "../../../lib/types/copilot_types";
import { CopilotAssistantMessage } from "../../../lib/types/copilot_types";
import { CopilotAssistantMessageActionPart } from "../../../lib/types/copilot_types";
import { CopilotUserMessage } from "../../../lib/types/copilot_types";
import { Workflow } from "../../../lib/types/workflow_types";
import { z } from "zod";
import { getCopilotResponse } from "../../../actions/actions";
import { Action } from "./copilot_actions";

View file

@ -2,7 +2,9 @@
import { createContext, useContext, useState } from "react";
import clsx from "clsx";
import { z } from "zod";
import { Workflow, CopilotAssistantMessage, CopilotAssistantMessageActionPart } from "../../../lib/types";
import { CopilotAssistantMessage } from "../../../lib/types/copilot_types";
import { CopilotAssistantMessageActionPart } from "../../../lib/types/copilot_types";
import { Workflow } from "../../../lib/types/workflow_types";
import { PreviewModalProvider, usePreviewModal } from './preview-modal';
import { getAppliedChangeKey } from "./copilot";
import { AlertTriangleIcon, CheckCheckIcon, CheckIcon, ChevronsDownIcon, ChevronsUpIcon, EyeIcon, PencilIcon, PlusIcon } from "lucide-react";

View file

@ -1,5 +1,7 @@
import { z } from "zod";
import { WorkflowAgent, WorkflowPrompt, AgenticAPITool } from "../../../lib/types";
import { AgenticAPITool } from "../../../lib/types/agents_api_types";
import { WorkflowPrompt } from "../../../lib/types/workflow_types";
import { WorkflowAgent } from "../../../lib/types/workflow_types";
import { Dropdown, DropdownItem, DropdownTrigger, DropdownMenu } from "@nextui-org/react";
import { useRef, useEffect } from "react";
import { ActionButton, Pane } from "./pane";

View file

@ -1,5 +1,5 @@
"use client";
import { WorkflowPrompt } from "../../../lib/types";
import { WorkflowPrompt } from "../../../lib/types/workflow_types";
import { Divider, Input, Textarea } from "@nextui-org/react";
import { z } from "zod";
import { ActionButton, Pane } from "./pane";

View file

@ -1,5 +1,5 @@
"use client";
import { WorkflowTool } from "../../../lib/types";
import { WorkflowTool } from "../../../lib/types/workflow_types";
import { Accordion, AccordionItem, Button, Checkbox, Select, SelectItem, Switch } from "@nextui-org/react";
import { z } from "zod";
import { ActionButton, Pane } from "./pane";

View file

@ -1,5 +1,10 @@
"use client";
import { DataSource, Workflow, WorkflowAgent, WorkflowPrompt, WorkflowTool, WithStringId } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { Workflow } from "../../../lib/types/workflow_types";
import { WorkflowTool } from "../../../lib/types/workflow_types";
import { WorkflowPrompt } from "../../../lib/types/workflow_types";
import { WorkflowAgent } from "../../../lib/types/workflow_types";
import { DataSource } from "../../../lib/types/datasource_types";
import { useReducer, Reducer, useState, useCallback, useEffect, useRef } from "react";
import { produce, applyPatches, enablePatches, produceWithPatches, Patch } from 'immer';
import { AgentConfig } from "./agent_config";

View file

@ -1,5 +1,6 @@
"use client";
import { Workflow, WithStringId } from "../../../lib/types";
import { WithStringId } from "../../../lib/types/types";
import { Workflow } from "../../../lib/types/workflow_types";
import { z } from "zod";
import { useEffect, useState, useCallback } from "react";
import { PublishedBadge } from "./published_badge";

View file

@ -2,7 +2,7 @@
import { Link, Button, Spinner } from "@nextui-org/react";
import { RelativeTime } from "@primer/react";
import { Project } from "../lib/types";
import { Project } from "../lib/types/project_types";
import { default as NextLink } from "next/link";
import { useEffect, useState } from "react";
import { z } from "zod";

View file

@ -2,7 +2,7 @@
import { cn, Input } from "@nextui-org/react";
import { createProject } from "../../actions/project_actions";
import { templates } from "../../lib/project_templates";
import { WorkflowTemplate } from "../../lib/types";
import { WorkflowTemplate } from "../../lib/types/workflow_types";
import { FormStatusButton } from "../../lib/components/FormStatusButton";
import { useFormStatus } from "react-dom";
import { z } from "zod";

View file

@ -3,7 +3,9 @@ import FirecrawlApp from '@mendable/firecrawl-js';
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import { z } from 'zod';
import { dataSourceDocsCollection, dataSourcesCollection } from '../lib/mongodb';
import { DataSource, DataSourceDoc, EmbeddingRecord } from '../lib/types';
import { EmbeddingRecord } from "../lib/types/datasource_types";
import { DataSourceDoc } from "../lib/types/datasource_types";
import { DataSource } from "../lib/types/datasource_types";
import { WithId } from 'mongodb';
import { embedMany } from 'ai';
import { embeddingModel } from '../lib/embedding';

View file

@ -3,7 +3,9 @@ import FirecrawlApp from '@mendable/firecrawl-js';
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import { z } from 'zod';
import { dataSourceDocsCollection, dataSourcesCollection } from '../lib/mongodb';
import { DataSource, DataSourceDoc, EmbeddingRecord } from '../lib/types';
import { EmbeddingRecord } from "../lib/types/datasource_types";
import { DataSourceDoc } from "../lib/types/datasource_types";
import { DataSource } from "../lib/types/datasource_types";
import { WithId } from 'mongodb';
import { embedMany } from 'ai';
import { embeddingModel } from '../lib/embedding';