Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cli/cmd/doc/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var docCreateFields = []string{

// CreateOptions holds CLI flag values for `doc create`.
type CreateOptions struct {
Publish bool
Text string // --text (required): document text content (Markdown)
Title string // --title: document title (matches `doc update --title`)
TagID string // --tag-id: associate with a tag
Expand Down Expand Up @@ -76,7 +77,7 @@ don't require a file upload or remote URL. KB resolution follows the standard
if err != nil {
return err
}
planArgs := map[string]any{"text": opts.Text, "title": opts.Title, "kb": kbID}
planArgs := map[string]any{"text": opts.Text, "title": opts.Title, "kb": kbID, "publish": opts.Publish}
if opts.TagID != "" {
planArgs["tag_id"] = opts.TagID
}
Expand Down Expand Up @@ -104,6 +105,7 @@ don't require a file upload or remote URL. KB resolution follows the standard
}
cmdutil.AddKBFlag(cmd)
cmd.Flags().StringVar(&opts.Text, "text", "", "Document text content in Markdown format (required)")
cmd.Flags().BoolVar(&opts.Publish, "publish", false, "Publish the document and queue it for indexing immediately")
cmd.Flags().StringVar(&opts.Title, "title", "", "Document title")
cmd.Flags().StringVar(&opts.TagID, "tag-id", "", "Tag id to associate with the new entry")
cmd.Flags().StringVar(&opts.Channel, "channel", "", "Ingestion-channel tag recorded server-side (default \"api\")")
Expand Down Expand Up @@ -136,11 +138,14 @@ func runCreate(ctx context.Context, opts *CreateOptions, fopts *cmdutil.FormatOp
TagID: opts.TagID,
Channel: cmp.Or(opts.Channel, uploadChannel),
}
if opts.Publish {
req.Status = "publish"
}
k, err := svc.CreateManualKnowledge(ctx, kbID, req)
if err != nil {
return cmdutil.WrapHTTP(err, "create document")
}
// Inline-created docs land in parse_status=draft and are NOT auto-queued
// By default, inline-created docs land in parse_status=draft and are NOT auto-queued
// for parsing (unlike `doc upload`), so they aren't searchable until
// reparsed. Surface the next step so an agent doesn't `doc wait` into a
// timeout or `search` into empty results.
Expand Down
10 changes: 10 additions & 0 deletions cli/cmd/doc/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestCreate_Channel_DefaultIsAPI(t *testing.T) {
svc := &fakeCreateSvc{resp: &sdk.Knowledge{ID: "doc_ch"}}
opts := &CreateOptions{Text: "content"}
require.NoError(t, runCreate(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, svc, "kb_xxx"))
assert.Empty(t, svc.got.req.Status)
assert.Equal(t, uploadChannel, svc.got.req.Channel)
}

Expand Down Expand Up @@ -182,3 +183,12 @@ func TestCreateDryRunShowsDocumentClassification(t *testing.T) {
assert.Equal(t, "ops", envelope.Meta.Plan.Args["tag_id"])
assert.Equal(t, "migration", envelope.Meta.Plan.Args["channel"])
}

func TestCreatePublish(t *testing.T) {
_, _ = iostreams.SetForTest(t)
svc := &fakeCreateSvc{resp: &sdk.Knowledge{ID: "doc", ParseStatus: "pending"}}
opts := &CreateOptions{Text: "index this note", Publish: true}
format := &cmdutil.FormatOptions{Mode: cmdutil.FormatJSON}
require.NoError(t, runCreate(context.Background(), opts, format, svc, "kb"))
assert.Equal(t, "publish", svc.got.req.Status)
}
1 change: 1 addition & 0 deletions client/knowledge.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ func (c *Client) UpdateImageInfo(ctx context.Context,

// CreateManualKnowledgeRequest contains the parameters for creating a manual Markdown knowledge entry.
type CreateManualKnowledgeRequest struct {
Status string `json:"status,omitempty"`
// TagIDs replaces TagID when nonempty. TagID remains supported for single-tag callers.
TagIDs []string `json:"tag_ids,omitempty"`
Title string `json:"title"`
Expand Down
Loading