import { VergeApiClient } from '../client/api.js';
import {
ListBlogsToolInput,
GetBlogToolInput,
CreateBlogToolInput,
UpdateBlogToolInput,
DeleteBlogToolInput,
} from './schemas.js';
/**
* verge_list_blogs ツール
* ブログ一覧を取得
*/
export async function handleListBlogs(
input: ListBlogsToolInput,
apiClient: VergeApiClient
) {
try {
const blogs = await apiClient.listBlogs();
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
count: blogs.length,
blogs: blogs.map((blog) => ({
id: blog.id,
user_id: blog.user_id,
name: blog.name,
slug: blog.slug,
description: blog.description,
created_at: blog.created_at,
deployment_url: blog.deployment_url,
last_deployed_at: blog.last_deployed_at,
article_count: blog.article_count,
})),
},
null,
2
),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* verge_get_blog ツール
* ブログ詳細を取得
*/
export async function handleGetBlog(input: GetBlogToolInput, apiClient: VergeApiClient) {
try {
const blog = await apiClient.getBlog(input.blog_id);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
blog: {
id: blog.id,
user_id: blog.user_id,
name: blog.name,
slug: blog.slug,
description: blog.description,
created_at: blog.created_at,
deployment_project_name: blog.deployment_project_name,
deployment_url: blog.deployment_url,
last_deployed_at: blog.last_deployed_at,
deployment_in_progress: blog.deployment_in_progress,
article_count: blog.article_count,
},
},
null,
2
),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* verge_create_blog ツール
* 新規ブログを作成
*/
export async function handleCreateBlog(
input: CreateBlogToolInput,
apiClient: VergeApiClient
) {
try {
const blog = await apiClient.createBlog({
name: input.name,
slug: input.slug,
description: input.description || null,
});
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: 'ブログを作成しました',
blog: {
id: blog.id,
name: blog.name,
slug: blog.slug,
description: blog.description,
created_at: blog.created_at,
},
},
null,
2
),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* verge_update_blog ツール
* 既存ブログを更新
*/
export async function handleUpdateBlog(
input: UpdateBlogToolInput,
apiClient: VergeApiClient
) {
try {
const { blog_id, ...updateData } = input;
const blog = await apiClient.updateBlog(blog_id, updateData);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: 'ブログを更新しました',
blog: {
id: blog.id,
name: blog.name,
slug: blog.slug,
description: blog.description,
},
},
null,
2
),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}
/**
* verge_delete_blog ツール
* ブログを削除
*/
export async function handleDeleteBlog(
input: DeleteBlogToolInput,
apiClient: VergeApiClient
) {
try {
await apiClient.deleteBlog(input.blog_id);
return {
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: true,
message: 'ブログを削除しました',
blog_id: input.blog_id,
},
null,
2
),
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: 'text' as const,
text: JSON.stringify(
{
success: false,
error: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
};
}
}