Complete outstanding ingestion and document UX work

This commit is contained in:
2026-08-22 18:54:07 +01:00
parent 932e889ee8
commit 5b5a9ecbc3
24 changed files with 696 additions and 41 deletions
+18 -6
View File
@@ -13,18 +13,23 @@ import (
var listCmd = &cobra.Command{
Use: "list",
Short: "List documents in the knowledge base",
Args: cobra.NoArgs,
RunE: runList,
}
func init() {
listCmd.Flags().String("type", "", "filter by document type")
listCmd.Flags().String("tags", "", "filter by tags (comma-separated)")
listCmd.Flags().String("title", "", "filter by title substring")
listCmd.Flags().String("filename", "", "filter by original filename substring")
rootCmd.AddCommand(listCmd)
}
func runList(cmd *cobra.Command, args []string) error {
docType, _ := cmd.Flags().GetString("type")
tags, _ := cmd.Flags().GetString("tags")
title, _ := cmd.Flags().GetString("title")
filename, _ := cmd.Flags().GetString("filename")
params := url.Values{}
if docType != "" {
@@ -33,6 +38,12 @@ func runList(cmd *cobra.Command, args []string) error {
if tags != "" {
params.Set("tags", tags)
}
if title != "" {
params.Set("title", title)
}
if filename != "" {
params.Set("filename", filename)
}
path := "/api/v1/documents"
if len(params) > 0 {
@@ -60,10 +71,11 @@ func runList(cmd *cobra.Command, args []string) error {
}
var docs []struct {
ID int `json:"id"`
Title string `json:"title"`
Type string `json:"doc_type"`
Tags []string `json:"tags"`
ID int `json:"id"`
Title string `json:"title"`
Filename string `json:"original_filename"`
Type string `json:"doc_type"`
Tags []string `json:"tags"`
}
if err := api.DecodeJSON(resp, &docs); err != nil {
return fmt.Errorf("failed to decode response: %w", err)
@@ -74,10 +86,10 @@ func runList(cmd *cobra.Command, args []string) error {
return nil
}
headers := []string{"ID", "TITLE", "TYPE", "TAGS"}
headers := []string{"ID", "TITLE", "FILENAME", "TYPE", "TAGS"}
var rows [][]string
for _, d := range docs {
rows = append(rows, []string{fmt.Sprintf("%d", d.ID), d.Title, d.Type, joinStrings(d.Tags)})
rows = append(rows, []string{fmt.Sprintf("%d", d.ID), d.Title, d.Filename, d.Type, joinStrings(d.Tags)})
}
output.PrintTable(headers, rows)
return nil