Files
OpenViking/sdk/go/admin.go
T
9eac8a6d3d feat(sdk): sync go/ts/python SDKs with server find/search, recall, an… (#3737)
* 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>
2026-08-24 14:09:11 +08:00

154 lines
6.1 KiB
Go

package openviking
import (
"context"
"net/http"
"net/url"
)
// AdminCreateAccount creates an account with its first admin user.
func (c *Client) AdminCreateAccount(ctx context.Context, accountID, adminUserID string) (map[string]any, error) {
return c.AdminCreateAccountWithOptions(ctx, accountID, adminUserID, nil)
}
// AdminCreateAccountWithOptions creates an account with its first admin user.
func (c *Client) AdminCreateAccountWithOptions(ctx context.Context, accountID, adminUserID string, opts *AdminCreateAccountOptions) (map[string]any, error) {
payload := map[string]any{
"account_id": accountID,
"admin_user_id": adminUserID,
}
if opts != nil && opts.UserConfig != nil {
payload["user_config"] = opts.UserConfig
}
if opts != nil && opts.Seed != nil {
payload["seed"] = *opts.Seed
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/admin/accounts", nil, payload, &result)
return result, err
}
// AdminListAccounts lists accounts.
func (c *Client) AdminListAccounts(ctx context.Context) ([]any, error) {
var result []any
err := c.doJSON(ctx, http.MethodGet, "/api/v1/admin/accounts", nil, nil, &result)
return result, err
}
// AdminDeleteAccount deletes an account and all associated users.
func (c *Client) AdminDeleteAccount(ctx context.Context, accountID string) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodDelete, "/api/v1/admin/accounts/"+url.PathEscape(accountID), nil, nil, &result)
return result, err
}
// AdminRegisterUser registers a user in an account.
func (c *Client) AdminRegisterUser(ctx context.Context, accountID, userID, role string) (map[string]any, error) {
return c.AdminRegisterUserWithOptions(ctx, accountID, userID, role, nil)
}
// AdminRegisterUserWithOptions registers a user in an account.
func (c *Client) AdminRegisterUserWithOptions(ctx context.Context, accountID, userID, role string, opts *AdminRegisterUserOptions) (map[string]any, error) {
if role == "" {
role = "user"
}
payload := map[string]any{
"user_id": userID,
"role": role,
}
if opts != nil && opts.UserConfig != nil {
payload["user_config"] = opts.UserConfig
}
if opts != nil && opts.Seed != nil {
payload["seed"] = *opts.Seed
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/users", nil, payload, &result)
return result, err
}
// AdminListUsers lists users in an account.
func (c *Client) AdminListUsers(ctx context.Context, accountID string) ([]any, error) {
var result []any
err := c.doJSON(ctx, http.MethodGet, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/users", nil, nil, &result)
return result, err
}
// AdminRemoveUser removes a user from an account.
func (c *Client) AdminRemoveUser(ctx context.Context, accountID, userID string) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodDelete, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/users/"+url.PathEscape(userID), nil, nil, &result)
return result, err
}
// AdminSetRole changes a user's role.
func (c *Client) AdminSetRole(ctx context.Context, accountID, userID, role string) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodPut, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/users/"+url.PathEscape(userID)+"/role", nil, map[string]any{
"role": role,
}, &result)
return result, err
}
// AdminRegenerateKey regenerates a user's API key.
func (c *Client) AdminRegenerateKey(ctx context.Context, accountID, userID string) (map[string]any, error) {
return c.AdminRegenerateKeyWithOptions(ctx, accountID, userID, nil)
}
// AdminRegenerateKeyWithOptions regenerates a user's API key.
func (c *Client) AdminRegenerateKeyWithOptions(ctx context.Context, accountID, userID string, opts *AdminRegenerateKeyOptions) (map[string]any, error) {
var payload map[string]any
if opts != nil && opts.Seed != nil {
payload = map[string]any{"seed": *opts.Seed}
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/users/"+url.PathEscape(userID)+"/key", nil, payload, &result)
return result, err
}
// AdminMigrate starts legacy data migration or cleanup.
func (c *Client) AdminMigrate(ctx context.Context, opts *AdminMigrateOptions) (map[string]any, error) {
action := "migrate"
if opts != nil && opts.Cleanup {
action = "cleanup"
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/admin/migrate", nil, map[string]any{"action": action}, &result)
return result, err
}
// AdminGetAgentEvolution returns the effective Agent Evolution switch for the
// caller's account.
func (c *Client) AdminGetAgentEvolution(ctx context.Context) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodGet, "/api/v1/admin/agent-evolution", nil, nil, &result)
return result, err
}
// AdminSetAgentEvolution persists and hot-reloads Agent Evolution for the
// caller's account.
func (c *Client) AdminSetAgentEvolution(ctx context.Context, enabled bool) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodPut, "/api/v1/admin/agent-evolution", nil, map[string]any{"enabled": enabled}, &result)
return result, err
}
// AdminGetAccountSettings returns the effective and explicitly overridden
// settings for one account.
func (c *Client) AdminGetAccountSettings(ctx context.Context, accountID string) (map[string]any, error) {
var result map[string]any
err := c.doJSON(ctx, http.MethodGet, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/settings", nil, nil, &result)
return result, err
}
// AdminSetAccountAgentEvolution updates the allowlisted, hot-reloadable Agent
// Evolution setting for one account via PATCH.
func (c *Client) AdminSetAccountAgentEvolution(ctx context.Context, accountID string, enabled bool) (map[string]any, error) {
payload := map[string]any{
"agent_evolution": map[string]any{"enabled": enabled},
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPatch, "/api/v1/admin/accounts/"+url.PathEscape(accountID)+"/settings", nil, payload, &result)
return result, err
}