feat(cli): doc delete multi-id + api --paginate + paginate fixes + batch deletes
Batch-write surface and pagination consistency:
* weknora doc delete <doc-id> [<doc-id>...] — positional multi-id, default
keep-going on failure. Single -y confirms entire batch.
* weknora session delete <session-id> [<session-id>...] — same shape.
* weknora chunk delete <chunk-id> [<chunk-id>...] --doc <doc-id> — multi-id
with shared --doc parent.
* Multi-id partial-failure rolls up as operation.failed (exit 1), not
server.error (exit 7) — failures are operation outcomes, not transient
transport issues, and the retry-with-backoff hint for server.* would
mislead callers.
* weknora api <path> --paginate — auto-walks offset pagination and merges
pages into a single {data, total} JSON response.
* Paginate truncation fix across 6 list/follower call sites.
* All doc / search / chunk / session / kb list commands migrated to
FormatOptions API.
Multi-id RunE only emits the {ok, failed} envelope when the operation
actually ran — pre-flight failures (e.g. confirmation_required) leave
stdout empty per the wire contract.
doc upload's missing-positional-or-flag check is wrapped as FlagError so
the exit code (2) matches the convention used by other commands that
require a positional argument directly.
This commit is contained in:
+10
-9
@@ -17,7 +17,7 @@ const (
|
||||
maxFullLimit = 1000
|
||||
)
|
||||
|
||||
// sessionViewFields enumerates the fields surfaced for `--json` discovery on
|
||||
// sessionViewFields enumerates the fields surfaced for `--format json` discovery on
|
||||
// `session view`. Mirrors sdk.Session json tags; adds the synthesized
|
||||
// `messages` projection surfaced by `--full`.
|
||||
var sessionViewFields = []string{
|
||||
@@ -53,7 +53,7 @@ type ViewService interface {
|
||||
func NewCmdView(f *cmdutil.Factory) *cobra.Command {
|
||||
opts := &ViewOptions{Limit: defaultFullLimit}
|
||||
cmd := &cobra.Command{
|
||||
Use: "view <id>",
|
||||
Use: "view <session-id>",
|
||||
Short: "Show a chat session by ID",
|
||||
Long: `Show a chat session.
|
||||
|
||||
@@ -65,24 +65,25 @@ Pass --full to also load the chat history (LoadMessages SDK call). Use
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
opts.LimitSet = c.Flags().Changed("limit")
|
||||
jopts, err := cmdutil.CheckJSONFlags(c)
|
||||
fopts, err := cmdutil.CheckFormatFlag(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fopts.ResolveDefault(iostreams.IO.IsStdoutTTY())
|
||||
cli, err := f.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return runView(c.Context(), opts, jopts, cli, args[0])
|
||||
return runView(c.Context(), opts, fopts, cli, args[0])
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVar(&opts.Full, "full", false, "Also load chat history via LoadMessages")
|
||||
cmd.Flags().IntVar(&opts.Limit, "limit", defaultFullLimit, "Max messages to load when --full is set (1..1000)")
|
||||
cmdutil.AddJSONFlags(cmd, sessionViewFields)
|
||||
cmdutil.AddFormatFlag(cmd, sessionViewFields...)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runView(ctx context.Context, opts *ViewOptions, jopts *cmdutil.JSONOptions, svc ViewService, id string) error {
|
||||
func runView(ctx context.Context, opts *ViewOptions, fopts *cmdutil.FormatOptions, svc ViewService, id string) error {
|
||||
if !opts.Full && opts.LimitSet {
|
||||
return &cmdutil.Error{
|
||||
Code: cmdutil.CodeInputInvalidArgument,
|
||||
@@ -114,9 +115,9 @@ func runView(ctx context.Context, opts *ViewOptions, jopts *cmdutil.JSONOptions,
|
||||
}
|
||||
}
|
||||
|
||||
if jopts.Enabled() {
|
||||
if fopts.WantsJSON() {
|
||||
if !opts.Full {
|
||||
return jopts.Emit(iostreams.IO.Out, s)
|
||||
return fopts.Emit(iostreams.IO.Out, s)
|
||||
}
|
||||
// Project session + messages into a single bare object. Use the
|
||||
// SDK json tags via an embedded *Session so existing keys stay
|
||||
@@ -125,7 +126,7 @@ func runView(ctx context.Context, opts *ViewOptions, jopts *cmdutil.JSONOptions,
|
||||
*sdk.Session
|
||||
Messages []sdk.Message `json:"messages"`
|
||||
}{Session: s, Messages: msgs}
|
||||
return jopts.Emit(iostreams.IO.Out, payload)
|
||||
return fopts.Emit(iostreams.IO.Out, payload)
|
||||
}
|
||||
|
||||
w := iostreams.IO.Out
|
||||
|
||||
Reference in New Issue
Block a user