Skip to content

Commit b36733b

Browse files
committed
fix animations, adjust table components, normalize action returns, adjust prompt detail versions accordion
1 parent a724564 commit b36733b

19 files changed

+503
-413
lines changed

next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const nextConfig: NextConfig = {
5252
`default-src ${self}`,
5353
`script-src ${self} ${unsafeEval} ${unsafeInline} ${supabaseWildcard} ${localhostWildcard} ${cfChallenges} ${posthogHosts} ${googleTagManager} ${googleAnalytics} ${googleAds} ${googleAdServices} ${sibforms} ${stripeJs} ${unpkg} ${vercelAssets} ${vercelLive}`,
5454
`style-src ${self} ${unsafeInline} ${googleFonts} ${gStatic} ${sibforms}`,
55-
`img-src ${self} ${blob} ${data} ${supabaseWildcard} ${localhostWildcard} ${googleAnalytics} ${googleAds} ${gStatic} ${githubAvatars} ${googleConnect} ${googleAdServices}`,
55+
`img-src ${self} ${blob} ${data} ${supabaseWildcard} ${localhostWildcard} ${googleAnalytics} ${googleAds} ${gStatic} ${githubAvatars} ${googleConnect} ${googleAdServices} ${googleTagManager}`,
5656
`font-src ${self} ${gStatic}`,
5757
`worker-src ${self} ${blob}`,
5858
`frame-src ${self} ${cfChallenges} ${sibforms} ${stripeFrame} td.doubleclick.net ${googleTagManager} ${vercelLive}`,

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"tailwindcss": "^4.0.9",
7777
"tailwindcss-animate": "^1.0.7",
7878
"ts-jest": "^29.2.5",
79+
"tw-animate-css": "^1.3.0",
7980
"typescript": "5.7.2"
8081
}
8182
}

src/app/actions/connect-project.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AgentsmithServices } from '@/lib/AgentsmithServices';
44
import { createClient } from '@/lib/supabase/server';
55
import { revalidatePath } from 'next/cache';
66
import { routes } from '@/utils/routes';
7+
import { ActionResponse } from '@/types/action-response';
8+
import { createErrorResponse, createSuccessResponse } from '@/utils/action-helpers';
79

810
type ConnectProjectOptions = {
911
projectUuid: string;
@@ -12,24 +14,31 @@ type ConnectProjectOptions = {
1214
organizationUuid: string;
1315
};
1416

15-
export async function connectProject(options: ConnectProjectOptions) {
17+
export async function connectProject(options: ConnectProjectOptions): Promise<ActionResponse> {
1618
const { projectUuid, projectRepositoryId, agentsmithFolder, organizationUuid } = options;
1719

1820
const supabase = await createClient();
1921
const agentsmith = new AgentsmithServices({ supabase });
2022

21-
const project = await agentsmith.services.projects.getProjectDataByUuid(projectUuid);
22-
23-
if (!project) {
24-
throw new Error('Project not found, cannot connect project to repository');
23+
try {
24+
const project = await agentsmith.services.projects.getProjectDataByUuid(projectUuid);
25+
26+
if (!project) {
27+
return createErrorResponse('Project not found, cannot connect project to repository');
28+
}
29+
30+
await agentsmith.services.githubApp.connectProjectRepository({
31+
projectId: project.id,
32+
projectUuid,
33+
agentsmithFolder,
34+
projectRepositoryId,
35+
});
36+
37+
revalidatePath(routes.studio.organization(organizationUuid));
38+
return createSuccessResponse(undefined, 'Project connected successfully.');
39+
} catch (error) {
40+
return createErrorResponse(
41+
error instanceof Error ? error.message : 'Failed to connect project',
42+
);
2543
}
26-
27-
await agentsmith.services.githubApp.connectProjectRepository({
28-
projectId: project.id,
29-
projectUuid,
30-
agentsmithFolder,
31-
projectRepositoryId,
32-
});
33-
34-
revalidatePath(routes.studio.organization(organizationUuid));
3544
}

src/app/actions/generate-types.ts

Lines changed: 97 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import { Project } from 'ts-morph';
44
import { createClient } from '@/lib/supabase/server';
55
import type { Database } from '@/app/__generated__/supabase.types';
6+
import { ActionResponse } from '@/types/action-response';
7+
import { createErrorResponse, createSuccessResponse } from '@/utils/action-helpers';
68

7-
export async function generateTypes() {
9+
export async function generateTypes(): Promise<
10+
ActionResponse<{ content: string; filename: string }>
11+
> {
812
// Initialize project and create source file
913
const project = new Project();
1014
const sourceFile = project.createSourceFile('agentsmith.types.ts', '', {
@@ -20,126 +24,111 @@ export async function generateTypes() {
2024

2125
// Fetch prompts from Supabase
2226
const supabase = await createClient();
23-
const { data: prompts, error } = await supabase
24-
.from('prompts')
25-
.select(
26-
`
27+
try {
28+
const { data: prompts, error } = await supabase
29+
.from('prompts')
30+
.select(
31+
`
2732
*,
2833
prompt_versions(*, prompt_variables(*))
29-
`
30-
)
31-
.order('created_at', { ascending: false });
34+
`,
35+
)
36+
.order('created_at', { ascending: false });
3237

33-
if (error) {
34-
console.error('Error fetching prompts:', error);
35-
return {
36-
content: '// Error generating types: ' + error.message,
37-
filename: 'agentsmith.types.ts',
38-
};
39-
}
38+
if (error) {
39+
console.error('Error fetching prompts:', error);
40+
return createErrorResponse('Error generating types: ' + error.message);
41+
}
4042

41-
// Process prompts to get the latest version and variables
42-
const processedPrompts = prompts.map((prompt) => {
43-
const versions = prompt.prompt_versions || [];
44-
// Sort versions by created_at in descending order
45-
const sortedVersions = [...versions].sort(
46-
(a, b) =>
47-
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
48-
);
43+
// Process prompts to get the latest version and variables
44+
const processedPrompts = prompts.map((prompt) => {
45+
const versions = prompt.prompt_versions || [];
46+
// Sort versions by created_at in descending order
47+
const sortedVersions = [...versions].sort(
48+
(a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
49+
);
4950

50-
const latestVersion = sortedVersions.length > 0 ? sortedVersions[0] : null;
51-
const variables = latestVersion?.prompt_variables || [];
51+
const latestVersion = sortedVersions.length > 0 ? sortedVersions[0] : null;
52+
const variables = latestVersion?.prompt_variables || [];
5253

53-
return {
54-
id: prompt.id,
55-
name: prompt.name,
56-
slug: prompt.uuid,
57-
content: latestVersion?.content || '',
58-
version: latestVersion?.version || '1.0.0',
59-
variables: variables.map((v) => ({
60-
name: v.name,
61-
type: v.type,
62-
required: v.required,
63-
})),
64-
};
65-
});
54+
return {
55+
id: prompt.id,
56+
name: prompt.name,
57+
slug: prompt.uuid,
58+
content: latestVersion?.content || '',
59+
version: latestVersion?.version || '1.0.0',
60+
variables: variables.map((v) => ({
61+
name: v.name,
62+
type: v.type,
63+
required: v.required,
64+
})),
65+
};
66+
});
6667

67-
// Add PromptSlug type
68-
const promptSlugs =
69-
processedPrompts.map((p) => `'${p.slug}'`).join(' | ') ||
70-
"'no_prompts_found'";
68+
// Add PromptSlug type
69+
const promptSlugs =
70+
processedPrompts.map((p) => `'${p.slug}'`).join(' | ') || "'no_prompts_found'";
7171

72-
sourceFile.addTypeAlias({
73-
name: 'PromptSlug',
74-
isExported: true,
75-
type: promptSlugs,
76-
});
72+
sourceFile.addTypeAlias({
73+
name: 'PromptSlug',
74+
isExported: true,
75+
type: promptSlugs,
76+
});
7777

78-
// Add Prompt type
79-
sourceFile.addTypeAlias({
80-
name: 'Prompt',
81-
isExported: true,
82-
type: `{
83-
id: number;
84-
name: string;
85-
content: string;
86-
version: string;
87-
variables: PromptVariable[];
88-
slug: PromptSlug;
89-
}`,
90-
});
78+
// Add Prompt type
79+
sourceFile.addTypeAlias({
80+
name: 'Prompt',
81+
isExported: true,
82+
type: `{\n id: number;\n name: string;\n content: string;\n version: string;\n variables: PromptVariable[];\n slug: PromptSlug;\n }`,
83+
});
9184

92-
// Add PromptVariable type
93-
sourceFile.addTypeAlias({
94-
name: 'PromptVariable',
95-
isExported: true,
96-
type: `{
97-
name: string;
98-
type: string;
99-
required: boolean;
100-
}`,
101-
});
85+
// Add PromptVariable type
86+
sourceFile.addTypeAlias({
87+
name: 'PromptVariable',
88+
isExported: true,
89+
type: `{\n name: string;\n type: string;\n required: boolean;\n }`,
90+
});
10291

103-
// Add Agency type with strict typing based on actual prompts
104-
sourceFile.addTypeAlias({
105-
name: 'Agency',
106-
isExported: true,
107-
type: (writer) => {
108-
writer.block(() => {
109-
writer
110-
.write('prompts: ')
111-
.block(() => {
112-
processedPrompts.forEach((prompt) => {
113-
writer.write(
114-
`'${prompt.slug}': Prompt & {
115-
id: ${prompt.id};
116-
name: '${prompt.name}';
117-
content: string;
118-
version: '${prompt.version}';
119-
variables: [${prompt.variables
92+
// Add Agency type with strict typing based on actual prompts
93+
sourceFile.addTypeAlias({
94+
name: 'Agency',
95+
isExported: true,
96+
type: (writer) => {
97+
writer.block(() => {
98+
writer
99+
.write('prompts: ')
100+
.block(() => {
101+
processedPrompts.forEach((prompt) => {
102+
writer.write(
103+
`'${prompt.slug}': Prompt & { \n id: ${prompt.id}; \n name: '${prompt.name}'; \n content: string;\n version: '${prompt.version}';\n variables: [${prompt.variables
120104
.map(
121-
(v) => `{
122-
name: '${v.name}',
123-
type: '${v.type}',
124-
required: ${v.required}
125-
}`
105+
(
106+
v,
107+
) => `{ \n name: '${v.name}', \n type: '${v.type}',
108+
required: ${v.required} \n }`,
126109
)
127-
.join(', ')}];
128-
slug: '${prompt.slug}';
129-
};\n`
130-
);
131-
});
132-
})
133-
.write(';\n');
134-
});
135-
},
136-
});
110+
.join(
111+
', ',
112+
)}];\n slug: '${prompt.slug}';\n };\n`,
113+
);
114+
});
115+
})
116+
.write(';\n');
117+
});
118+
},
119+
});
137120

138-
// Format the source file
139-
sourceFile.formatText();
121+
// Format the source file
122+
sourceFile.formatText();
140123

141-
return {
142-
content: sourceFile.getFullText(),
143-
filename: 'agentsmith.types.ts',
144-
};
124+
return createSuccessResponse(
125+
{
126+
content: sourceFile.getFullText(),
127+
filename: 'agentsmith.types.ts',
128+
},
129+
'Types generated successfully.',
130+
);
131+
} catch (error) {
132+
return createErrorResponse(error instanceof Error ? error.message : 'Type generation failed');
133+
}
145134
}

src/app/actions/github.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { createClient } from '@/lib/supabase/server';
55
import { routes } from '@/utils/routes';
66
import { revalidatePath } from 'next/cache';
77
import { redirect } from 'next/navigation';
8+
import { ActionResponse } from '@/types/action-response';
9+
import { createErrorResponse, createSuccessResponse } from '@/utils/action-helpers';
810

911
export const installGithubApp = async (organizationUuid: string) => {
1012
const supabase = await createClient();
@@ -22,29 +24,37 @@ export const installGithubApp = async (organizationUuid: string) => {
2224
redirect(installUrl);
2325
};
2426

25-
export const syncProject = async (projectUuid: string) => {
27+
export const syncProject = async (projectUuid: string): Promise<ActionResponse> => {
2628
const supabase = await createClient();
2729

2830
const { services, logger } = new AgentsmithServices({ supabase });
2931

3032
logger.info('calling syncProject action with projectUuid', projectUuid);
3133

32-
const project = await services.projects.getProjectDataByUuid(projectUuid);
34+
try {
35+
const project = await services.projects.getProjectDataByUuid(projectUuid);
3336

34-
if (!project) {
35-
throw new Error(`Project with uuid ${projectUuid} not found, cannot sync project`);
36-
}
37+
if (!project) {
38+
return createErrorResponse(`Project with uuid ${projectUuid} not found, cannot sync project`);
39+
}
3740

38-
const projectRepository = await services.projects.getProjectRepositoryByProjectId(project.id);
41+
const projectRepository = await services.projects.getProjectRepositoryByProjectId(project.id);
3942

40-
if (!projectRepository) {
41-
throw new Error(`Project repository for project ${project.id} not found, cannot sync project`);
42-
}
43+
if (!projectRepository) {
44+
return createErrorResponse(
45+
`Project repository for project ${project.id} not found, cannot sync project`,
46+
);
47+
}
4348

44-
revalidatePath(routes.studio.home);
49+
revalidatePath(routes.studio.home);
4550

46-
await services.githubSync.sync({
47-
projectRepository,
48-
source: 'agentsmith',
49-
});
51+
await services.githubSync.sync({
52+
projectRepository,
53+
source: 'agentsmith',
54+
});
55+
return createSuccessResponse(undefined, 'Project synced successfully.');
56+
} catch (error) {
57+
logger.error('Error syncing project:', error);
58+
return createErrorResponse(error instanceof Error ? error.message : 'Failed to sync project');
59+
}
5060
};

0 commit comments

Comments
 (0)