118 lines
3.6 KiB
Go
118 lines
3.6 KiB
Go
// Copyright 2026 eat-pray-ai & OpenWaygate
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package liveStream
|
|
|
|
import (
|
|
"encoding/json/jsontext"
|
|
"io"
|
|
|
|
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/liveStream"
|
|
"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 (
|
|
listTool = "liveStream-list"
|
|
listIdsUsage = "Return live streams with the given ids"
|
|
listShort = "List live streams"
|
|
listLong = "List live streams. Use this tool to list live streams for the authenticated user."
|
|
listExample = `# List my live streams
|
|
yutu liveStream list --mine
|
|
# List live streams by ID
|
|
yutu liveStream list --ids stream1,stream2
|
|
# List live streams in JSON format
|
|
yutu liveStream list --mine --output json --maxResults 10`
|
|
)
|
|
|
|
var listInSchema = &jsonschema.Schema{
|
|
Type: "object",
|
|
Required: []string{},
|
|
Properties: map[string]*jsonschema.Schema{
|
|
"ids": {
|
|
Type: "array", Description: listIdsUsage,
|
|
Items: &jsonschema.Schema{Type: "string"},
|
|
},
|
|
"mine": {Type: "boolean", Description: "List streams owned by the authenticated user"},
|
|
"max_results": {
|
|
Type: "number", Description: pkg.MRUsage,
|
|
Default: jsontext.Value("5"), Minimum: new(float64(0)),
|
|
},
|
|
"on_behalf_of_content_owner": {Type: "string", Description: pkg.OBOCOUsage},
|
|
"on_behalf_of_content_owner_channel": {
|
|
Type: "string", Description: obococUsage,
|
|
},
|
|
"parts": {
|
|
Type: "array", Description: pkg.PartsUsage,
|
|
Items: &jsonschema.Schema{Type: "string"},
|
|
Default: jsontext.Value(`["id","snippet","cdn","status"]`),
|
|
},
|
|
"output": {
|
|
Type: "string", Enum: []any{"json", "yaml", "table"},
|
|
Description: pkg.TableUsage, Default: jsontext.Value(`"json"`),
|
|
},
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
mcp.AddTool(
|
|
cmd.Server, &mcp.Tool{
|
|
Name: listTool, Title: listShort, Description: listLong,
|
|
InputSchema: listInSchema, Annotations: &mcp.ToolAnnotations{
|
|
DestructiveHint: new(false),
|
|
IdempotentHint: true,
|
|
OpenWorldHint: new(true),
|
|
ReadOnlyHint: true,
|
|
},
|
|
}, cobramcp.GenToolHandler(
|
|
listTool, func(input liveStream.LiveStream, writer io.Writer) error {
|
|
return input.List(writer)
|
|
},
|
|
),
|
|
)
|
|
liveStreamCmd.AddCommand(listCmd)
|
|
|
|
listCmd.Flags().StringSliceVarP(&ids, "ids", "i", []string{}, listIdsUsage)
|
|
listCmd.Flags().BoolVarP(
|
|
mine, "mine", "m", false, "List streams owned by the authenticated user",
|
|
)
|
|
listCmd.Flags().Int64VarP(&maxResults, "maxResults", "n", 5, pkg.MRUsage)
|
|
listCmd.Flags().StringVarP(
|
|
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "b", "", pkg.OBOCOUsage,
|
|
)
|
|
listCmd.Flags().StringVarP(
|
|
&onBehalfOfContentOwnerChannel, "onBehalfOfContentOwnerChannel", "B", "",
|
|
obococUsage,
|
|
)
|
|
listCmd.Flags().StringSliceVarP(
|
|
&parts, "parts", "p", []string{"id", "snippet", "cdn", "status"},
|
|
pkg.PartsUsage,
|
|
)
|
|
listCmd.Flags().StringP("output", "o", "table", pkg.TableUsage)
|
|
}
|
|
|
|
var listCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: listShort,
|
|
Long: listLong,
|
|
Example: listExample,
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
output, _ := cmd.Flags().GetString("output")
|
|
input := liveStream.NewLiveStream(
|
|
liveStream.WithIds(ids),
|
|
liveStream.WithMine(mine),
|
|
liveStream.WithMaxResults(maxResults),
|
|
liveStream.WithOnBehalfOfContentOwner(onBehalfOfContentOwner),
|
|
liveStream.WithOnBehalfOfContentOwnerChannel(onBehalfOfContentOwnerChannel),
|
|
liveStream.WithParts(parts),
|
|
liveStream.WithOutput(output),
|
|
)
|
|
utils.HandleCmdError(input.List(cmd.OutOrStdout()), cmd)
|
|
},
|
|
}
|