feat(cli): doc/kb resource expansion — upload flags + list filters + view fields
Closes deep-tuning gaps in v0.4-shipped doc / kb / session commands. Each command had multiple SDK fields the CLI silently hardcoded or omitted; this commit threads them through. doc upload: - --enable-multimodel (tri-state via NoOptDefVal): toggle multimodal extraction (PDF/DOCX image-to-text) per upload. Empty explicit value (e.g. --enable-multimodel="" from uninterpolated shell var) rejected as input.invalid_argument rather than silently coerced. - --metadata key=value (repeatable): attach arbitrary metadata - --channel <name> (default api, override for browser / wechat ingests) - URL mode gains --title / --file-type / --tag-id; URL-only flags rejected with input.invalid_argument when used without --from-url doc list filter flags: - --keyword (server-side LIKE — case-sensitive per PG) - --file-type / --source / --tag-id - --start-time / --end-time (RFC3339) search docs switches from client-side substring to server-side Keyword via ListKnowledgeWithFilter — smaller wire payload, but case-sensitivity shifts (documented in CHANGELOG + help text + Long). MCP doc_list schema gains the same 6 filter fields (parity with CLI). session view --full + --limit: loads chat history via LoadMessages SDK method. kb view human KV expanded: type / pinned / temporary / processing state + count / summary model / created timestamp. All omit-empty. doc view human KV expanded: title (when distinct from filename) / description / source / channel / summary_status / enable_status / tag_id / storage (human bytes) / file_hash (12-char prefix).
This commit is contained in:
@@ -25,16 +25,25 @@ type scriptedUploadSvc struct {
|
||||
err error
|
||||
}
|
||||
called []string
|
||||
|
||||
// Captures from the most-recent call (every recursive iteration writes
|
||||
// these; tests that want all-rows can extend to slices later).
|
||||
lastMetadata map[string]string
|
||||
lastEnableMultimodel *bool
|
||||
lastChannel string
|
||||
}
|
||||
|
||||
func (s *scriptedUploadSvc) CreateKnowledgeFromFile(
|
||||
_ context.Context,
|
||||
_, filePath string,
|
||||
_ map[string]string,
|
||||
_ *bool,
|
||||
_, _ string,
|
||||
metadata map[string]string,
|
||||
enableMultimodel *bool,
|
||||
_, channel string,
|
||||
) (*sdk.Knowledge, error) {
|
||||
s.called = append(s.called, filepath.Base(filePath))
|
||||
s.lastMetadata = metadata
|
||||
s.lastEnableMultimodel = enableMultimodel
|
||||
s.lastChannel = channel
|
||||
r, ok := s.results[filepath.Base(filePath)]
|
||||
if !ok {
|
||||
return &sdk.Knowledge{ID: "doc_" + filepath.Base(filePath), FileName: filepath.Base(filePath)}, nil
|
||||
@@ -157,6 +166,68 @@ func TestUploadRecursive_RejectsNameFlag(t *testing.T) {
|
||||
assert.Contains(t, typed.Message, "--name")
|
||||
}
|
||||
|
||||
func TestUploadRecursive_PropagatesMultimodelAndMetadata(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
dir := t.TempDir()
|
||||
mkTree(t, dir, "a.pdf")
|
||||
|
||||
svc := &scriptedUploadSvc{}
|
||||
mm := true
|
||||
opts := &UploadOptions{
|
||||
Recursive: true,
|
||||
Glob: "*",
|
||||
EnableMultimodel: &mm,
|
||||
Metadata: []string{"team=alpha"},
|
||||
Channel: "browser_extension",
|
||||
}
|
||||
require.NoError(t, runUploadRecursive(context.Background(), opts, nil, svc, "kb_xxx", dir))
|
||||
|
||||
require.NotNil(t, svc.lastEnableMultimodel)
|
||||
assert.True(t, *svc.lastEnableMultimodel)
|
||||
assert.Equal(t, map[string]string{"team": "alpha"}, svc.lastMetadata)
|
||||
assert.Equal(t, "browser_extension", svc.lastChannel)
|
||||
}
|
||||
|
||||
func TestUploadRecursive_MetadataInvalid_NoCalls(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
dir := t.TempDir()
|
||||
mkTree(t, dir, "a.pdf")
|
||||
|
||||
svc := &scriptedUploadSvc{}
|
||||
opts := &UploadOptions{Recursive: true, Glob: "*", Metadata: []string{"badformat"}}
|
||||
err := runUploadRecursive(context.Background(), opts, nil, svc, "kb_xxx", dir)
|
||||
require.Error(t, err)
|
||||
var typed *cmdutil.Error
|
||||
require.ErrorAs(t, err, &typed)
|
||||
assert.Equal(t, cmdutil.CodeInputInvalidArgument, typed.Code)
|
||||
assert.Empty(t, svc.called, "must fail before any per-file call")
|
||||
}
|
||||
|
||||
func TestUploadRecursive_RejectsURLOnlyFlags(t *testing.T) {
|
||||
_, _ = iostreams.SetForTest(t)
|
||||
dir := t.TempDir()
|
||||
mkTree(t, dir, "a.pdf")
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
opts *UploadOptions
|
||||
want string
|
||||
}{
|
||||
{"title", &UploadOptions{Recursive: true, Glob: "*", Title: "x"}, "--title"},
|
||||
{"file-type", &UploadOptions{Recursive: true, Glob: "*", FileType: "pdf"}, "--file-type"},
|
||||
{"tag-id", &UploadOptions{Recursive: true, Glob: "*", TagID: "t"}, "--tag-id"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
svc := &scriptedUploadSvc{}
|
||||
err := runUploadRecursive(context.Background(), tc.opts, nil, svc, "kb_xxx", dir)
|
||||
require.Error(t, err)
|
||||
var typed *cmdutil.Error
|
||||
require.ErrorAs(t, err, &typed)
|
||||
assert.Equal(t, cmdutil.CodeInputInvalidArgument, typed.Code)
|
||||
assert.Contains(t, typed.Message, tc.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUploadRecursive_JSON_BareObject(t *testing.T) {
|
||||
out, _ := iostreams.SetForTest(t)
|
||||
dir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user