// Copyright 2025 eat-pray-ai & OpenWaygate
// SPDX-License-Identifier: Apache-2.0
package comment
import (
"encoding/json"
"io"
"github.com/eat-pray-ai/yutu/cmd"
"github.com/eat-pray-ai/yutu/pkg"
"github.com/eat-pray-ai/yutu/pkg/comment"
"github.com/eat-pray-ai/yutu/pkg/utils"
"github.com/google/jsonschema-go/jsonschema"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/spf13/cobra"
)
const (
updateTool = "comment-update"
updateShort = "Update a comment"
updateLong = "Update a comment on a video"
updateIdUsage = "ID of the comment"
)
var updateInSchema = &jsonschema.Schema{
Type: "object",
Required: []string{"ids"},
Properties: map[string]*jsonschema.Schema{
"ids": {
Type: "array", Description: updateIdUsage,
Items: &jsonschema.Schema{Type: "string"},
},
"can_rate": {Type: "boolean", Description: crUsage},
"text_original": {Type: "string", Description: toUsage},
"viewer_rating": {
Type: "string", Description: vrUsage,
Enum: []any{"none", "like", "dislike", ""},
},
"output": {
Type: "string", Enum: []any{"json", "yaml", "silent", ""},
Description: pkg.SilentUsage, Default: json.RawMessage(`"yaml"`),
},
"jsonpath": {Type: "string", Description: pkg.JPUsage},
},
}
func init() {
mcp.AddTool(
cmd.Server, &mcp.Tool{
Name: updateTool, Title: updateShort, Description: updateLong,
InputSchema: updateInSchema, Annotations: &mcp.ToolAnnotations{
DestructiveHint: jsonschema.Ptr(false),
IdempotentHint: false,
OpenWorldHint: jsonschema.Ptr(true),
ReadOnlyHint: false,
},
}, cmd.GenToolHandler(
updateTool, func(input comment.Comment, writer io.Writer) error {
return input.Update(writer)
},
),
)
commentCmd.AddCommand(updateCmd)
updateCmd.Flags().StringSliceVarP(&ids, "id", "i", []string{}, updateIdUsage)
updateCmd.Flags().BoolVarP(canRate, "canRate", "R", false, crUsage)
updateCmd.Flags().StringVarP(
&textOriginal, "textOriginal", "t", "", toUsage,
)
updateCmd.Flags().StringVarP(
&viewerRating, "viewerRating", "r", "", vrUsage,
)
updateCmd.Flags().StringVarP(&output, "output", "o", "", pkg.SilentUsage)
updateCmd.Flags().StringVarP(&jsonpath, "jsonPath", "j", "", pkg.JPUsage)
_ = updateCmd.MarkFlagRequired("id")
}
var updateCmd = &cobra.Command{
Use: "update",
Short: updateShort,
Long: updateLong,
Run: func(cmd *cobra.Command, args []string) {
input := comment.NewComment(
comment.WithIds(ids),
comment.WithCanRate(canRate),
comment.WithTextOriginal(textOriginal),
comment.WithViewerRating(viewerRating),
comment.WithOutput(output),
comment.WithJsonpath(jsonpath),
)
utils.HandleCmdError(input.Update(cmd.OutOrStdout()), cmd)
},
}