mirror of
https://github.com/volcengine/OpenViking.git
synced 2026-10-01 01:38:07 +08:00
* feat(memory): support event tag filtering Add session-level default event tags, commit-time overrides, durable queue propagation, and first-write vector index tagging. Include config update APIs and coverage for serialization, concurrency, extraction, and HTTP behavior. Co-authored-by: TRAE CLI <noreply@bytedance.com> * feat(memory): expose event tags in SDKs and CLI Add session default tag configuration, config updates, and commit-time event tag overrides across embedded Python, standalone Python, TypeScript, Go, and the Rust CLI. Preserve explicit empty-tag semantics and document each public interface. Co-authored-by: TRAE CLI <noreply@bytedance.com> * fix(sdk): align legacy session tag APIs Forward commit-time event tags through the legacy Python HTTP shims and align BaseClient session signatures without adding a new abstract-method requirement for existing subclasses. Co-authored-by: TRAE CLI <noreply@bytedance.com> * feat(session): allow updating auto-commit policy Extend PATCH session config to atomically update event tags and auto-commit settings. Merge policy objects by field, use explicit null to disable automatic commits, preserve omitted fields, and expose the contract across SDKs and CLI. Co-authored-by: TRAE CLI <noreply@bytedance.com> * fix(session): align session config interfaces Replace the generic session create config JSON flag with explicit event-tag and auto-commit options. Preserve omitted, object, and null auto-commit semantics across HTTP, embedded clients, SDKs, and CLI, reject ambiguous null policy fields, and handle nullable event configuration consistently. Co-authored-by: TRAE CLI <noreply@bytedance.com> * test(session): trim redundant event tag tests --------- Co-authored-by: TRAE CLI <noreply@bytedance.com> Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
146 lines
3.0 KiB
Go
146 lines
3.0 KiB
Go
package openviking
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"mime"
|
|
"net/url"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func setString(m map[string]any, key, value string) {
|
|
if value != "" {
|
|
m[key] = value
|
|
}
|
|
}
|
|
|
|
func setAny(m map[string]any, key string, value any) {
|
|
if value != nil {
|
|
m[key] = value
|
|
}
|
|
}
|
|
|
|
func setQueryString(values url.Values, key, value string) {
|
|
if value != "" {
|
|
values.Set(key, value)
|
|
}
|
|
}
|
|
|
|
// setQueryAny mirrors setAny for query parameters: it sets key only when value
|
|
// is non-nil, so an unset optional (e.g. a skill TargetURI) is omitted entirely.
|
|
func setQueryAny(values url.Values, key string, value any) {
|
|
if value == nil {
|
|
return
|
|
}
|
|
if s, ok := value.(string); ok {
|
|
values.Set(key, s)
|
|
return
|
|
}
|
|
values.Set(key, fmt.Sprint(value))
|
|
}
|
|
|
|
func setFloatPtr(m map[string]any, key string, value *float64) {
|
|
if value != nil {
|
|
m[key] = *value
|
|
}
|
|
}
|
|
|
|
func boolValue(ptr *bool, fallback bool) bool {
|
|
if ptr == nil {
|
|
return fallback
|
|
}
|
|
return *ptr
|
|
}
|
|
|
|
// String returns a string pointer for request fields that must distinguish empty from omitted.
|
|
func String(s string) *string {
|
|
return &s
|
|
}
|
|
|
|
// Bool returns a bool pointer for optional request fields.
|
|
func Bool(v bool) *bool {
|
|
return &v
|
|
}
|
|
|
|
// Int returns an int pointer for optional request fields.
|
|
func Int(v int) *int {
|
|
return &v
|
|
}
|
|
|
|
// Float64 returns a float64 pointer for optional request fields.
|
|
func Float64(v float64) *float64 {
|
|
return &v
|
|
}
|
|
|
|
// Map returns a map pointer for request fields that distinguish null from omitted.
|
|
func Map(v map[string]any) *map[string]any {
|
|
return &v
|
|
}
|
|
|
|
func queryBool(values url.Values, key string, value bool) {
|
|
values.Set(key, strconv.FormatBool(value))
|
|
}
|
|
|
|
func queryInt(values url.Values, key string, value int) {
|
|
values.Set(key, strconv.Itoa(value))
|
|
}
|
|
|
|
func queryFloat(values url.Values, key string, value float64) {
|
|
values.Set(key, strconv.FormatFloat(value, 'f', -1, 64))
|
|
}
|
|
|
|
func normalizeTarget(target any) any {
|
|
switch v := target.(type) {
|
|
case nil:
|
|
return ""
|
|
case string:
|
|
if v == "" {
|
|
return ""
|
|
}
|
|
return NormalizeURI(v)
|
|
case []string:
|
|
uris := make([]string, 0, len(v))
|
|
for _, uri := range v {
|
|
if uri == "" {
|
|
uris = append(uris, uri)
|
|
} else {
|
|
uris = append(uris, NormalizeURI(uri))
|
|
}
|
|
}
|
|
return uris
|
|
default:
|
|
return v
|
|
}
|
|
}
|
|
|
|
func normalizeImageInput(image string) (string, error) {
|
|
if image == "" || strings.HasPrefix(image, "data:image/") ||
|
|
strings.HasPrefix(image, "http://") ||
|
|
strings.HasPrefix(image, "https://") ||
|
|
strings.HasPrefix(image, "viking://") {
|
|
return image, nil
|
|
}
|
|
info, err := os.Stat(image)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return image, nil
|
|
}
|
|
return "", err
|
|
}
|
|
if info.IsDir() {
|
|
return image, nil
|
|
}
|
|
data, err := os.ReadFile(image)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
mimeType := mime.TypeByExtension(strings.ToLower(filepath.Ext(image)))
|
|
if mimeType == "" || !strings.HasPrefix(mimeType, "image/") {
|
|
mimeType = "image/png"
|
|
}
|
|
return fmt.Sprintf("data:%s;base64,%s", mimeType, base64.StdEncoding.EncodeToString(data)), nil
|
|
}
|