94 lines
2.7 KiB
Go
94 lines
2.7 KiB
Go
// Copyright 2025 eat-pray-ai & OpenWaygate
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package channelSection
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
cobramcp "github.com/eat-pray-ai/cobra-mcp"
|
|
"github.com/eat-pray-ai/yutu/cmd"
|
|
"github.com/eat-pray-ai/yutu/pkg"
|
|
"github.com/eat-pray-ai/yutu/pkg/channelSection"
|
|
"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 (
|
|
deleteTool = "channelSection-delete"
|
|
deleteIdsUsage = "Delete the channel sections with the given ids"
|
|
deleteConfirm = "Delete channel section(s): %s"
|
|
deleteShort = "Delete channel sections"
|
|
deleteLong = "Delete channel sections. Use this tool to delete channel sections by IDs."
|
|
deleteExample = `# Delete a channel section by ID
|
|
yutu channelSection delete --ids abc123
|
|
# Delete multiple channel sections
|
|
yutu channelSection delete --ids abc123,def456`
|
|
)
|
|
|
|
var deleteInSchema = &jsonschema.Schema{
|
|
Type: "object",
|
|
Required: []string{"ids"},
|
|
Properties: map[string]*jsonschema.Schema{
|
|
"ids": {
|
|
Type: "array", Description: deleteIdsUsage,
|
|
Items: &jsonschema.Schema{Type: "string"},
|
|
},
|
|
"on_behalf_of_content_owner": {Type: "string", Description: pkg.OBOCOUsage},
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
mcp.AddTool(
|
|
cmd.Server, &mcp.Tool{
|
|
Name: deleteTool, Title: deleteShort, Description: deleteLong,
|
|
InputSchema: deleteInSchema, Annotations: &mcp.ToolAnnotations{
|
|
DestructiveHint: new(true),
|
|
IdempotentHint: false,
|
|
OpenWorldHint: new(true),
|
|
ReadOnlyHint: false,
|
|
},
|
|
}, cobramcp.GenToolHandlerWithMRTR(
|
|
deleteTool, cobramcp.ConfirmThen(
|
|
func(input channelSection.ChannelSection) string {
|
|
return fmt.Sprintf(deleteConfirm, strings.Join(input.Ids, ", "))
|
|
},
|
|
func(input channelSection.ChannelSection, w io.Writer) error {
|
|
return input.Delete(w)
|
|
},
|
|
),
|
|
),
|
|
)
|
|
channelSectionCmd.AddCommand(deleteCmd)
|
|
|
|
deleteCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, deleteIdsUsage)
|
|
deleteCmd.Flags().StringVarP(
|
|
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", pkg.OBOCOUsage,
|
|
)
|
|
deleteCmd.Flags().Bool("yes", false, pkg.ConfirmedUsage)
|
|
_ = deleteCmd.MarkFlagRequired("ids")
|
|
}
|
|
|
|
var deleteCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Short: deleteShort,
|
|
Long: deleteLong,
|
|
Example: deleteExample,
|
|
PreRunE: func(c *cobra.Command, _ []string) error {
|
|
return utils.ConfirmPreRun(
|
|
c, fmt.Sprintf(deleteConfirm, strings.Join(ids, ", ")),
|
|
)
|
|
},
|
|
Run: func(c *cobra.Command, _ []string) {
|
|
input := channelSection.NewChannelSection(
|
|
channelSection.WithIds(ids),
|
|
channelSection.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
|
)
|
|
utils.HandleCmdError(input.Delete(c.OutOrStdout()), c)
|
|
},
|
|
}
|