mirror of
https://github.com/volcengine/OpenViking.git
synced 2026-09-30 17:28:07 +08:00
* feat(sdk): sync go/ts/python SDKs with server find/search, recall, and admin changes Server-side changes recently landed that the language SDKs had drifted from: - find/search results now return `tags` and no longer return `category`/`match_reason`/`relations`/`overview` (#3730). Go's strict struct was the only one broken; update MatchedContext accordingly. - new admin endpoints for agent-evolution and per-account settings (#3695). - public `search/recall` endpoint was missing from all SDKs. Changes: - python: add `level`/`since`/`until`/`time_field` to find/search; add an `extra` escape hatch to find/search/add_resource/write/batch_write so new server fields can be passed without an SDK bump (only forwarded when set, preserving `level=0`); add `recall` and the four admin methods. - go: fix MatchedContext (add Tags, drop removed fields), add Recall and the four admin methods. - typescript: type MatchedContext/FindResult, add RecallOptions, add `recall` and the four admin methods. Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> feat(sdk): unify options APIs and sync latest server interfaces - migrate complex Python SDK calls to typed options dictionaries - add dedicated context search and consistent extra-field handling - align Go and TypeScript options with omission-aware serialization - support session config, event tags, Agent Evolution date filters, OpenViking Assets, batch write, downloads, and create_parent - refresh SDK tests and examples across all three languages Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): address options API review findings - fix Go session extra merging and Python message precedence - adapt LangChain calls to the Python options API - migrate repository examples, tests, and documentation Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): complete options migration and message parity - migrate remaining Python SDK benchmarks to options dictionaries - normalize empty parts consistently for single and batch messages - add regression guards for repository SDK call sites Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): align reindex options after main rebase - preserve reindex tags in Python typed options - add reindex extra support for Go and TypeScript - reject official fields passed through extra across SDKs Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> feat(sdk): support legacy keyword options Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> docs(sdk): use explicit Python SDK arguments Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): support set tags extra options Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): expose Go add resource options Expose AddType and ProcessingMode through Go AddResourceOptions and serialize them to the resources API. Add a regression test covering the resulting request payload. Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: TRAE CLI <traecli@bytedance.com> feat(sdk): flatten core Python client options Co-authored-by: TRAE CLI <traecli@bytedance.com> docs(sdk): align Python examples with flattened options Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): preserve core API compatibility Co-authored-by: TRAE CLI <traecli@bytedance.com> refactor(python-sdk): move resource hints to options Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): align resource option callers Co-authored-by: TRAE CLI <traecli@bytedance.com> test(sdk): cover recursive reindex forwarding Co-authored-by: TRAE CLI <traecli@bytedance.com> fix(sdk): preserve Go options compatibility Co-authored-by: TRAE CLI <traecli@bytedance.com> feat(python-sdk): expose message peer id Co-authored-by: TRAE CLI <traecli@bytedance.com> test(python-sdk): consolidate options coverage Co-authored-by: TRAE CLI <traecli@bytedance.com> feat(python-sdk): add parts and flatten image search Co-authored-by: TRAE CLI <traecli@bytedance.com> * docs(sdk): align Python call examples Co-authored-by: TRAE CLI <traecli@bytedance.com> --------- Co-authored-by: TRAE CLI <traecli@bytedance.com> Co-authored-by: Qin Haojie <qinhaojie.exe@bytedance.com>
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package openviking
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// AddResource imports a local path or remote URL into OpenViking resources.
|
|
func (c *Client) AddResource(ctx context.Context, path string, opts *AddResourceOptions) (map[string]any, error) {
|
|
if opts == nil {
|
|
opts = &AddResourceOptions{}
|
|
}
|
|
if opts.To != "" && opts.Parent != "" {
|
|
return nil, fmt.Errorf("openviking: cannot specify both To and Parent")
|
|
}
|
|
payload := map[string]any{
|
|
"reason": opts.Reason,
|
|
"instruction": opts.Instruction,
|
|
"wait": opts.Wait,
|
|
"strict": opts.Strict,
|
|
"directly_upload_media": boolValue(opts.DirectlyUploadMedia, true),
|
|
"watch_interval": opts.WatchInterval,
|
|
}
|
|
setString(payload, "to", opts.To)
|
|
setString(payload, "parent", opts.Parent)
|
|
setAny(payload, "create_parent", opts.CreateParent)
|
|
setString(payload, "add_type", opts.AddType)
|
|
setString(payload, "ignore_dirs", opts.IgnoreDirs)
|
|
setString(payload, "include", opts.Include)
|
|
setString(payload, "exclude", opts.Exclude)
|
|
setFloatPtr(payload, "timeout", opts.Timeout)
|
|
if opts.PreserveStructure != nil {
|
|
payload["preserve_structure"] = *opts.PreserveStructure
|
|
}
|
|
setString(payload, "processing_mode", opts.ProcessingMode)
|
|
setAny(payload, "telemetry", opts.Telemetry)
|
|
// Only attach args when arguments were actually provided. Instances that
|
|
// predate #2549 (which added the args field to the resources route under
|
|
// model_config=ConfigDict(extra="forbid")) reject an empty args object with
|
|
// "body.args: Extra inputs are not permitted". Mirrors the Python SDK
|
|
// _compact_request_body (#2834) and the Rust CLI compact_request_body (#2799).
|
|
if len(opts.Args) > 0 {
|
|
payload["args"] = opts.Args
|
|
}
|
|
if opts.Tags != nil {
|
|
payload["tags"] = opts.Tags
|
|
if opts.TagMode != "" {
|
|
payload["tag_mode"] = opts.TagMode
|
|
}
|
|
}
|
|
if err := c.addLocalUpload(ctx, payload, path, true); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := mergeExtra(payload, opts.Extra); err != nil {
|
|
return nil, err
|
|
}
|
|
var result map[string]any
|
|
err := c.doJSON(ctx, http.MethodPost, "/api/v1/resources", nil, payload, &result)
|
|
return result, err
|
|
}
|